[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KG5P35WJY02WVB86B9548F":3,"skill-same:01M6KG5P35WJY02WVB86B9548F":72},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":14,"repositoryHtmlUrl":47,"repositoryHomepageUrl":6,"ownerHtmlUrl":48,"ownerBlogUrl":49,"ownerDescription":50,"updatedAt":51,"install":52,"resources":65},"01M6KG5P35WJY02WVB86B9548F","spreadsheet-create-verify-gate",null,"Create or edit Excel workbooks with openpyxl-specific pitfall handling, anchored preflight audit, and deterministic post-write proof that every criterion is satisfied","xyliu-cs\u002FOpenSpace-GDPval","xyliu-cs","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F89236536?v=4","01M6KF8Z1V4TXS86CKSH48BY8T","xy","01M6KF8Z67443W0SHXM85JEF0B",0,"MIT","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-proof-gate-merged-fedf41\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000004","电子表格","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"create","spreadsheet","verify","gate","spreadsheet create verify gate","xlsx","audit","preflight","write","edit","deterministic","proof","post","with","openpyxl","2026-11-10 10:12:30",false,"---\nname: spreadsheet-create-verify-gate\ndescription: Create or edit Excel workbooks with openpyxl-specific pitfall handling, anchored preflight audit, and deterministic post-write proof that every criterion is satisfied\n---\n\n# Spreadsheet Create\u002FVerify Gate\n\nUse this skill when you must **create from scratch** or **modify** an Excel workbook and the result must be proven against a user specification rather than merely described.\n\nThis skill extends the spreadsheet-proof-gate methodology with explicit support for:\n\n- **Workbook creation from scratch** (not just editing existing files)\n- **openpyxl-specific pitfall handling** (MergedCell, worksheet creation, formula handling)\n- **Tool failure resilience** with clear escalation paths\n- **Pre-edit audit phases** that catch common openpyxl errors before they occur\n\nThis is a workflow skill requiring a direct Python verification pass with `openpyxl` before reporting success. **The verification script must be saved to a .py file and executed via run_shell (NOT execute_code_sandbox).**\n\n## When to use\n\nUse this skill when ANY of the following are true:\n\n### Creation scenarios:\n- You must create a new Excel workbook from scratch\n- No existing template is provided\n- You need to establish the initial workbook structure\n\n### Editing scenarios:\n- The workbook path must be discovered\n- Multiple similar Excel files may exist\n- The user requires exact sheet names, columns, counts, or samples\n- Prior summaries are inconsistent or not trustworthy\n- Exact post-edit workbook state matters\n\n### General:\n- You must prove that mandatory criteria were satisfied\n- A delegated agent may perform spreadsheet work\n- Tool instability has been observed in prior attempts\n\n## Core rules\n\n### Rule 1: Creation vs. Editing distinction\n\nBefore starting, determine which path applies:\n\n**Creation path** (new workbook):\n- No existing workbook at the target path\n- You are establishing the initial structure\n- Pre-edit audit focuses on workspace validation and structure planning\n\n**Editing path** (existing workbook):\n- Existing workbook at the target path\n- You are modifying structure or content\n- Pre-edit audit includes full workbook structure inspection\n\n### Rule 2: Openpyxl pitfall awareness\n\nThe following openpyxl-specific issues must be handled explicitly:\n\n**MergedCell errors:**\n- Accessing `.value` on merged cells raises `MergedCell` exception\n- **Solution**: Check `ws.merged_cells.ranges` and handle merged regions specially\n- **Pre-edit check**: Identify all merged ranges before accessing cell values\n\n**Worksheet creation patterns:**\n- `wb.create_sheet()` is the correct method, not direct assignment\n- Sheet names must be unique and ≤31 characters\n- Invalid characters (`\\ \u002F ? * [ ]`) are not allowed in sheet names\n\n**Formula handling:**\n- Set `data_only=False` when loading to preserve formulas\n- Use `wb.save()` after modifications, not `wb.close()`\n- Formula cells need explicit formula strings, not calculated values\n\n**Cell value type handling:**\n- Dates, numbers, and strings may need explicit type handling\n- Use `cell.value` not direct cell access for safety\n\n### Rule 3: Never finalize from narrative summary alone\n\nA workbook task is only complete when:\n\n1. The target workbook path was identified (for editing) or chosen (for creation)\n2. Pre-edit structure matched the intended operation\n3. The edit\u002Fcreation was performed on the correct file\n4. The saved workbook was directly re-read from disk\n5. Every requested criterion was checked in a deterministic verification report\n6. Each criterion is marked as one of: `PASS`, `FAIL`, or `UNAVAILABLE-IN-SOURCE`\n7. Any non-pass result is explicitly reconciled before finalizing\n\n### Rule 4: Workspace anchoring is absolute\n\nAll discovery, reads, writes, and verification must be anchored to the exact workspace path provided for the task.\n\n- Treat the provided workspace path as the authoritative root\n- Resolve workbooks to exact paths under that root\n- Do not silently switch to similarly named files elsewhere\n- If the anchored file cannot be found for editing, stop rather than guessing\n- For creation, ensure the output directory exists\n\n## Outcome contract\n\nYour output should be based on proof, not inference.\n\nFor every task using this workflow, maintain these artifacts internally:\n\n1. **Workbook inventory**: path, existence status, sheet structure (for editing) OR planned structure (for creation)\n2. **Pre-edit audit checklist**: workbook structure before modification\n3. **Post-write proof checklist**: deterministic verification of every criterion\n\nThe post-write proof checklist is decisive.\n\n# Workflow\n\n## Phase 1: Determine creation vs. editing path\n\n### Step 1.1: Check for existing workbook\n\n```python\nfrom pathlib import Path\ntarget_path = Path(\"path\u002Fto\u002Fworkbook.xlsx\")\nexists = target_path.exists()\n```\n\n**If `exists == False` and user expects to create new workbook:**\n- Follow the **creation path** (Phase 2A)\n\n**If `exists == True` and user expects to edit:**\n- Follow the **editing path** (Phase 2B)\n\n**If `exists == False` but user expects to edit:**\n- **STOP** and report: workbook not found at anchored path\n- Do not proceed with creation unless user explicitly requests it\n\n### Step 1.2: Validate workspace for creation\n\nFor creation path, confirm:\n\n- Output directory exists or can be created\n- No conflicting file at target path\n- Sufficient permissions inferred from workspace context\n\n## Phase 2A: Creation path pre-audit\n\n### Step 2A.1: Plan workbook structure\n\nBefore writing any code, document:\n\n- All sheet names to be created\n- Column headers for each sheet\n- Expected row counts\n- Any formulas to be inserted\n- Any merged cell regions\n- Any special formatting requirements\n\n### Step 2A.2: Check for openpyxl pitfalls\n\n**Merged cell planning:**\n- If merged cells are required, plan the merge ranges explicitly\n- Ensure merged ranges don't overlap\n- Plan to populate only the top-left cell of merged regions\n\n**Sheet name validation:**\n- All names ≤31 characters\n- No invalid characters: `\\ \u002F ? * [ ]`\n- All names unique (case-sensitive in openpyxl)\n\n**Data type planning:**\n- Dates: use Python `datetime` objects, not strings\n- Numbers: use numeric types, not formatted strings\n- Formulas: use Excel formula syntax as strings\n\n## Phase 2B: Editing path pre-audit\n\n### Step 2B.1: Discover and confirm workbook identity\n\nSearch under the exact workspace root for plausible Excel files:\n- `.xlsx`, `.xlsm`, `.xls`\n\nConfirm:\n- Exact anchored path\n- File existence\n- Workbook readability (can be loaded by openpyxl)\n\n### Step 2B.2: Openpyxl-safe structure inspection\n\n```python\nfrom openpyxl import load_workbook\n\n# Always use data_only=False to preserve formulas\nwb = load_workbook(target_path, data_only=False)\n\n# Get all sheet names\nsheet_names = wb.sheetnames\n\n# For each sheet, inspect safely\nfor ws in wb.worksheets:\n    # Check for merged cells BEFORE accessing values\n    merged_ranges = list(ws.merged_cells.ranges)\n    \n    # Get headers safely\n    headers = []\n    for cell in ws[1]:  # Row 1\n        # Check if cell is part of a merged range\n        is_merged = any(cell.coordinate in mr for mr in merged_ranges)\n        if is_merged:\n            # Get value from top-left of merged range\n            for mr in merged_ranges:\n                if cell.coordinate in mr:\n                    headers.append(ws[mr.min_row][mr.min_col - 1].value)\n                    break\n        else:\n            headers.append(cell.value)\n```\n\n### Step 2B.3: Identity consistency check\n\nIf you inspect the workbook multiple times:\n- Inspections must agree on: path, sheet names, row counts, headers\n- If they disagree, treat workbook identity as unconfirmed\n- Do not edit until reconciled\n\n## Phase 3: Convert requirements into explicit criteria\n\nBefore editing\u002Fcreating, extract every verifiable requirement.\n\n**For creation tasks:**\n- `output-exists: workbook created at \u003Cpath>`\n- `required-sheet: \u003Cname> exists`\n- `required-column: Sheet \u003Cname> has column \"\u003Ccolumn>\"`\n- `row-count: Sheet \u003Cname> has exactly N data rows`\n- `data-populated: Column \u003CX> contains values for all data rows`\n- `formula: Column \u003CY> contains formulas`\n- `merged-region: Sheet \u003Cname> has merged range \u003Crange>`\n\n**For editing tasks:**\n- All creation criteria, plus:\n- `preservation: Sheet \u003Cname> still exists unchanged`\n- `unchanged-sheets: \u003Clist> were not modified`\n- `macro-preservation: VBA macros preserved (if applicable)`\n\n### Good criterion examples:\n- `required-sheet: Summary exists`\n- `required-column: Sheet Sample has column \"Selected\"`\n- `row-count: exactly 25 data rows in Sample`\n- `formula: column H contains formulas for all populated rows`\n- `merged-region: Summary A1:B1 is merged`\n\n### Bad criterion examples:\n- `workbook looks right`\n- `sampling seems okay`\n- `most tabs present`\n\n## Phase 4: Pre-edit go\u002Fno-go gate\n\nProceed only if ALL are true:\n\n**For creation:**\n- Output directory is valid\n- Planned sheet names are valid (length, characters, uniqueness)\n- Planned structure is coherent\n- No conflicting file at target path\n\n**For editing:**\n- Workbook identity is confirmed\n- Target sheet is unambiguous\n- Required columns exist or can be added safely\n- Row counts are plausible\n- No unresolved inspection conflicts remain\n- Requested edit is possible from available source data\n\n**For both:**\n- Openpyxl pitfalls have been planned for (merged cells, etc.)\n- All required criteria are checkable\n\nOtherwise, stop and report the mismatch.\n\n## Phase 5: Perform the creation\u002Fedit\n\n### For creation:\n\n```python\nfrom openpyxl import Workbook\n\nwb = Workbook()\n# Remove default sheet if creating custom structure\nif 'Sheet' in wb.sheetnames:\n    del wb['Sheet']\n\n# Create sheets with validated names\nfor sheet_name in planned_sheets:\n    ws = wb.create_sheet(title=sheet_name)\n    # Populate headers\n    for col_idx, header in enumerate(headers, start=1):\n        ws.cell(row=1, column=col_idx, value=header)\n    # Populate data rows\n    for row_idx, row_data in enumerate(data_rows, start=2):\n        for col_idx, value in enumerate(row_data, start=1):\n            ws.cell(row=row_idx, column=col_idx, value=value)\n    # Apply merges if planned\n    for merge_range in planned_merges:\n        ws.merge_cells(merge_range)\n\nwb.save(output_path)\n```\n\n### For editing:\n\n```python\nfrom openpyxl import load_workbook\n\nwb = load_workbook(target_path, data_only=False)\nws = wb[sheet_name]\n\n# Handle merged cells when reading\nmerged_ranges = list(ws.merged_cells.ranges)\n\n# When modifying, be careful with merged regions\n# Don't write to cells within merged ranges (except top-left)\n\n# Modify content\nws.cell(row=row, column=col, value=new_value)\n\n# Add new sheet if needed\nif new_sheet_name not in wb.sheetnames:\n    wb.create_sheet(title=new_sheet_name)\n\nwb.save(output_path)\n```\n\n### Record what was done:\n\n- Workbook path edited\u002Fcreated\n- Output path written\n- Sheets modified or created\n- Columns added or populated\n- Rows added or updated\n- Formulas inserted\n- Merged regions applied\n- Any assumptions made\n\n## Phase 6: Deterministic post-write proof\n\n**This phase is mandatory.**\n\nAfter saving, directly inspect the saved workbook from disk with Python and `openpyxl`. Do not finalize from memory, delegated prose, or a generic success message.\n\n### Verification script procedure\n\n```python\nfrom pathlib import Path\nfrom openpyxl import load_workbook\n\nWORKBOOK = Path(\"TARGET.xlsx\")\nTRUTHY = {\"x\", \"yes\", \"true\", \"1\", \"y\"}\n\ndef norm(v):\n    if v is None:\n        return \"\"\n    return str(v).strip()\n\ndef lower(v):\n    return norm(v).lower()\n\ndef first_nonempty_row(ws, max_scan=20):\n    for r in ws.iter_rows(min_row=1, max_row=min(ws.max_row, max_scan), values_only=True):\n        vals = list(r)\n        if any(norm(v) != \"\" for v in vals):\n            return vals\n    return []\n\ndef data_rows(ws, header_row_idx=1):\n    count = 0\n    for row in ws.iter_rows(min_row=header_row_idx + 1, values_only=True):\n        if any(norm(v) != \"\" for v in row):\n            count += 1\n    return count\n\ndef safe_cell_value(ws, coord, merged_ranges=None):\n    \"\"\"Safely get cell value, handling merged cells\"\"\"\n    cell = ws[coord]\n    if merged_ranges:\n        for mr in merged_ranges:\n            if coord in mr:\n                # Return value from top-left of merged range\n                return ws[mr.min_row][mr.min_col - 1].value\n    return cell.value\n\nprint(f\"WORKBOOK: {WORKBOOK}\")\nprint(f\"EXISTS: {WORKBOOK.exists()}\")\n\nif not WORKBOOK.exists():\n    print(\"CRITERION|output-exists|FAIL|Workbook file missing\")\n    raise SystemExit(0)\n\nwb = load_workbook(WORKBOOK, data_only=False)\nprint(f\"SHEETS: {wb.sheetnames}\")\n\nfor ws in wb.worksheets:\n    merged_ranges = list(ws.merged_cells.ranges)\n    headers = first_nonempty_row(ws)\n    print(f\"SHEET|{ws.title}|HEADERS|{headers}\")\n    print(f\"SHEET|{ws.title}|DATA_ROWS|{data_rows(ws)}\")\n    print(f\"SHEET|{ws.title}|MERGED_RANGES|{[str(mr) for mr in merged_ranges]}\")\n\n# Check each criterion\n# Example:\n# required_sheets = [\"Summary\", \"Data\"]\n# for sheet in required_sheets:\n#     status = \"PASS\" if sheet in wb.sheetnames else \"FAIL\"\n#     print(f\"CRITERION|required-sheet-{sheet}|{status}|Sheet {sheet} {'found' if status == 'PASS' else 'missing'}\")\n\n# Print all criteria with status\nfor criterion_line in criteria:\n    print(criterion_line)\n```\n\n### Required proof outputs\n\nThe verification must report:\n- Inspected file path\n- Whether the file exists\n- Workbook sheet names\n- Per-sheet headers for relevant sheets\n- Per-sheet non-empty row counts\n- Merged cell ranges (if applicable)\n- Formula presence (if relevant)\n- Preservation of required source sheets (for editing)\n- Criterion checklist with status for each item\n\n### Status vocabulary\n\nEach criterion must end in exactly one status:\n\n- `PASS` — requirement satisfied by direct inspection\n- `FAIL` — requirement not satisfied\n- `UNAVAILABLE-IN-SOURCE` — requirement could not be satisfied because required source information was absent\n\nDo not use softer wording like:\n- looks okay\n- appears complete\n- probably satisfied\n- seems unavailable\n\n## Finalization gate\n\nYou may finalize only when every required criterion is either:\n\n- `PASS`, or\n- `UNAVAILABLE-IN-SOURCE` with explicit reconciliation\n\nYou must not finalize when:\n\n- Any mandatory criterion remains `FAIL`\n- A claimed output file was not verified from disk\n- The workbook path is uncertain\n- Post-write proof was not run\n- You only have delegated summary evidence\n- Requested counts differ from actual counts without reconciliation\n- Required sheet names or headers are missing\n- Openpyxl errors occurred during verification (indicates file corruption or structural issues)\n\nIf direct proof says the workbook is incomplete, that proof is authoritative.\n\n## Error handling and resilience\n\n### Tool failure patterns\n\nIf `execute_code_sandbox` or `run_shell` returns opaque errors:\n\n1. **Retry once** with the same command (may be transient)\n2. **If still failing**, try alternative approach:\n   - If `execute_code_sandbox` fails, try `run_shell` with python script\n   - If `run_shell` fails, try `execute_code_sandbox`\n   - If both fail, use `shell_agent` for autonomous execution\n\n### openpyxl-specific errors\n\n**MergedCell AttributeError:**\n- **Symptom**: Accessing `.value` on merged cells raises exception\n- **Fix**: Check `ws.merged_cells.ranges` before accessing; get value from top-left cell\n\n**Invalid sheet name:**\n- **Symptom**: ValueError on sheet creation\n- **Fix**: Validate names before creation (≤31 chars, no `\\ \u002F ? * [ ]`)\n\n**Formula parsing errors:**\n- **Symptom**: Formula not calculating correctly\n- **Fix**: Use `data_only=False` when loading; verify formula syntax is Excel-compatible\n\n**File lock\u002Fpermission errors:**\n- **Symptom**: Cannot save or load workbook\n- **Fix**: Ensure file is not open in another process; verify directory permissions\n\n### Escalation to shell_agent\n\nIf spreadsheet operations fail repeatedly (>2 attempts):\n\n```python\nshell_agent(\n    task=\"\"\"\n    Create\u002Fmodify Excel workbook at \u003Cexact_path>.\n    \n    Required structure:\n    - Sheets: \u003Clist>\n    - Columns per sheet: \u003Cspecification>\n    - Data to populate: \u003Cdetails>\n    - Formulas: \u003Cspecification>\n    - Merged regions: \u003Cif any>\n    \n    Handle openpyxl pitfalls:\n    - Check merged_cells.ranges before accessing cell values\n    - Validate sheet names (31 chars max, no special chars)\n    - Use data_only=False when loading to preserve formulas\n    \n    Provide: created file path, sheets created, row counts, any errors encountered.\n    \"\"\",\n    timeout=300\n)\n```\n\nThen verify shell_agent output with the Phase 6 proof procedure.\n**Tool requirement**: Write verification script to a .py file and execute via `run_shell`, NOT `execute_code_sandbox`. This ensures reliability when sandbox providers are unavailable.\n**Step 6.1: Write script to disk first**\n\nCreate a Python file (e.g., `verify_workbook.py`) with the verification logic, then execute it via shell.\n\n**Step 6.2: Execute via run_shell**\n\n```bash\npython verify_workbook.py\n```\n\n**Step 6.3: Parse verification output**\n\nThe script must output explicit PASS\u002FFAIL markers for each criterion.\n","# Spreadsheet Create\u002FVerify Gate\n\nUse this skill when you must **create from scratch** or **modify** an Excel workbook and the result must be proven against a user specification rather than merely described.\n\nThis skill extends the spreadsheet-proof-gate methodology with explicit support for:\n\n- **Workbook creation from scratch** (not just editing existing files)\n- **openpyxl-specific pitfall handling** (MergedCell, worksheet creation, formula handling)\n- **Tool failure resilience** with clear escalation paths\n- **Pre-edit audit phases** that catch common openpyxl errors before they occur\n\nThis is a workflow skill requiring a direct Python verification pass with `openpyxl` before reporting success. **The verification script must be saved to a .py file and executed via run_shell (NOT execute_code_sandbox).**\n\n## When to use\n\nUse this skill when ANY of the following are true:\n\n### Creation scenarios:\n- You must create a new Excel workbook from scratch\n- No existing template is provided\n- You need to establish the initial workbook structure\n\n### Editing scenarios:\n- The workbook path must be discovered\n- Multiple similar Excel files may exist\n- The user requires exact sheet names, columns, counts, or samples\n- Prior summaries are inconsistent or not trustworthy\n- Exact post-edit workbook state matters\n\n### General:\n- You must prove that mandatory criteria were satisfied\n- A delegated agent may perform spreadsheet work\n- Tool instability has been observed in prior attempts\n\n## Core rules\n\n### Rule 1: Creation vs. Editing distinction\n\nBefore starting, determine which path applies:\n\n**Creation path** (new workbook):\n- No existing workbook at the target path\n- You are establishing the initial structure\n- Pre-edit audit focuses on workspace validation and structure planning\n\n**Editing path** (existing workbook):\n- Existing workbook at the target path\n- You are modifying structure or content\n- Pre-edit audit includes full workbook structure inspection\n\n### Rule 2: Openpyxl pitfall awareness\n\nThe following openpyxl-specific issues must be handled explicitly:\n\n**MergedCell errors:**\n- Accessing `.value` on merged cells raises `MergedCell` exception\n- **Solution**: Check `ws.merged_cells.ranges` and handle merged regions specially\n- **Pre-edit check**: Identify all merged ranges before accessing cell values\n\n**Worksheet creation patterns:**\n- `wb.create_sheet()` is the correct method, not direct assignment\n- Sheet names must be unique and ≤31 characters\n- Invalid characters (`\\ \u002F ? * [ ]`) are not allowed in sheet names\n\n**Formula handling:**\n- Set `data_only=False` when loading to preserve formulas\n- Use `wb.save()` after modifications, not `wb.close()`\n- Formula cells need explicit formula strings, not calculated values\n\n**Cell value type handling:**\n- Dates, numbers, and strings may need explicit type handling\n- Use `cell.value` not direct cell access for safety\n\n### Rule 3: Never finalize from narrative summary alone\n\nA workbook task is only complete when:\n\n1. The target workbook path was identified (for editing) or chosen (for creation)\n2. Pre-edit structure matched the intended operation\n3. The edit\u002Fcreation was performed on the correct file\n4. The saved workbook was directly re-read from disk\n5. Every requested criterion was checked in a deterministic verification report\n6. Each criterion is marked as one of: `PASS`, `FAIL`, or `UNAVAILABLE-IN-SOURCE`\n7. Any non-pass result is explicitly reconciled before finalizing\n\n### Rule 4: Workspace anchoring is absolute\n\nAll discovery, reads, writes, and verification must be anchored to the exact workspace path provided for the task.\n\n- Treat the provided workspace path as the authoritative root\n- Resolve workbooks to exact paths under that root\n- Do not silently switch to similarly named files elsewhere\n- If the anchored file cannot be found for editing, stop rather than guessing\n- For creation, ensure the output directory exists\n\n## Outcome contract\n\nYour output should be based on proof, not inference.\n\nFor every task using this workflow, maintain these artifacts internally:\n\n1. **Workbook inventory**: path, existence status, sheet structure (for editing) OR planned structure (for creation)\n2. **Pre-edit audit checklist**: workbook structure before modification\n3. **Post-write proof checklist**: deterministic verification of every criterion\n\nThe post-write proof checklist is decisive.\n\n# Workflow\n\n## Phase 1: Determine creation vs. editing path\n\n### Step 1.1: Check for existing workbook\n\n```python\nfrom pathlib import Path\ntarget_path = Path(\"path\u002Fto\u002Fworkbook.xlsx\")\nexists = target_path.exists()\n```\n\n**If `exists == False` and user expects to create new workbook:**\n- Follow the **creation path** (Phase 2A)\n\n**If `exists == True` and user expects to edit:**\n- Follow the **editing path** (Phase 2B)\n\n**If `exists == False` but user expects to edit:**\n- **STOP** and report: workbook not found at anchored path\n- Do not proceed with creation unless user explicitly requests it\n\n### Step 1.2: Validate workspace for creation\n\nFor creation path, confirm:\n\n- Output directory exists or can be created\n- No conflicting file at target path\n- Sufficient permissions inferred from workspace context\n\n## Phase 2A: Creation path pre-audit\n\n### Step 2A.1: Plan workbook structure\n\nBefore writing any code, document:\n\n- All sheet names to be created\n- Column headers for each sheet\n- Expected row counts\n- Any formulas to be inserted\n- Any merged cell regions\n- Any special formatting requirements\n\n### Step 2A.2: Check for openpyxl pitfalls\n\n**Merged cell planning:**\n- If merged cells are required, plan the merge ranges explicitly\n- Ensure merged ranges don't overlap\n- Plan to populate only the top-left cell of merged regions\n\n**Sheet name validation:**\n- All names ≤31 characters\n- No invalid characters: `\\ \u002F ? * [ ]`\n- All names unique (case-sensitive in openpyxl)\n\n**Data type planning:**\n- Dates: use Python `datetime` objects, not strings\n- Numbers: use numeric types, not formatted strings\n- Formulas: use Excel formula syntax as strings\n\n## Phase 2B: Editing path pre-audit\n\n### Step 2B.1: Discover and confirm workbook identity\n\nSearch under the exact workspace root for plausible Excel files:\n- `.xlsx`, `.xlsm`, `.xls`\n\nConfirm:\n- Exact anchored path\n- File existence\n- Workbook readability (can be loaded by openpyxl)\n\n### Step 2B.2: Openpyxl-safe structure inspection\n\n```python\nfrom openpyxl import load_workbook\n\n# Always use data_only=False to preserve formulas\nwb = load_workbook(target_path, data_only=False)\n\n# Get all sheet names\nsheet_names = wb.sheetnames\n\n# For each sheet, inspect safely\nfor ws in wb.worksheets:\n    # Check for merged cells BEFORE accessing values\n    merged_ranges = list(ws.merged_cells.ranges)\n    \n    # Get headers safely\n    headers = []\n    for cell in ws[1]:  # Row 1\n        # Check if cell is part of a merged range\n        is_merged = any(cell.coordinate in mr for mr in merged_ranges)\n        if is_merged:\n            # Get value from top-left of merged range\n            for mr in merged_ranges:\n                if cell.coordinate in mr:\n                    headers.append(ws[mr.min_row][mr.min_col - 1].value)\n                    break\n        else:\n            headers.append(cell.value)\n```\n\n### Step 2B.3: Identity consistency check\n\nIf you inspect the workbook multiple times:\n- Inspections must agree on: path, sheet names, row counts, headers\n- If they disagree, treat workbook identity as unconfirmed\n- Do not edit until reconciled\n\n## Phase 3: Convert requirements into explicit criteria\n\nBefore editing\u002Fcreating, extract every verifiable requirement.\n\n**For creation tasks:**\n- `output-exists: workbook created at \u003Cpath>`\n- `required-sheet: \u003Cname> exists`\n- `required-column: Sheet \u003Cname> has column \"\u003Ccolumn>\"`\n- `row-count: Sheet \u003Cname> has exactly N data rows`\n- `data-populated: Column \u003CX> contains values for all data rows`\n- `formula: Column \u003CY> contains formulas`\n- `merged-region: Sheet \u003Cname> has merged range \u003Crange>`\n\n**For editing tasks:**\n- All creation criteria, plus:\n- `preservation: Sheet \u003Cname> still exists unchanged`\n- `unchanged-sheets: \u003Clist> were not modified`\n- `macro-preservation: VBA macros preserved (if applicable)`\n\n### Good criterion examples:\n- `required-sheet: Summary exists`\n- `required-column: Sheet Sample has column \"Selected\"`\n- `row-count: exactly 25 data rows in Sample`\n- `formula: column H contains formulas for all populated rows`\n- `merged-region: Summary A1:B1 is merged`\n\n### Bad criterion examples:\n- `workbook looks right`\n- `sampling seems okay`\n- `most tabs present`\n\n## Phase 4: Pre-edit go\u002Fno-go gate\n\nProceed only if ALL are true:\n\n**For creation:**\n- Output directory is valid\n- Planned sheet names are valid (length, characters, uniqueness)\n- Planned structure is coherent\n- No conflicting file at target path\n\n**For editing:**\n- Workbook identity is confirmed\n- Target sheet is unambiguous\n- Required columns exist or can be added safely\n- Row counts are plausible\n- No unresolved inspection conflicts remain\n- Requested edit is possible from available source data\n\n**For both:**\n- Openpyxl pitfalls have been planned for (merged cells, etc.)\n- All required criteria are checkable\n\nOtherwise, stop and report the mismatch.\n\n## Phase 5: Perform the creation\u002Fedit\n\n### For creation:\n\n```python\nfrom openpyxl import Workbook\n\nwb = Workbook()\n# Remove default sheet if creating custom structure\nif 'Sheet' in wb.sheetnames:\n    del wb['Sheet']\n\n# Create sheets with validated names\nfor sheet_name in planned_sheets:\n    ws = wb.create_sheet(title=sheet_name)\n    # Populate headers\n    for col_idx, header in enumerate(headers, start=1):\n        ws.cell(row=1, column=col_idx, value=header)\n    # Populate data rows\n    for row_idx, row_data in enumerate(data_rows, start=2):\n        for col_idx, value in enumerate(row_data, start=1):\n            ws.cell(row=row_idx, column=col_idx, value=value)\n    # Apply merges if planned\n    for merge_range in planned_merges:\n        ws.merge_cells(merge_range)\n\nwb.save(output_path)\n```\n\n### For editing:\n\n```python\nfrom openpyxl import load_workbook\n\nwb = load_workbook(target_path, data_only=False)\nws = wb[sheet_name]\n\n# Handle merged cells when reading\nmerged_ranges = list(ws.merged_cells.ranges)\n\n# When modifying, be careful with merged regions\n# Don't write to cells within merged ranges (except top-left)\n\n# Modify content\nws.cell(row=row, column=col, value=new_value)\n\n# Add new sheet if needed\nif new_sheet_name not in wb.sheetnames:\n    wb.create_sheet(title=new_sheet_name)\n\nwb.save(output_path)\n```\n\n### Record what was done:\n\n- Workbook path edited\u002Fcreated\n- Output path written\n- Sheets modified or created\n- Columns added or populated\n- Rows added or updated\n- Formulas inserted\n- Merged regions applied\n- Any assumptions made\n\n## Phase 6: Deterministic post-write proof\n\n**This phase is mandatory.**\n\nAfter saving, directly inspect the saved workbook from disk with Python and `openpyxl`. Do not finalize from memory, delegated prose, or a generic success message.\n\n### Verification script procedure\n\n```python\nfrom pathlib import Path\nfrom openpyxl import load_workbook\n\nWORKBOOK = Path(\"TARGET.xlsx\")\nTRUTHY = {\"x\", \"yes\", \"true\", \"1\", \"y\"}\n\ndef norm(v):\n    if v is None:\n        return \"\"\n    return str(v).strip()\n\ndef lower(v):\n    return norm(v).lower()\n\ndef first_nonempty_row(ws, max_scan=20):\n    for r in ws.iter_rows(min_row=1, max_row=min(ws.max_row, max_scan), values_only=True):\n        vals = list(r)\n        if any(norm(v) != \"\" for v in vals):\n            return vals\n    return []\n\ndef data_rows(ws, header_row_idx=1):\n    count = 0\n    for row in ws.iter_rows(min_row=header_row_idx + 1, values_only=True):\n        if any(norm(v) != \"\" for v in row):\n            count += 1\n    return count\n\ndef safe_cell_value(ws, coord, merged_ranges=None):\n    \"\"\"Safely get cell value, handling merged cells\"\"\"\n    cell = ws[coord]\n    if merged_ranges:\n        for mr in merged_ranges:\n            if coord in mr:\n                # Return value from top-left of merged range\n                return ws[mr.min_row][mr.min_col - 1].value\n    return cell.value\n\nprint(f\"WORKBOOK: {WORKBOOK}\")\nprint(f\"EXISTS: {WORKBOOK.exists()}\")\n\nif not WORKBOOK.exists():\n    print(\"CRITERION|output-exists|FAIL|Workbook file missing\")\n    raise SystemExit(0)\n\nwb = load_workbook(WORKBOOK, data_only=False)\nprint(f\"SHEETS: {wb.sheetnames}\")\n\nfor ws in wb.worksheets:\n    merged_ranges = list(ws.merged_cells.ranges)\n    headers = first_nonempty_row(ws)\n    print(f\"SHEET|{ws.title}|HEADERS|{headers}\")\n    print(f\"SHEET|{ws.title}|DATA_ROWS|{data_rows(ws)}\")\n    print(f\"SHEET|{ws.title}|MERGED_RANGES|{[str(mr) for mr in merged_ranges]}\")\n\n# Check each criterion\n# Example:\n# required_sheets = [\"Summary\", \"Data\"]\n# for sheet in required_sheets:\n#     status = \"PASS\" if sheet in wb.sheetnames else \"FAIL\"\n#     print(f\"CRITERION|required-sheet-{sheet}|{status}|Sheet {sheet} {'found' if status == 'PASS' else 'missing'}\")\n\n# Print all criteria with status\nfor criterion_line in criteria:\n    print(criterion_line)\n```\n\n### Required proof outputs\n\nThe verification must report:\n- Inspected file path\n- Whether the file exists\n- Workbook sheet names\n- Per-sheet headers for relevant sheets\n- Per-sheet non-empty row counts\n- Merged cell ranges (if applicable)\n- Formula presence (if relevant)\n- Preservation of required source sheets (for editing)\n- Criterion checklist with status for each item\n\n### Status vocabulary\n\nEach criterion must end in exactly one status:\n\n- `PASS` — requirement satisfied by direct inspection\n- `FAIL` — requirement not satisfied\n- `UNAVAILABLE-IN-SOURCE` — requirement could not be satisfied because required source information was absent\n\nDo not use softer wording like:\n- looks okay\n- appears complete\n- probably satisfied\n- seems unavailable\n\n## Finalization gate\n\nYou may finalize only when every required criterion is either:\n\n- `PASS`, or\n- `UNAVAILABLE-IN-SOURCE` with explicit reconciliation\n\nYou must not finalize when:\n\n- Any mandatory criterion remains `FAIL`\n- A claimed output file was not verified from disk\n- The workbook path is uncertain\n- Post-write proof was not run\n- You only have delegated summary evidence\n- Requested counts differ from actual counts without reconciliation\n- Required sheet names or headers are missing\n- Openpyxl errors occurred during verification (indicates file corruption or structural issues)\n\nIf direct proof says the workbook is incomplete, that proof is authoritative.\n\n## Error handling and resilience\n\n### Tool failure patterns\n\nIf `execute_code_sandbox` or `run_shell` returns opaque errors:\n\n1. **Retry once** with the same command (may be transient)\n2. **If still failing**, try alternative approach:\n   - If `execute_code_sandbox` fails, try `run_shell` with python script\n   - If `run_shell` fails, try `execute_code_sandbox`\n   - If both fail, use `shell_agent` for autonomous execution\n\n### openpyxl-specific errors\n\n**MergedCell AttributeError:**\n- **Symptom**: Accessing `.value` on merged cells raises exception\n- **Fix**: Check `ws.merged_cells.ranges` before accessing; get value from top-left cell\n\n**Invalid sheet name:**\n- **Symptom**: ValueError on sheet creation\n- **Fix**: Validate names before creation (≤31 chars, no `\\ \u002F ? * [ ]`)\n\n**Formula parsing errors:**\n- **Symptom**: Formula not calculating correctly\n- **Fix**: Use `data_only=False` when loading; verify formula syntax is Excel-compatible\n\n**File lock\u002Fpermission errors:**\n- **Symptom**: Cannot save or load workbook\n- **Fix**: Ensure file is not open in another process; verify directory permissions\n\n### Escalation to shell_agent\n\nIf spreadsheet operations fail repeatedly (>2 attempts):\n\n```python\nshell_agent(\n    task=\"\"\"\n    Create\u002Fmodify Excel workbook at \u003Cexact_path>.\n    \n    Required structure:\n    - Sheets: \u003Clist>\n    - Columns per sheet: \u003Cspecification>\n    - Data to populate: \u003Cdetails>\n    - Formulas: \u003Cspecification>\n    - Merged regions: \u003Cif any>\n    \n    Handle openpyxl pitfalls:\n    - Check merged_cells.ranges before accessing cell values\n    - Validate sheet names (31 chars max, no special chars)\n    - Use data_only=False when loading to preserve formulas\n    \n    Provide: created file path, sheets created, row counts, any errors encountered.\n    \"\"\",\n    timeout=300\n)\n```\n\nThen verify shell_agent output with the Phase 6 proof procedure.\n**Tool requirement**: Write verification script to a .py file and execute via `run_shell`, NOT `execute_code_sandbox`. This ensures reliability when sandbox providers are unavailable.\n**Step 6.1: Write script to disk first**\n\nCreate a Python file (e.g., `verify_workbook.py`) with the verification logic, then execute it via shell.\n\n**Step 6.2: Execute via run_shell**\n\n```bash\npython verify_workbook.py\n```\n\n**Step 6.3: Parse verification output**\n\nThe script must output explicit PASS\u002FFAIL markers for each criterion.\n",{"name":5,"description":7},"main","af1b40a42167d09c30b3a63000aa14ace4c1e229","gdpval_bench\u002Fskills\u002Fspreadsheet-proof-gate-merged-fedf41","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs","https:\u002F\u002Fxyliu-cs.github.io","PhD Student in CS, CUHK-Shenzhen.","2026-04-06 20:32:15",{"source":8,"skillName":5,"commands":53,"prompt":63,"zipAvailable":64},[54,57,60],{"tool":55,"command":56},"npx","npx skills add xyliu-cs\u002FOpenSpace-GDPval --skill spreadsheet-create-verify-gate",{"tool":58,"command":59},"bunx","bunx skills add xyliu-cs\u002FOpenSpace-GDPval --skill spreadsheet-create-verify-gate",{"tool":61,"command":62},"pnpm","pnpm dlx skills add xyliu-cs\u002FOpenSpace-GDPval --skill spreadsheet-create-verify-gate","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-proof-gate-merged-fedf41\u002FSKILL.md",true,[66],{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},".skill_id","OTHER","其他",50,"https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fspreadsheet-proof-gate-merged-fedf41\u002F.skill_id",[73,86,94,109,134,154],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":39},"01M6KG8MF1S664SWBDENYRSCK8","zip-export-deliverable","Ensures codebase deliverables are properly exported as ZIP archives through a dedicated finalization step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-export-deliverable\u002FSKILL.md",[],[80,81,82,83,84,85],"zip export deliverable","zip","export","deliverables","codebase","as",{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":39},"01M6KG8GAZWHHEK7VNJDW0ME21","zip-deliverable-finalization","Ensure codebase deliverables are properly packaged as ZIP exports in a dedicated final step","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzip-deliverable-finalization\u002FSKILL.md",[],[93,81,83,84,85],"zip deliverable finalization",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":39},"01M6KG8CMQQ1PYMNTSRZ9VS1MD","zero-iteration-failure-analysis","Identify and handle agent failures with 0 iterations as pre-execution system issues","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fzero-iteration-failure-analysis\u002FSKILL.md",[],[101,102,103,104,105,37,106,107,85,108],"failure analysis","ZeRO","analysis","iteration","zero iteration failure analysis","issues","execution","system",{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":120,"publishedAt":39},"01M6KG86W3PA07FT9W58YHHERM","write-file-fallback-report","Generate professional documents using write_file when primary data sources fail, leveraging embedded domain knowledge instead of external retrieval","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report\u002FSKILL.md",[115],{"categoryNo":116,"categoryName":117,"taxonomyType":118,"taxonomyTypeDesc":119},"01JBSEEDCAT000000000000034","行政与办公人员","PROFESSION","适用职业",[121,32,122,123,124,125,126,127,128,129,130,131,132,133],"fallback","file","report","write file fallback report","domain","professional","sources","retrieval","generate","embedded","documents","data","knowledge",{"skillNo":135,"name":136,"nameZh":6,"description":137,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":138,"categories":139,"keywords":143,"publishedAt":39},"01M6KG82GAEY3GG77CMGCK1C2T","fallback-doc-with-delegation","Generate professional documents after tool failures using shell_agent for complex formats or write_file for simple text\u002Fmarkdown","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced\u002FSKILL.md",[140],{"categoryNo":141,"categoryName":142,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[144,37,121,145,146,147,131,129,122,148,149,150,32,151,126,152,153],"fallback doc with delegation","doc","delegation","shell","markdown","tool","text","simple","formats","for",{"skillNo":155,"name":156,"nameZh":6,"description":157,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":158,"categories":159,"keywords":161,"publishedAt":39},"01M6KG7WT7GX5NYCGEFHW22NV7","context-anchored-fallback-report","Generate documents with write_file when retrieval tools fail, with explicit guardrails against task context drift","https:\u002F\u002Fgithub.com\u002Fxyliu-cs\u002FOpenSpace-GDPval\u002Fblob\u002Fmain\u002Fgdpval_bench\u002Fskills\u002Fwrite-file-fallback-report-enhanced-4bc5c2\u002FSKILL.md",[160],{"categoryNo":116,"categoryName":117,"taxonomyType":118,"taxonomyTypeDesc":119},[121,123,162,163,129,122,164,165,32,166,167,128,37,168,131],"context","context anchored fallback report","Guardrails","Tools","task","drift","context drift"]