[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KK3MXMT38M810TEDQZ7M23":3,"skill-same:01M6KK3MXMT38M810TEDQZ7M23":69},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":22,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":13,"repositoryHtmlUrl":45,"repositoryHomepageUrl":6,"ownerHtmlUrl":46,"ownerBlogUrl":6,"ownerDescription":47,"updatedAt":48,"install":49,"resources":62},"01M6KK3MXMT38M810TEDQZ7M23","spreadsheet-validated-exec",null,"Execute Python scripts for spreadsheets with prerequisite data validation and source accessibility checks","AG064\u002FOpenSpace","AG064","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184930299?v=4","01M6KHVFG7TB73NHX3RDYSTMH2","01M6KHVFMM7XA2PZA9Z83PHS3V",0,"MIT","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-enhanced-enhanced-f0b1db\u002FSKILL.md",[17],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000004","电子表格","SCENARIO","使用场景",[23,24,25,26,27,28,29,30,31,32,33,34,35,36],"spreadsheet","exec","spreadsheet validated exec","python","accessibility","spreadsheets","validation","data","execute","data validation","scripts","with","for","source","2026-11-10 10:12:30",false,"---\nname: spreadsheet-validated-exec\ndescription: Execute Python scripts for spreadsheets with prerequisite data validation and source accessibility checks\n---\n\n# Validated Python Execution for Spreadsheet Tasks\n\n## Overview\n\nThis skill extends direct Python execution for spreadsheet operations by adding a **mandatory data validation phase** before any processing begins. This prevents wasted iterations on inaccessible data sources and provides clear error documentation when data cannot be accessed.\n\n## When to Use This Skill\n\nUse validated direct `run_shell` with Python scripts for spreadsheet operations when:\n\n- Reading or writing complex Excel files with multiple sheets\n- Data sources have already been validated as accessible\n- You have fallback sources identified in case of access failures\n- Applying formulas, formatting, or data transformations\n- Working with `openpyxl`, `pandas`, or similar libraries\n- The operation involves multiple steps that could exceed agent step limits\n- You need precise control over error handling and debugging\n- Complex scripts benefit from file-based execution for better reliability\n\n## Why Validated Direct Execution?\n\nBeyond standard shell_agent limitations, **unvalidated data access** causes:\n\n- Wasted iterations attempting to process non-existent data\n- Unclear error messages when source files are inaccessible\n- No graceful degradation when primary sources fail\n- Missing documentation of why data operations couldn't complete\n\nDirect `run_shell` with Python validation is more reliable because it:\n\n- Executes validation in a single step with no iteration limits\n- Provides clearer, immediate error messages for access failures\n- Handles complex operations without step constraints\n- Gives full control over library imports and execution flow\n- Writing scripts to `.py` files first avoids shell_agent parsing issues with heredocs\n- Documents all access failures for troubleshooting and reporting\n\n## Phase 0: Data Source Validation (REQUIRED)\n\n**Before writing any spreadsheet processing code**, verify your data sources are accessible:\n\n### Step 0.1: Verify Data Availability\n\n```python\nimport os\nimport requests\nfrom pathlib import Path\n\n# For local files\ndef verify_local_file(file_path):\n    path = Path(file_path)\n    if not path.exists():\n        raise FileNotFoundError(f\"Data file not found: {file_path}\")\n    if not path.is_file():\n        raise ValueError(f\"Path is not a file: {file_path}\")\n    if path.stat().st_size == 0:\n        raise ValueError(f\"Data file is empty: {file_path}\")\n    print(f\"✓ Local file verified: {file_path} ({path.stat().st_size} bytes)\")\n    return True\n\n# For remote URLs\ndef verify_remote_url(url, timeout=30):\n    try:\n        # Try HEAD request first (lighter than GET)\n        response = requests.head(url, timeout=timeout, allow_redirects=True)\n        if response.status_code == 405:  # HEAD not allowed, try GET\n            response = requests.get(url, timeout=timeout, stream=True)\n        response.raise_for_status()\n        \n        # Check content type if available\n        content_type = response.headers.get('Content-Type', '')\n        if 'text\u002Fhtml' in content_type and 'excel' not in url.lower():\n            print(f\"⚠ Warning: URL may return HTML, not data file\")\n        \n        print(f\"✓ Remote URL verified: {url} (Status: {response.status_code})\")\n        return True\n    except requests.exceptions.SSLError as e:\n        print(f\"✗ SSL Error: {str(e)}\")\n        return False\n    except requests.exceptions.ConnectionError as e:\n        print(f\"✗ Connection Error: {str(e)}\")\n        return False\n    except requests.exceptions.Timeout as e:\n        print(f\"✗ Timeout Error: {str(e)}\")\n        return False\n    except Exception as e:\n        print(f\"✗ Verification Failed: {str(e)}\")\n        return False\n```\n\n### Step 0.2: Handle Inaccessible Sources\n\n**If primary data source is unavailable:**\n\n1. **Check alternative locations:**\n   - Is data available from a backup URL?\n   - Is there a cached\u002Flocal copy available?\n   - Can data be obtained from an API instead of web scraping?\n   - Is there an alternative data provider?\n\n2. **Document the failure:**\n   ```python\n   def log_access_failure(source, error_type, timestamp=None):\n       from datetime import datetime\n       if not timestamp:\n           timestamp = datetime.now().isoformat()\n       \n       error_log = {\n           'timestamp': timestamp,\n           'source': source,\n           'error_type': error_type,\n           'alternatives_attempted': [],\n           'resolution': 'pending'\n       }\n       \n       # Save to error log file\n       import json\n       with open('data_access_errors.json', 'a') as f:\n           f.write(json.dumps(error_log) + '\\n')\n       \n       return error_log\n   ```\n\n3. **Implement fallback strategy:**\n   ```python\n   def get_data_with_fallback(primary_source, fallback_sources):\n       sources = [primary_source] + fallback_sources\n       \n       for i, source in enumerate(sources):\n           print(f\"Attempting source {i+1}\u002F{len(sources)}: {source}\")\n           \n           if source.startswith('http'):\n               if verify_remote_url(source):\n                   return download_data(source)\n           else:\n               if verify_local_file(source):\n                   return load_local_data(source)\n           \n           print(f\"Source {source} unavailable, trying next...\")\n       \n       raise Exception(f\"All {len(sources)} data sources unavailable\")\n   ```\n\n### Step 0.3: Pre-Execution Checklist\n\nBefore proceeding to spreadsheet operations, confirm:\n\n- [ ] Primary data source is accessible (file exists \u002F URL responds)\n- [ ] Data file is not empty (has content to process)\n- [ ] Required permissions are in place (file not locked, API keys valid)\n- [ ] Alternative sources identified if primary fails\n- [ ] Error logging mechanism is configured\n\n**If any check fails:** Do NOT proceed to spreadsheet processing. Report the blocking issue and either:\n- Resolve the data access problem first\n- Switch to an alternative data source\n- Abort the task with clear error documentation\n\n## How to Use (With Validation)\n\n### Complete Workflow Template\n\n**Recommended Pattern: Validate → Process → Report**\n\n```bash\n# Step 1: Write validation + processing script to file\ncat > validated_spreadsheet_process.py \u003C\u003C 'EOF'\nimport sys\nimport os\nfrom pathlib import Path\nimport pandas as pd\nfrom openpyxl import load_workbook\n\n# === PHASE 0: VALIDATION ===\ndef validate_sources():\n    sources_to_check = [\n        ('input_data.xlsx', 'local'),\n        # ('https:\u002F\u002Fbackup-source.com\u002Fdata.xlsx', 'remote')\n    ]\n    \n    validated_sources = []\n    for source, source_type in sources_to_check:\n        try:\n            if source_type == 'local':\n                if not Path(source).exists():\n                    print(f\"ERROR: Local file not found: {source}\")\n                    continue\n                if Path(source).stat().st_size == 0:\n                    print(f\"ERROR: Local file is empty: {source}\")\n                    continue\n            validated_sources.append(source)\n            print(f\"✓ Validated: {source}\")\n        except Exception as e:\n            print(f\"ERROR validating {source}: {e}\")\n    \n    if not validated_sources:\n        print(\"FATAL: No valid data sources available. Aborting.\")\n        sys.exit(1)\n    \n    return validated_sources\n\n# === PHASE 1: PROCESSING ===\ndef process_data(source_file):\n    # Your spreadsheet operations here\n    pass\n\n# === PHASE 2: REPORTING ===\ndef generate_report(success, details):\n    report = {\n        'status': 'success' if success else 'failed',\n        'details': details\n    }\n    print(f\"Report: {report}\")\n    return report\n\nif __name__ == '__main__':\n    try:\n        # Validate first\n        sources = validate_sources()\n        \n        # Process validated sources\n        for source in sources:\n            process_data(source)\n        \n        generate_report(True, f\"Processed {len(sources)} sources\")\n        \n    except Exception as e:\n        generate_report(False, str(e))\n        sys.exit(1)\nEOF\n\n# Step 2: Execute the validated script\npython3 validated_spreadsheet_process.py\n```\n\n### Pattern 1: Write Script to File First (Complex Operations)\n\nFor complex multi-line scripts with multiple data sources:\n\n```bash\n# Step 1: Write the Python script to a file\ncat > process_spreadsheet.py \u003C\u003C 'EOF'\nimport openpyxl\nfrom openpyxl import Workbook\nfrom pathlib import Path\nimport sys\n\n# Validate first\ninput_file = Path('file.xlsx')\nif not input_file.exists():\n    print(f\"ERROR: Input file not found: {input_file}\")\n    sys.exit(1)\nif input_file.stat().st_size == 0:\n    print(f\"ERROR: Input file is empty: {input_file}\")\n    sys.exit(1)\n\n# Your spreadsheet code here\nwb = openpyxl.load_workbook('file.xlsx')\n# ... operations ...\nwb.save('output.xlsx')\nprint('Success')\nEOF\n\n# Step 2: Execute the script\npython3 process_spreadsheet.py\n```\n\n### Pattern 2: Inline Heredoc (Simple Scripts with Validation)\n\nFor short scripts when NOT using shell_agent, include validation inline:\n\n```bash\n# Include quick validation before processing\npython3 \u003C\u003C 'EOF'\nimport os\nimport sys\n\n# Quick validation\ninput_file = 'data.xlsx'\nif not os.path.exists(input_file):\n    print(f\"ERROR: {input_file} not found\")\n    sys.exit(1)\nif os.path.getsize(input_file) == 0:\n    print(f\"ERROR: {input_file} is empty\")\n    sys.exit(1)\n\n# Continue with processing...\nEOF\n```\n\n## Examples\n\n### Example 1: Validated Read and Transform\n\n**With prerequisite validation:**\n\n```python\nimport pandas as pd\nimport sys\nfrom pathlib import Path\n\n# Validate input file exists and has content\ninput_path = Path('input.xlsx')\nif not input_path.exists():\n    print(f\"ERROR: Input file not found: {input_path}\")\n    sys.exit(1)\nif input_path.stat().st_size == 0:\n    print(f\"ERROR: Input file is empty: {input_path}\")\n    sys.exit(1)\n\n# Now safe to process\ndf = pd.read_excel('input.xlsx', sheet_name='Revenue')\n\n# Apply transformations\ndf['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])\n\n# Save results\ndf.to_excel('output.xlsx', index=False, sheet_name='Processed')\n```\n\n### Example 2: Multi-Sheet with Source Validation\n\n```python\nfrom openpyxl import load_workbook\nimport sys\nfrom pathlib import Path\n\n# Validate workbook accessibility\nwb_path = Path('tour_data.xlsx')\nif not wb_path.exists():\n    print(f\"ERROR: Workbook not found: {wb_path.absolute()}\")\n    sys.exit(1)\n\ntry:\n    wb = load_workbook('tour_data.xlsx')\nexcept Exception as e:\n    print(f\"ERROR: Cannot open workbook: {e}\")\n    print(\"Possible causes: file locked, corrupted, or wrong format\")\n    sys.exit(1)\n\n# Iterate through sheets\nfor sheet_name in wb.sheetnames:\n    ws = wb[sheet_name]\n    # Apply formatting or calculations\n    for row in ws.iter_rows(min_row=2, max_col=5):\n        # Process cells\n        pass\n\nwb.save('tour_data_processed.xlsx')\n```\n\n### Example 3: Formatting with Pre-Checks\n\n```python\nfrom openpyxl import load_workbook\nfrom openpyxl.styles import Font, PatternFill, Alignment\nfrom pathlib import Path\nimport sys\n\n# Pre-check file\nreport_path = Path('report.xlsx')\nif not report_path.exists():\n    print(f\"ERROR: Report file not found: {report_path}\")\n    sys.exit(1)\n\nwb = load_workbook('report.xlsx')\nws = wb.active\n\n# Apply header styling\nheader_fill = PatternFill(start_color='4472C4', fill_type='solid')\nheader_font = Font(bold=True, color='FFFFFF')\n\nfor cell in ws[1]:\n    cell.fill = header_fill\n    cell.font = header_font\n    cell.alignment = Alignment(horizontal='center')\n\nwb.save('report_formatted.xlsx')\n```\n\n### Example 4: Comprehensive Error Handling with Logging\n\n```python\nimport sys\nimport json\nfrom datetime import datetime\nfrom pathlib import Path\nfrom openpyxl import load_workbook\n\ndef log_error(source, error_msg, error_type):\n    \"\"\"Log errors for later analysis and reporting\"\"\"\n    error_record = {\n        'timestamp': datetime.now().isoformat(),\n        'source': source,\n        'error_type': error_type,\n        'message': error_msg\n    }\n    \n    with open('processing_errors.log', 'a') as f:\n        f.write(json.dumps(error_record) + '\\n')\n    \n    return error_record\n\ntry:\n    # Validate file before opening\n    if not Path('data.xlsx').exists():\n        log_error('data.xlsx', 'File not found', 'ValidationError')\n        raise FileNotFoundError('data.xlsx')\n    \n    wb = load_workbook('data.xlsx')\n    ws = wb.active\n    \n    # Your operations here\n    value = ws['A1'].value\n    \n    wb.save('output.xlsx')\n    print(f\"Success: Processed {ws.max_row} rows\")\n    \nexcept FileNotFoundError as e:\n    log_error('data.xlsx', str(e), 'FileNotFoundError')\n    print(f\"ERROR: {str(e)}\", file=sys.stderr)\n    print(\"ACTION: Verify file path and permissions\")\n    sys.exit(1)\nexcept PermissionError as e:\n    log_error('data.xlsx', str(e), 'PermissionError')\n    print(f\"ERROR: Permission denied - file may be open in another application\")\n    print(\"ACTION: Close the file in other applications and retry\")\n    sys.exit(1)\nexcept Exception as e:\n    log_error('data.xlsx', str(e), type(e).__name__)\n    print(f\"ERROR: {str(e)}\", file=sys.stderr)\n    sys.exit(1)\n```\n\n## Best Practices (Enhanced)\n\n1. **Always validate before processing**: Check data source availability before any spreadsheet operations\n2. **Log all access failures**: Document when and why data sources become unavailable\n3. **Identify fallbacks upfront**: Know your alternative sources before starting\n4. **Fail fast on validation errors**: Don't waste iterations on impossible operations\n5. **Prefer file-based execution** for complex scripts: write to `.py` file first, then execute via `run_shell`\n6. **Import only needed libraries** to reduce execution time\n7. **Print clear success\u002Ferror messages** for debugging\n8. **Save intermediate results** for complex multi-step transformations\n9. **Test with small data** before scaling to large spreadsheets\n10. **Use pandas for data manipulation** and openpyxl for formatting when both are needed\n11. **Clean up temporary script files** after execution if they won't be reused\n\n## Data Access Failure Protocols\n\n### When Primary Source Fails\n\n1. **Immediate actions:**\n   - Log the failure with timestamp, source, and error type\n   - Check if error is temporary (timeout) or permanent (404, file doesn't exist)\n   - Attempt alternative sources if available\n\n2. **For temporary failures (timeouts, 5xx errors):**\n   ```python\n   def retry_with_backoff(operation, max_retries=3, base_delay=1):\n       import time\n       for attempt in range(max_retries):\n           try:\n               return operation()\n           except (TimeoutError, ConnectionError) as e:\n               if attempt == max_retries - 1:\n                   raise\n               delay = base_delay * (2 ** attempt)\n               print(f\"Retry {attempt + 1}\u002F{max_retries} after {delay}s delay\")\n               time.sleep(delay)\n   ```\n\n3. **For permanent failures (file not found, 404):**\n   - Switch to identified fallback source immediately\n   - Document the primary source failure\n   - Continue with fallback if available, otherwise abort cleanly\n\n### Error Reporting Template\n\n```python\ndef report_data_access_issue(issue_type, source, details, alternatives_tried=None):\n    \"\"\"Standardize error reporting for data access failures\"\"\"\n    from datetime import datetime\n    \n    report = f\"\"\"\n=== DATA ACCESS FAILURE REPORT ===\nType: {issue_type}\nSource: {source}\nTime: {datetime.now().isoformat()}\nDetails: {details}\nAlternatives Attempted: {alternatives_tried or 'None'}\nRecommended Action: {get_recommended_action(issue_type)}\n==================================\n\"\"\"\n    print(report)\n    return report\n\ndef get_recommended_action(issue_type):\n    actions = {\n        'FileNotFound': 'Verify file path, check if file was moved or deleted',\n        'ConnectionError': 'Check network connectivity, try alternative source',\n        'Timeout': 'Increase timeout, check source server status',\n        'PermissionError': 'Check file permissions, ensure file not open elsewhere',\n        'SSLError': 'Verify SSL certificate, try HTTP if appropriate',\n        'default': 'Review error details, check source availability'\n    }\n    return actions.get(issue_type, actions['default'])\n```\n\n## When NOT to Use This Skill\n\n- Simple single-cell reads\u002Fwrites (validation overhead not warranted)\n- Operations that require interactive user input\n- Tasks where you need the agent to iteratively refine the approach\n- When you have no way to validate data sources (skip to error handling only)\n\n## Common Libraries\n\n| Library | Best For | Also Use For |\n|---------|----------|--------------|\n| `requests` | Web requests | Source URL validation, health checks |\n| `openpyxl` | Reading\u002Fwriting .xlsx files, formatting, formulas | - |\n| `pandas` | Data manipulation, analysis, merging datasets | Chunked reading for large files |\n| `xlrd` | Reading older .xls files (read-only) | - |\n| `xlsxwriter` | Creating new .xlsx files with advanced formatting | - |\n\n## Troubleshooting (Enhanced)\n\n**Issue**: Data source unavailable \u002F file not found\n- **Solution**: Run validation check first before processing. If validation fails:\n  1. Verify the path\u002FURL is correct\n  2. Check if file was moved, renamed, or deleted\n  3. Try alternative sources if available\n  4. Document the failure and abort cleanly rather than proceeding\n\n**Issue**: Source was accessible yesterday but not today\n- **Solution**: Implement fallback sources and log the change. Consider:\n  - Setting up monitoring for critical data sources\n  - Caching important data locally when possible\n  - Having contact information for data source maintainers\n\n**Issue**: Validation passes but processing fails\n- **Solution**: Validation checks accessibility, not content validity. Add:\n  - Schema validation (check expected columns exist)\n  - Content validation (check data types, ranges)\n  - Sample verification (read first few rows to confirm structure)\n\n**Issue**: Heredoc syntax fails with 'unknown error' when using shell_agent\n- **Solution**: Write the Python script to a `.py` file first with full validation logic, then execute with `python3 script.py`. This is significantly more reliable than inline heredoc when shell_agent is the executor.\n\n**Issue**: FileNotFoundError (after validation passed)\n- **Solution**: File may have been moved\u002Fdeleted between validation and processing, or path is relative and working directory changed. Use absolute paths.\n\n**Issue**: PermissionError\n- **Solution**: Ensure the file is not open in another application. On Linux\u002FMac, check with `lsof | grep filename`\n\n**Issue**: ConnectionError \u002F Timeout on remote sources\n- **Solution**: Check network connectivity, try with increased timeout, use retry logic with exponential backoff, or switch to cached\u002Flocal copy if available\n\n**Issue**: SSL Certificate errors\n- **Solution**: Verify the certificate is valid. As last resort for trusted internal sources only: `requests.get(url, verify=False)` - but log this as a security concern\n\n**Issue**: All alternative sources fail\n- **Solution**: Abort with comprehensive error report documenting:\n  - All sources attempted\n  - Error types for each\n  - Timestamp of failures\n  - Recommended next steps for human operator\n\n**Issue**: MemoryError on large files\n- **Solution**: Process data in chunks using pandas `chunksize` parameter. Validate chunk size during initial validation phase.\n\n**Issue**: Formatting not applying\n- **Solution**: Ensure you're modifying cell styles before saving, and use `.copy()` for style objects. Verify workbook is not in read-only mode.\n","# Validated Python Execution for Spreadsheet Tasks\n\n## Overview\n\nThis skill extends direct Python execution for spreadsheet operations by adding a **mandatory data validation phase** before any processing begins. This prevents wasted iterations on inaccessible data sources and provides clear error documentation when data cannot be accessed.\n\n## When to Use This Skill\n\nUse validated direct `run_shell` with Python scripts for spreadsheet operations when:\n\n- Reading or writing complex Excel files with multiple sheets\n- Data sources have already been validated as accessible\n- You have fallback sources identified in case of access failures\n- Applying formulas, formatting, or data transformations\n- Working with `openpyxl`, `pandas`, or similar libraries\n- The operation involves multiple steps that could exceed agent step limits\n- You need precise control over error handling and debugging\n- Complex scripts benefit from file-based execution for better reliability\n\n## Why Validated Direct Execution?\n\nBeyond standard shell_agent limitations, **unvalidated data access** causes:\n\n- Wasted iterations attempting to process non-existent data\n- Unclear error messages when source files are inaccessible\n- No graceful degradation when primary sources fail\n- Missing documentation of why data operations couldn't complete\n\nDirect `run_shell` with Python validation is more reliable because it:\n\n- Executes validation in a single step with no iteration limits\n- Provides clearer, immediate error messages for access failures\n- Handles complex operations without step constraints\n- Gives full control over library imports and execution flow\n- Writing scripts to `.py` files first avoids shell_agent parsing issues with heredocs\n- Documents all access failures for troubleshooting and reporting\n\n## Phase 0: Data Source Validation (REQUIRED)\n\n**Before writing any spreadsheet processing code**, verify your data sources are accessible:\n\n### Step 0.1: Verify Data Availability\n\n```python\nimport os\nimport requests\nfrom pathlib import Path\n\n# For local files\ndef verify_local_file(file_path):\n    path = Path(file_path)\n    if not path.exists():\n        raise FileNotFoundError(f\"Data file not found: {file_path}\")\n    if not path.is_file():\n        raise ValueError(f\"Path is not a file: {file_path}\")\n    if path.stat().st_size == 0:\n        raise ValueError(f\"Data file is empty: {file_path}\")\n    print(f\"✓ Local file verified: {file_path} ({path.stat().st_size} bytes)\")\n    return True\n\n# For remote URLs\ndef verify_remote_url(url, timeout=30):\n    try:\n        # Try HEAD request first (lighter than GET)\n        response = requests.head(url, timeout=timeout, allow_redirects=True)\n        if response.status_code == 405:  # HEAD not allowed, try GET\n            response = requests.get(url, timeout=timeout, stream=True)\n        response.raise_for_status()\n        \n        # Check content type if available\n        content_type = response.headers.get('Content-Type', '')\n        if 'text\u002Fhtml' in content_type and 'excel' not in url.lower():\n            print(f\"⚠ Warning: URL may return HTML, not data file\")\n        \n        print(f\"✓ Remote URL verified: {url} (Status: {response.status_code})\")\n        return True\n    except requests.exceptions.SSLError as e:\n        print(f\"✗ SSL Error: {str(e)}\")\n        return False\n    except requests.exceptions.ConnectionError as e:\n        print(f\"✗ Connection Error: {str(e)}\")\n        return False\n    except requests.exceptions.Timeout as e:\n        print(f\"✗ Timeout Error: {str(e)}\")\n        return False\n    except Exception as e:\n        print(f\"✗ Verification Failed: {str(e)}\")\n        return False\n```\n\n### Step 0.2: Handle Inaccessible Sources\n\n**If primary data source is unavailable:**\n\n1. **Check alternative locations:**\n   - Is data available from a backup URL?\n   - Is there a cached\u002Flocal copy available?\n   - Can data be obtained from an API instead of web scraping?\n   - Is there an alternative data provider?\n\n2. **Document the failure:**\n   ```python\n   def log_access_failure(source, error_type, timestamp=None):\n       from datetime import datetime\n       if not timestamp:\n           timestamp = datetime.now().isoformat()\n       \n       error_log = {\n           'timestamp': timestamp,\n           'source': source,\n           'error_type': error_type,\n           'alternatives_attempted': [],\n           'resolution': 'pending'\n       }\n       \n       # Save to error log file\n       import json\n       with open('data_access_errors.json', 'a') as f:\n           f.write(json.dumps(error_log) + '\\n')\n       \n       return error_log\n   ```\n\n3. **Implement fallback strategy:**\n   ```python\n   def get_data_with_fallback(primary_source, fallback_sources):\n       sources = [primary_source] + fallback_sources\n       \n       for i, source in enumerate(sources):\n           print(f\"Attempting source {i+1}\u002F{len(sources)}: {source}\")\n           \n           if source.startswith('http'):\n               if verify_remote_url(source):\n                   return download_data(source)\n           else:\n               if verify_local_file(source):\n                   return load_local_data(source)\n           \n           print(f\"Source {source} unavailable, trying next...\")\n       \n       raise Exception(f\"All {len(sources)} data sources unavailable\")\n   ```\n\n### Step 0.3: Pre-Execution Checklist\n\nBefore proceeding to spreadsheet operations, confirm:\n\n- [ ] Primary data source is accessible (file exists \u002F URL responds)\n- [ ] Data file is not empty (has content to process)\n- [ ] Required permissions are in place (file not locked, API keys valid)\n- [ ] Alternative sources identified if primary fails\n- [ ] Error logging mechanism is configured\n\n**If any check fails:** Do NOT proceed to spreadsheet processing. Report the blocking issue and either:\n- Resolve the data access problem first\n- Switch to an alternative data source\n- Abort the task with clear error documentation\n\n## How to Use (With Validation)\n\n### Complete Workflow Template\n\n**Recommended Pattern: Validate → Process → Report**\n\n```bash\n# Step 1: Write validation + processing script to file\ncat > validated_spreadsheet_process.py \u003C\u003C 'EOF'\nimport sys\nimport os\nfrom pathlib import Path\nimport pandas as pd\nfrom openpyxl import load_workbook\n\n# === PHASE 0: VALIDATION ===\ndef validate_sources():\n    sources_to_check = [\n        ('input_data.xlsx', 'local'),\n        # ('https:\u002F\u002Fbackup-source.com\u002Fdata.xlsx', 'remote')\n    ]\n    \n    validated_sources = []\n    for source, source_type in sources_to_check:\n        try:\n            if source_type == 'local':\n                if not Path(source).exists():\n                    print(f\"ERROR: Local file not found: {source}\")\n                    continue\n                if Path(source).stat().st_size == 0:\n                    print(f\"ERROR: Local file is empty: {source}\")\n                    continue\n            validated_sources.append(source)\n            print(f\"✓ Validated: {source}\")\n        except Exception as e:\n            print(f\"ERROR validating {source}: {e}\")\n    \n    if not validated_sources:\n        print(\"FATAL: No valid data sources available. Aborting.\")\n        sys.exit(1)\n    \n    return validated_sources\n\n# === PHASE 1: PROCESSING ===\ndef process_data(source_file):\n    # Your spreadsheet operations here\n    pass\n\n# === PHASE 2: REPORTING ===\ndef generate_report(success, details):\n    report = {\n        'status': 'success' if success else 'failed',\n        'details': details\n    }\n    print(f\"Report: {report}\")\n    return report\n\nif __name__ == '__main__':\n    try:\n        # Validate first\n        sources = validate_sources()\n        \n        # Process validated sources\n        for source in sources:\n            process_data(source)\n        \n        generate_report(True, f\"Processed {len(sources)} sources\")\n        \n    except Exception as e:\n        generate_report(False, str(e))\n        sys.exit(1)\nEOF\n\n# Step 2: Execute the validated script\npython3 validated_spreadsheet_process.py\n```\n\n### Pattern 1: Write Script to File First (Complex Operations)\n\nFor complex multi-line scripts with multiple data sources:\n\n```bash\n# Step 1: Write the Python script to a file\ncat > process_spreadsheet.py \u003C\u003C 'EOF'\nimport openpyxl\nfrom openpyxl import Workbook\nfrom pathlib import Path\nimport sys\n\n# Validate first\ninput_file = Path('file.xlsx')\nif not input_file.exists():\n    print(f\"ERROR: Input file not found: {input_file}\")\n    sys.exit(1)\nif input_file.stat().st_size == 0:\n    print(f\"ERROR: Input file is empty: {input_file}\")\n    sys.exit(1)\n\n# Your spreadsheet code here\nwb = openpyxl.load_workbook('file.xlsx')\n# ... operations ...\nwb.save('output.xlsx')\nprint('Success')\nEOF\n\n# Step 2: Execute the script\npython3 process_spreadsheet.py\n```\n\n### Pattern 2: Inline Heredoc (Simple Scripts with Validation)\n\nFor short scripts when NOT using shell_agent, include validation inline:\n\n```bash\n# Include quick validation before processing\npython3 \u003C\u003C 'EOF'\nimport os\nimport sys\n\n# Quick validation\ninput_file = 'data.xlsx'\nif not os.path.exists(input_file):\n    print(f\"ERROR: {input_file} not found\")\n    sys.exit(1)\nif os.path.getsize(input_file) == 0:\n    print(f\"ERROR: {input_file} is empty\")\n    sys.exit(1)\n\n# Continue with processing...\nEOF\n```\n\n## Examples\n\n### Example 1: Validated Read and Transform\n\n**With prerequisite validation:**\n\n```python\nimport pandas as pd\nimport sys\nfrom pathlib import Path\n\n# Validate input file exists and has content\ninput_path = Path('input.xlsx')\nif not input_path.exists():\n    print(f\"ERROR: Input file not found: {input_path}\")\n    sys.exit(1)\nif input_path.stat().st_size == 0:\n    print(f\"ERROR: Input file is empty: {input_path}\")\n    sys.exit(1)\n\n# Now safe to process\ndf = pd.read_excel('input.xlsx', sheet_name='Revenue')\n\n# Apply transformations\ndf['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])\n\n# Save results\ndf.to_excel('output.xlsx', index=False, sheet_name='Processed')\n```\n\n### Example 2: Multi-Sheet with Source Validation\n\n```python\nfrom openpyxl import load_workbook\nimport sys\nfrom pathlib import Path\n\n# Validate workbook accessibility\nwb_path = Path('tour_data.xlsx')\nif not wb_path.exists():\n    print(f\"ERROR: Workbook not found: {wb_path.absolute()}\")\n    sys.exit(1)\n\ntry:\n    wb = load_workbook('tour_data.xlsx')\nexcept Exception as e:\n    print(f\"ERROR: Cannot open workbook: {e}\")\n    print(\"Possible causes: file locked, corrupted, or wrong format\")\n    sys.exit(1)\n\n# Iterate through sheets\nfor sheet_name in wb.sheetnames:\n    ws = wb[sheet_name]\n    # Apply formatting or calculations\n    for row in ws.iter_rows(min_row=2, max_col=5):\n        # Process cells\n        pass\n\nwb.save('tour_data_processed.xlsx')\n```\n\n### Example 3: Formatting with Pre-Checks\n\n```python\nfrom openpyxl import load_workbook\nfrom openpyxl.styles import Font, PatternFill, Alignment\nfrom pathlib import Path\nimport sys\n\n# Pre-check file\nreport_path = Path('report.xlsx')\nif not report_path.exists():\n    print(f\"ERROR: Report file not found: {report_path}\")\n    sys.exit(1)\n\nwb = load_workbook('report.xlsx')\nws = wb.active\n\n# Apply header styling\nheader_fill = PatternFill(start_color='4472C4', fill_type='solid')\nheader_font = Font(bold=True, color='FFFFFF')\n\nfor cell in ws[1]:\n    cell.fill = header_fill\n    cell.font = header_font\n    cell.alignment = Alignment(horizontal='center')\n\nwb.save('report_formatted.xlsx')\n```\n\n### Example 4: Comprehensive Error Handling with Logging\n\n```python\nimport sys\nimport json\nfrom datetime import datetime\nfrom pathlib import Path\nfrom openpyxl import load_workbook\n\ndef log_error(source, error_msg, error_type):\n    \"\"\"Log errors for later analysis and reporting\"\"\"\n    error_record = {\n        'timestamp': datetime.now().isoformat(),\n        'source': source,\n        'error_type': error_type,\n        'message': error_msg\n    }\n    \n    with open('processing_errors.log', 'a') as f:\n        f.write(json.dumps(error_record) + '\\n')\n    \n    return error_record\n\ntry:\n    # Validate file before opening\n    if not Path('data.xlsx').exists():\n        log_error('data.xlsx', 'File not found', 'ValidationError')\n        raise FileNotFoundError('data.xlsx')\n    \n    wb = load_workbook('data.xlsx')\n    ws = wb.active\n    \n    # Your operations here\n    value = ws['A1'].value\n    \n    wb.save('output.xlsx')\n    print(f\"Success: Processed {ws.max_row} rows\")\n    \nexcept FileNotFoundError as e:\n    log_error('data.xlsx', str(e), 'FileNotFoundError')\n    print(f\"ERROR: {str(e)}\", file=sys.stderr)\n    print(\"ACTION: Verify file path and permissions\")\n    sys.exit(1)\nexcept PermissionError as e:\n    log_error('data.xlsx', str(e), 'PermissionError')\n    print(f\"ERROR: Permission denied - file may be open in another application\")\n    print(\"ACTION: Close the file in other applications and retry\")\n    sys.exit(1)\nexcept Exception as e:\n    log_error('data.xlsx', str(e), type(e).__name__)\n    print(f\"ERROR: {str(e)}\", file=sys.stderr)\n    sys.exit(1)\n```\n\n## Best Practices (Enhanced)\n\n1. **Always validate before processing**: Check data source availability before any spreadsheet operations\n2. **Log all access failures**: Document when and why data sources become unavailable\n3. **Identify fallbacks upfront**: Know your alternative sources before starting\n4. **Fail fast on validation errors**: Don't waste iterations on impossible operations\n5. **Prefer file-based execution** for complex scripts: write to `.py` file first, then execute via `run_shell`\n6. **Import only needed libraries** to reduce execution time\n7. **Print clear success\u002Ferror messages** for debugging\n8. **Save intermediate results** for complex multi-step transformations\n9. **Test with small data** before scaling to large spreadsheets\n10. **Use pandas for data manipulation** and openpyxl for formatting when both are needed\n11. **Clean up temporary script files** after execution if they won't be reused\n\n## Data Access Failure Protocols\n\n### When Primary Source Fails\n\n1. **Immediate actions:**\n   - Log the failure with timestamp, source, and error type\n   - Check if error is temporary (timeout) or permanent (404, file doesn't exist)\n   - Attempt alternative sources if available\n\n2. **For temporary failures (timeouts, 5xx errors):**\n   ```python\n   def retry_with_backoff(operation, max_retries=3, base_delay=1):\n       import time\n       for attempt in range(max_retries):\n           try:\n               return operation()\n           except (TimeoutError, ConnectionError) as e:\n               if attempt == max_retries - 1:\n                   raise\n               delay = base_delay * (2 ** attempt)\n               print(f\"Retry {attempt + 1}\u002F{max_retries} after {delay}s delay\")\n               time.sleep(delay)\n   ```\n\n3. **For permanent failures (file not found, 404):**\n   - Switch to identified fallback source immediately\n   - Document the primary source failure\n   - Continue with fallback if available, otherwise abort cleanly\n\n### Error Reporting Template\n\n```python\ndef report_data_access_issue(issue_type, source, details, alternatives_tried=None):\n    \"\"\"Standardize error reporting for data access failures\"\"\"\n    from datetime import datetime\n    \n    report = f\"\"\"\n=== DATA ACCESS FAILURE REPORT ===\nType: {issue_type}\nSource: {source}\nTime: {datetime.now().isoformat()}\nDetails: {details}\nAlternatives Attempted: {alternatives_tried or 'None'}\nRecommended Action: {get_recommended_action(issue_type)}\n==================================\n\"\"\"\n    print(report)\n    return report\n\ndef get_recommended_action(issue_type):\n    actions = {\n        'FileNotFound': 'Verify file path, check if file was moved or deleted',\n        'ConnectionError': 'Check network connectivity, try alternative source',\n        'Timeout': 'Increase timeout, check source server status',\n        'PermissionError': 'Check file permissions, ensure file not open elsewhere',\n        'SSLError': 'Verify SSL certificate, try HTTP if appropriate',\n        'default': 'Review error details, check source availability'\n    }\n    return actions.get(issue_type, actions['default'])\n```\n\n## When NOT to Use This Skill\n\n- Simple single-cell reads\u002Fwrites (validation overhead not warranted)\n- Operations that require interactive user input\n- Tasks where you need the agent to iteratively refine the approach\n- When you have no way to validate data sources (skip to error handling only)\n\n## Common Libraries\n\n| Library | Best For | Also Use For |\n|---------|----------|--------------|\n| `requests` | Web requests | Source URL validation, health checks |\n| `openpyxl` | Reading\u002Fwriting .xlsx files, formatting, formulas | - |\n| `pandas` | Data manipulation, analysis, merging datasets | Chunked reading for large files |\n| `xlrd` | Reading older .xls files (read-only) | - |\n| `xlsxwriter` | Creating new .xlsx files with advanced formatting | - |\n\n## Troubleshooting (Enhanced)\n\n**Issue**: Data source unavailable \u002F file not found\n- **Solution**: Run validation check first before processing. If validation fails:\n  1. Verify the path\u002FURL is correct\n  2. Check if file was moved, renamed, or deleted\n  3. Try alternative sources if available\n  4. Document the failure and abort cleanly rather than proceeding\n\n**Issue**: Source was accessible yesterday but not today\n- **Solution**: Implement fallback sources and log the change. Consider:\n  - Setting up monitoring for critical data sources\n  - Caching important data locally when possible\n  - Having contact information for data source maintainers\n\n**Issue**: Validation passes but processing fails\n- **Solution**: Validation checks accessibility, not content validity. Add:\n  - Schema validation (check expected columns exist)\n  - Content validation (check data types, ranges)\n  - Sample verification (read first few rows to confirm structure)\n\n**Issue**: Heredoc syntax fails with 'unknown error' when using shell_agent\n- **Solution**: Write the Python script to a `.py` file first with full validation logic, then execute with `python3 script.py`. This is significantly more reliable than inline heredoc when shell_agent is the executor.\n\n**Issue**: FileNotFoundError (after validation passed)\n- **Solution**: File may have been moved\u002Fdeleted between validation and processing, or path is relative and working directory changed. Use absolute paths.\n\n**Issue**: PermissionError\n- **Solution**: Ensure the file is not open in another application. On Linux\u002FMac, check with `lsof | grep filename`\n\n**Issue**: ConnectionError \u002F Timeout on remote sources\n- **Solution**: Check network connectivity, try with increased timeout, use retry logic with exponential backoff, or switch to cached\u002Flocal copy if available\n\n**Issue**: SSL Certificate errors\n- **Solution**: Verify the certificate is valid. As last resort for trusted internal sources only: `requests.get(url, verify=False)` - but log this as a security concern\n\n**Issue**: All alternative sources fail\n- **Solution**: Abort with comprehensive error report documenting:\n  - All sources attempted\n  - Error types for each\n  - Timestamp of failures\n  - Recommended next steps for human operator\n\n**Issue**: MemoryError on large files\n- **Solution**: Process data in chunks using pandas `chunksize` parameter. Validate chunk size during initial validation phase.\n\n**Issue**: Formatting not applying\n- **Solution**: Ensure you're modifying cell styles before saving, and use `.copy()` for style objects. Verify workbook is not in read-only mode.\n",{"name":5,"description":7},"main","ff671ef61ed6587c49bd54c81cdc751c0b99e363","gdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-enhanced-enhanced-f0b1db","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace","https:\u002F\u002Fgithub.com\u002FAG064","AG064, E.Mi.\r\n\r\nA person who thinks all the time, yet all they have to think about is nothing. I want to improve the world and work on open source projects","2026-10-08 06:53:48",{"source":8,"skillName":5,"commands":50,"prompt":60,"zipAvailable":61},[51,54,57],{"tool":52,"command":53},"npx","npx skills add AG064\u002FOpenSpace --skill spreadsheet-validated-exec",{"tool":55,"command":56},"bunx","bunx skills add AG064\u002FOpenSpace --skill spreadsheet-validated-exec",{"tool":58,"command":59},"pnpm","pnpm dlx skills add AG064\u002FOpenSpace --skill spreadsheet-validated-exec","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-enhanced-enhanced-f0b1db\u002FSKILL.md",true,[63],{"path":64,"resourceType":65,"resourceTypeDesc":66,"sizeBytes":67,"sourceHtmlUrl":68},".skill_id","OTHER","其他",64,"https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-direct-python-enhanced-enhanced-f0b1db\u002F.skill_id",[70,92,107,116,144,160],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":37},"01M6KKMPWA0B5SCCH766F8M5EA","write-special-chars-ts-check","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-ts-check\u002FSKILL.md",[],[77,78,79,80,81,82,35,83,84,85,86,87,88,89,90,26,91],"write special chars ts check","check","write","filters","Existing","type-checking","errors","script","output","type","files","only","template","file","typescript",{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":37},"01M6KKMJXVBNVEY3TRK055F4A7","write-special-chars-readback","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of \u002Ftmp helper scripts.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-readback\u002FSKILL.md",[],[99,100,79,89,101,102,90,26,33,103,104,105,106,35,84,34],"readback","write special chars readback","cleanup","read","verification","via","post","helper",{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":37},"01M6KKMEGX9M9NC105J0W3Q5B9","write-special-chars-heredoc","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) by using a Python heredoc script executed via shell.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-heredoc\u002FSKILL.md",[],[79,114,26,35,104,89,115,90,84],"write special chars heredoc","shell",{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":127,"publishedAt":37},"01M6KKM8EJ2AATVHZBNB916WT0","worldmonitor-reference","Curated architecture index of the WorldMonitor open-source dashboard. Reference for extracting patterns — vanilla TypeScript, Panel class hierarchy, service layer, CSS grid, API edge functions, refresh scheduler, and 60+ data source integrations.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fworldmonitor-reference\u002FSKILL.md",[122],{"categoryNo":123,"categoryName":124,"taxonomyType":125,"taxonomyTypeDesc":126},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[128,129,130,131,91,132,133,134,135,36,35,136,137,138,139,140,141,142,30,143],"reference","worldmonitor","worldmonitor reference","dashboard","css","architecture","extracting","hierarchy","layer","panel","patterns","edge functions","integrations","open","api","scheduler",{"skillNo":145,"name":146,"nameZh":6,"description":147,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":148,"categories":149,"keywords":150,"publishedAt":37},"01M6KKM39PHYK627F19GE2B9XN","virtual-list","Implement efficient virtual scrolling for rendering large lists with DOM recycling, chunk-based rendering, and performance optimizations","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvirtual-list\u002FSKILL.md",[],[151,152,153,154,35,155,34,156,157,158,159],"virtual list","list","virtual","chunk","dom","rendering","recycling","implement","performance",{"skillNo":161,"name":162,"nameZh":6,"description":163,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":164,"categories":165,"keywords":166,"publishedAt":37},"01M6KKKY7T2P61Y0JH54CDEJKQ","verify-directory-structure","Diagnose and resolve file access issues by first verifying the directory structure.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fverify-directory-structure\u002FSKILL.md",[],[167,168,169,170,171,172,90,173,174,175],"directory","verify","structure","verify directory structure","access","first","issues","diagnose","file access"]