@haposoft/cafekit 0.7.15 → 0.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/bin/install.js +2 -1
  2. package/package.json +1 -1
  3. package/src/claude/CLAUDE.md +85 -15
  4. package/src/claude/agents/spec-maker.md +1 -1
  5. package/src/claude/gitignore +17 -0
  6. package/src/claude/hooks/lib/config.cjs +2 -2
  7. package/src/claude/migration-manifest.json +5 -2
  8. package/src/claude/skills/docx/LICENSE.txt +30 -0
  9. package/src/claude/skills/docx/SKILL.md +200 -0
  10. package/src/claude/skills/docx/docx-js.md +350 -0
  11. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  12. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  13. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  14. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  15. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  16. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  17. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  18. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  19. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  20. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  21. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  22. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  23. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  24. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  25. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  26. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  27. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  28. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  29. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  30. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  31. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  32. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  33. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  34. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  35. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  36. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  37. package/src/claude/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  38. package/src/claude/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  39. package/src/claude/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  40. package/src/claude/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  41. package/src/claude/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  42. package/src/claude/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
  43. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  44. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  45. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  46. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  47. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  48. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  49. package/src/claude/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  50. package/src/claude/skills/docx/ooxml/scripts/pack.py +159 -0
  51. package/src/claude/skills/docx/ooxml/scripts/unpack.py +29 -0
  52. package/src/claude/skills/docx/ooxml/scripts/validate.py +69 -0
  53. package/src/claude/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
  54. package/src/claude/skills/docx/ooxml/scripts/validation/base.py +951 -0
  55. package/src/claude/skills/docx/ooxml/scripts/validation/docx.py +274 -0
  56. package/src/claude/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
  57. package/src/claude/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
  58. package/src/claude/skills/docx/ooxml.md +610 -0
  59. package/src/claude/skills/docx/scripts/__init__.py +1 -0
  60. package/src/claude/skills/docx/scripts/document.py +1276 -0
  61. package/src/claude/skills/docx/scripts/templates/comments.xml +3 -0
  62. package/src/claude/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  63. package/src/claude/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  64. package/src/claude/skills/docx/scripts/templates/commentsIds.xml +3 -0
  65. package/src/claude/skills/docx/scripts/templates/people.xml +3 -0
  66. package/src/claude/skills/docx/scripts/utilities.py +374 -0
  67. package/src/claude/skills/pdf/LICENSE.txt +30 -0
  68. package/src/claude/skills/pdf/SKILL.md +297 -0
  69. package/src/claude/skills/pdf/forms.md +205 -0
  70. package/src/claude/skills/pdf/reference.md +612 -0
  71. package/src/claude/skills/pdf/scripts/check_bounding_boxes.py +70 -0
  72. package/src/claude/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
  73. package/src/claude/skills/pdf/scripts/check_fillable_fields.py +12 -0
  74. package/src/claude/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
  75. package/src/claude/skills/pdf/scripts/create_validation_image.py +41 -0
  76. package/src/claude/skills/pdf/scripts/extract_form_field_info.py +152 -0
  77. package/src/claude/skills/pdf/scripts/fill_fillable_fields.py +114 -0
  78. package/src/claude/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
  79. package/src/claude/skills/pptx/LICENSE.txt +30 -0
  80. package/src/claude/skills/pptx/SKILL.md +487 -0
  81. package/src/claude/skills/pptx/html2pptx.md +625 -0
  82. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  83. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  84. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  85. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  86. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  87. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  88. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  89. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  90. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  91. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  92. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  93. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  94. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  95. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  96. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  97. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  98. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  99. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  100. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  101. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  102. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  103. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  104. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  105. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  106. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  107. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  108. package/src/claude/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  109. package/src/claude/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  110. package/src/claude/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  111. package/src/claude/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  112. package/src/claude/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  113. package/src/claude/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
  114. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  115. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  116. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  117. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  118. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  119. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  120. package/src/claude/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  121. package/src/claude/skills/pptx/ooxml/scripts/pack.py +159 -0
  122. package/src/claude/skills/pptx/ooxml/scripts/unpack.py +29 -0
  123. package/src/claude/skills/pptx/ooxml/scripts/validate.py +69 -0
  124. package/src/claude/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
  125. package/src/claude/skills/pptx/ooxml/scripts/validation/base.py +951 -0
  126. package/src/claude/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
  127. package/src/claude/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
  128. package/src/claude/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
  129. package/src/claude/skills/pptx/ooxml.md +427 -0
  130. package/src/claude/skills/pptx/scripts/html2pptx.js +979 -0
  131. package/src/claude/skills/pptx/scripts/inventory.py +1020 -0
  132. package/src/claude/skills/pptx/scripts/rearrange.py +231 -0
  133. package/src/claude/skills/pptx/scripts/replace.py +385 -0
  134. package/src/claude/skills/pptx/scripts/thumbnail.py +450 -0
  135. package/src/claude/skills/specs/SKILL.md +11 -4
  136. package/src/claude/skills/xlsx/LICENSE.txt +30 -0
  137. package/src/claude/skills/xlsx/SKILL.md +292 -0
  138. package/src/claude/skills/xlsx/recalc.py +191 -0
  139. package/src/claude/skills/code/SKILL.md +0 -55
  140. package/src/claude/skills/code/references/execution-loop.md +0 -21
@@ -0,0 +1,292 @@
1
+ ---
2
+ name: hapo:xlsx
3
+ description: Create, edit, analyze spreadsheets (.xlsx, .csv, .tsv). Use for Excel formulas, data analysis, visualization, formatting, pivot tables, charts, formula recalculation.
4
+ license: Proprietary. LICENSE.txt has complete terms
5
+ metadata:
6
+ author: haposoft
7
+ version: "1.0.0"
8
+ ---
9
+
10
+ # Requirements for Outputs
11
+
12
+ ## All Excel files
13
+
14
+ ### Zero Formula Errors
15
+ - Every Excel model MUST be delivered with ZERO formula errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?)
16
+
17
+ ### Preserve Existing Templates (when updating templates)
18
+ - Study and EXACTLY match existing format, style, and conventions when modifying files
19
+ - Never impose standardized formatting on files with established patterns
20
+ - Existing template conventions ALWAYS override these guidelines
21
+
22
+ ## Financial models
23
+
24
+ ### Color Coding Standards
25
+ Unless otherwise stated by the user or existing template
26
+
27
+ #### Industry-Standard Color Conventions
28
+ - **Blue text (RGB: 0,0,255)**: Hardcoded inputs, and numbers users will change for scenarios
29
+ - **Black text (RGB: 0,0,0)**: ALL formulas and calculations
30
+ - **Green text (RGB: 0,128,0)**: Links pulling from other worksheets within same workbook
31
+ - **Red text (RGB: 255,0,0)**: External links to other files
32
+ - **Yellow background (RGB: 255,255,0)**: Key assumptions needing attention or cells that need to be updated
33
+
34
+ ### Number Formatting Standards
35
+
36
+ #### Required Format Rules
37
+ - **Years**: Format as text strings (e.g., "2024" not "2,024")
38
+ - **Currency**: Use $#,##0 format; ALWAYS specify units in headers ("Revenue ($mm)")
39
+ - **Zeros**: Use number formatting to make all zeros "-", including percentages (e.g., "$#,##0;($#,##0);-")
40
+ - **Percentages**: Default to 0.0% format (one decimal)
41
+ - **Multiples**: Format as 0.0x for valuation multiples (EV/EBITDA, P/E)
42
+ - **Negative numbers**: Use parentheses (123) not minus -123
43
+
44
+ ### Formula Construction Rules
45
+
46
+ #### Assumptions Placement
47
+ - Place ALL assumptions (growth rates, margins, multiples, etc.) in separate assumption cells
48
+ - Use cell references instead of hardcoded values in formulas
49
+ - Example: Use =B5*(1+$B$6) instead of =B5*1.05
50
+
51
+ #### Formula Error Prevention
52
+ - Verify all cell references are correct
53
+ - Check for off-by-one errors in ranges
54
+ - Ensure consistent formulas across all projection periods
55
+ - Test with edge cases (zero values, negative numbers)
56
+ - Verify no unintended circular references
57
+
58
+ #### Documentation Requirements for Hardcodes
59
+ - Comment or in cells beside (if end of table). Format: "Source: [System/Document], [Date], [Specific Reference], [URL if applicable]"
60
+ - Examples:
61
+ - "Source: Company 10-K, FY2024, Page 45, Revenue Note, [SEC EDGAR URL]"
62
+ - "Source: Company 10-Q, Q2 2025, Exhibit 99.1, [SEC EDGAR URL]"
63
+ - "Source: Bloomberg Terminal, 8/15/2025, AAPL US Equity"
64
+ - "Source: FactSet, 8/20/2025, Consensus Estimates Screen"
65
+
66
+ # XLSX creation, editing, and analysis
67
+
68
+ ## Overview
69
+
70
+ A user may ask you to create, edit, or analyze the contents of an .xlsx file. You have different tools and workflows available for different tasks.
71
+
72
+ ## Important Requirements
73
+
74
+ **LibreOffice Required for Formula Recalculation**: You can assume LibreOffice is installed for recalculating formula values using the `recalc.py` script. The script automatically configures LibreOffice on first run
75
+
76
+ ## Reading and analyzing data
77
+
78
+ ### Data analysis with pandas
79
+ For data analysis, visualization, and basic operations, use **pandas** which provides powerful data manipulation capabilities:
80
+
81
+ ```python
82
+ import pandas as pd
83
+
84
+ # Read Excel
85
+ df = pd.read_excel('file.xlsx') # Default: first sheet
86
+ all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # All sheets as dict
87
+
88
+ # Analyze
89
+ df.head() # Preview data
90
+ df.info() # Column info
91
+ df.describe() # Statistics
92
+
93
+ # Write Excel
94
+ df.to_excel('output.xlsx', index=False)
95
+ ```
96
+
97
+ ## Excel File Workflows
98
+
99
+ ## CRITICAL: Use Formulas, Not Hardcoded Values
100
+
101
+ **Always use Excel formulas instead of calculating values in Python and hardcoding them.** This ensures the spreadsheet remains dynamic and updateable.
102
+
103
+ ### ❌ WRONG - Hardcoding Calculated Values
104
+ ```python
105
+ # Bad: Calculating in Python and hardcoding result
106
+ total = df['Sales'].sum()
107
+ sheet['B10'] = total # Hardcodes 5000
108
+
109
+ # Bad: Computing growth rate in Python
110
+ growth = (df.iloc[-1]['Revenue'] - df.iloc[0]['Revenue']) / df.iloc[0]['Revenue']
111
+ sheet['C5'] = growth # Hardcodes 0.15
112
+
113
+ # Bad: Python calculation for average
114
+ avg = sum(values) / len(values)
115
+ sheet['D20'] = avg # Hardcodes 42.5
116
+ ```
117
+
118
+ ### ✅ CORRECT - Using Excel Formulas
119
+ ```python
120
+ # Good: Let Excel calculate the sum
121
+ sheet['B10'] = '=SUM(B2:B9)'
122
+
123
+ # Good: Growth rate as Excel formula
124
+ sheet['C5'] = '=(C4-C2)/C2'
125
+
126
+ # Good: Average using Excel function
127
+ sheet['D20'] = '=AVERAGE(D2:D19)'
128
+ ```
129
+
130
+ This applies to ALL calculations - totals, percentages, ratios, differences, etc. The spreadsheet should be able to recalculate when source data changes.
131
+
132
+ ## Common Workflow
133
+ 1. **Choose tool**: pandas for data, openpyxl for formulas/formatting
134
+ 2. **Create/Load**: Create new workbook or load existing file
135
+ 3. **Modify**: Add/edit data, formulas, and formatting
136
+ 4. **Save**: Write to file
137
+ 5. **Recalculate formulas (MANDATORY IF USING FORMULAS)**: Use the recalc.py script
138
+ ```bash
139
+ python recalc.py output.xlsx
140
+ ```
141
+ 6. **Verify and fix any errors**:
142
+ - The script returns JSON with error details
143
+ - If `status` is `errors_found`, check `error_summary` for specific error types and locations
144
+ - Fix the identified errors and recalculate again
145
+ - Common errors to fix:
146
+ - `#REF!`: Invalid cell references
147
+ - `#DIV/0!`: Division by zero
148
+ - `#VALUE!`: Wrong data type in formula
149
+ - `#NAME?`: Unrecognized formula name
150
+
151
+ ### Creating new Excel files
152
+
153
+ ```python
154
+ # Using openpyxl for formulas and formatting
155
+ from openpyxl import Workbook
156
+ from openpyxl.styles import Font, PatternFill, Alignment
157
+
158
+ wb = Workbook()
159
+ sheet = wb.active
160
+
161
+ # Add data
162
+ sheet['A1'] = 'Hello'
163
+ sheet['B1'] = 'World'
164
+ sheet.append(['Row', 'of', 'data'])
165
+
166
+ # Add formula
167
+ sheet['B2'] = '=SUM(A1:A10)'
168
+
169
+ # Formatting
170
+ sheet['A1'].font = Font(bold=True, color='FF0000')
171
+ sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
172
+ sheet['A1'].alignment = Alignment(horizontal='center')
173
+
174
+ # Column width
175
+ sheet.column_dimensions['A'].width = 20
176
+
177
+ wb.save('output.xlsx')
178
+ ```
179
+
180
+ ### Editing existing Excel files
181
+
182
+ ```python
183
+ # Using openpyxl to preserve formulas and formatting
184
+ from openpyxl import load_workbook
185
+
186
+ # Load existing file
187
+ wb = load_workbook('existing.xlsx')
188
+ sheet = wb.active # or wb['SheetName'] for specific sheet
189
+
190
+ # Working with multiple sheets
191
+ for sheet_name in wb.sheetnames:
192
+ sheet = wb[sheet_name]
193
+ print(f"Sheet: {sheet_name}")
194
+
195
+ # Modify cells
196
+ sheet['A1'] = 'New Value'
197
+ sheet.insert_rows(2) # Insert row at position 2
198
+ sheet.delete_cols(3) # Delete column 3
199
+
200
+ # Add new sheet
201
+ new_sheet = wb.create_sheet('NewSheet')
202
+ new_sheet['A1'] = 'Data'
203
+
204
+ wb.save('modified.xlsx')
205
+ ```
206
+
207
+ ## Recalculating formulas
208
+
209
+ Excel files created or modified by openpyxl contain formulas as strings but not calculated values. Use the provided `recalc.py` script to recalculate formulas:
210
+
211
+ ```bash
212
+ python recalc.py <excel_file> [timeout_seconds]
213
+ ```
214
+
215
+ Example:
216
+ ```bash
217
+ python recalc.py output.xlsx 30
218
+ ```
219
+
220
+ The script:
221
+ - Automatically sets up LibreOffice macro on first run
222
+ - Recalculates all formulas in all sheets
223
+ - Scans ALL cells for Excel errors (#REF!, #DIV/0!, etc.)
224
+ - Returns JSON with detailed error locations and counts
225
+ - Works on both Linux and macOS
226
+
227
+ ## Formula Verification Checklist
228
+
229
+ Quick checks to ensure formulas work correctly:
230
+
231
+ ### Essential Verification
232
+ - [ ] **Test 2-3 sample references**: Verify they pull correct values before building full model
233
+ - [ ] **Column mapping**: Confirm Excel columns match (e.g., column 64 = BL, not BK)
234
+ - [ ] **Row offset**: Remember Excel rows are 1-indexed (DataFrame row 5 = Excel row 6)
235
+
236
+ ### Common Pitfalls
237
+ - [ ] **NaN handling**: Check for null values with `pd.notna()`
238
+ - [ ] **Far-right columns**: FY data often in columns 50+
239
+ - [ ] **Multiple matches**: Search all occurrences, not just first
240
+ - [ ] **Division by zero**: Check denominators before using `/` in formulas (#DIV/0!)
241
+ - [ ] **Wrong references**: Verify all cell references point to intended cells (#REF!)
242
+ - [ ] **Cross-sheet references**: Use correct format (Sheet1!A1) for linking sheets
243
+
244
+ ### Formula Testing Strategy
245
+ - [ ] **Start small**: Test formulas on 2-3 cells before applying broadly
246
+ - [ ] **Verify dependencies**: Check all cells referenced in formulas exist
247
+ - [ ] **Test edge cases**: Include zero, negative, and very large values
248
+
249
+ ### Interpreting recalc.py Output
250
+ The script returns JSON with error details:
251
+ ```json
252
+ {
253
+ "status": "success", // or "errors_found"
254
+ "total_errors": 0, // Total error count
255
+ "total_formulas": 42, // Number of formulas in file
256
+ "error_summary": { // Only present if errors found
257
+ "#REF!": {
258
+ "count": 2,
259
+ "locations": ["Sheet1!B5", "Sheet1!C10"]
260
+ }
261
+ }
262
+ }
263
+ ```
264
+
265
+ ## Best Practices
266
+
267
+ ### Library Selection
268
+ - **pandas**: Best for data analysis, bulk operations, and simple data export
269
+ - **openpyxl**: Best for complex formatting, formulas, and Excel-specific features
270
+
271
+ ### Working with openpyxl
272
+ - Cell indices are 1-based (row=1, column=1 refers to cell A1)
273
+ - Use `data_only=True` to read calculated values: `load_workbook('file.xlsx', data_only=True)`
274
+ - **Warning**: If opened with `data_only=True` and saved, formulas are replaced with values and permanently lost
275
+ - For large files: Use `read_only=True` for reading or `write_only=True` for writing
276
+ - Formulas are preserved but not evaluated - use recalc.py to update values
277
+
278
+ ### Working with pandas
279
+ - Specify data types to avoid inference issues: `pd.read_excel('file.xlsx', dtype={'id': str})`
280
+ - For large files, read specific columns: `pd.read_excel('file.xlsx', usecols=['A', 'C', 'E'])`
281
+ - Handle dates properly: `pd.read_excel('file.xlsx', parse_dates=['date_column'])`
282
+
283
+ ## Code Style Guidelines
284
+ **IMPORTANT**: When generating Python code for Excel operations:
285
+ - Write minimal, concise Python code without unnecessary comments
286
+ - Avoid verbose variable names and redundant operations
287
+ - Avoid unnecessary print statements
288
+
289
+ **For Excel files themselves**:
290
+ - Add comments to cells with complex formulas or important assumptions
291
+ - Document data sources for hardcoded values
292
+ - Include notes for key calculations and model sections
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Excel Formula Recalculation Script
4
+ Recalculates all formulas in an Excel file using LibreOffice
5
+ """
6
+
7
+ import json
8
+ import sys
9
+ import subprocess
10
+ import os
11
+ import platform
12
+ from pathlib import Path
13
+
14
+ # Windows UTF-8 compatibility (works for both local and global installs)
15
+ CLAUDE_ROOT = Path(__file__).parent.parent.parent.parent
16
+ sys.path.insert(0, str(CLAUDE_ROOT / 'scripts'))
17
+ try:
18
+ from win_compat import ensure_utf8_stdout
19
+ ensure_utf8_stdout()
20
+ except ImportError:
21
+ if sys.platform == 'win32':
22
+ import io
23
+ if hasattr(sys.stdout, 'buffer'):
24
+ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
25
+
26
+ from openpyxl import load_workbook
27
+
28
+
29
+ def setup_libreoffice_macro():
30
+ """Setup LibreOffice macro for recalculation if not already configured"""
31
+ if platform.system() == 'Darwin':
32
+ macro_dir = os.path.expanduser('~/Library/Application Support/LibreOffice/4/user/basic/Standard')
33
+ else:
34
+ macro_dir = os.path.expanduser('~/.config/libreoffice/4/user/basic/Standard')
35
+
36
+ macro_file = os.path.join(macro_dir, 'Module1.xba')
37
+
38
+ if os.path.exists(macro_file):
39
+ with open(macro_file, 'r') as f:
40
+ if 'RecalculateAndSave' in f.read():
41
+ return True
42
+
43
+ if not os.path.exists(macro_dir):
44
+ subprocess.run(['soffice', '--headless', '--terminate_after_init'],
45
+ capture_output=True, timeout=10)
46
+ os.makedirs(macro_dir, exist_ok=True)
47
+
48
+ macro_content = '''<?xml version="1.0" encoding="UTF-8"?>
49
+ <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
50
+ <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">
51
+ Sub RecalculateAndSave()
52
+ ThisComponent.calculateAll()
53
+ ThisComponent.store()
54
+ ThisComponent.close(True)
55
+ End Sub
56
+ </script:module>'''
57
+
58
+ try:
59
+ with open(macro_file, 'w') as f:
60
+ f.write(macro_content)
61
+ return True
62
+ except Exception:
63
+ return False
64
+
65
+
66
+ def recalc(filename, timeout=30):
67
+ """
68
+ Recalculate formulas in Excel file and report any errors
69
+
70
+ Args:
71
+ filename: Path to Excel file
72
+ timeout: Maximum time to wait for recalculation (seconds)
73
+
74
+ Returns:
75
+ dict with error locations and counts
76
+ """
77
+ if not Path(filename).exists():
78
+ return {'error': f'File {filename} does not exist'}
79
+
80
+ abs_path = str(Path(filename).absolute())
81
+
82
+ if not setup_libreoffice_macro():
83
+ return {'error': 'Failed to setup LibreOffice macro'}
84
+
85
+ cmd = [
86
+ 'soffice', '--headless', '--norestore',
87
+ 'vnd.sun.star.script:Standard.Module1.RecalculateAndSave?language=Basic&location=application',
88
+ abs_path
89
+ ]
90
+
91
+ # Handle timeout command differences between Linux and macOS
92
+ if platform.system() != 'Windows':
93
+ timeout_cmd = 'timeout' if platform.system() == 'Linux' else None
94
+ if platform.system() == 'Darwin':
95
+ # Check if gtimeout is available on macOS
96
+ try:
97
+ subprocess.run(['gtimeout', '--version'], capture_output=True, timeout=1, check=False)
98
+ timeout_cmd = 'gtimeout'
99
+ except (FileNotFoundError, subprocess.TimeoutExpired):
100
+ pass
101
+
102
+ if timeout_cmd:
103
+ cmd = [timeout_cmd, str(timeout)] + cmd
104
+
105
+ result = subprocess.run(cmd, capture_output=True, text=True)
106
+
107
+ if result.returncode != 0 and result.returncode != 124: # 124 is timeout exit code
108
+ error_msg = result.stderr or 'Unknown error during recalculation'
109
+ if 'Module1' in error_msg or 'RecalculateAndSave' not in error_msg:
110
+ return {'error': 'LibreOffice macro not configured properly'}
111
+ else:
112
+ return {'error': error_msg}
113
+
114
+ # Check for Excel errors in the recalculated file - scan ALL cells
115
+ try:
116
+ wb = load_workbook(filename, data_only=True)
117
+
118
+ excel_errors = ['#VALUE!', '#DIV/0!', '#REF!', '#NAME?', '#NULL!', '#NUM!', '#N/A']
119
+ error_details = {err: [] for err in excel_errors}
120
+ total_errors = 0
121
+
122
+ for sheet_name in wb.sheetnames:
123
+ ws = wb[sheet_name]
124
+ # Check ALL rows and columns - no limits
125
+ for row in ws.iter_rows():
126
+ for cell in row:
127
+ if cell.value is not None and isinstance(cell.value, str):
128
+ for err in excel_errors:
129
+ if err in cell.value:
130
+ location = f"{sheet_name}!{cell.coordinate}"
131
+ error_details[err].append(location)
132
+ total_errors += 1
133
+ break
134
+
135
+ wb.close()
136
+
137
+ # Build result summary
138
+ result = {
139
+ 'status': 'success' if total_errors == 0 else 'errors_found',
140
+ 'total_errors': total_errors,
141
+ 'error_summary': {}
142
+ }
143
+
144
+ # Add non-empty error categories
145
+ for err_type, locations in error_details.items():
146
+ if locations:
147
+ result['error_summary'][err_type] = {
148
+ 'count': len(locations),
149
+ 'locations': locations[:20] # Show up to 20 locations
150
+ }
151
+
152
+ # Add formula count for context - also check ALL cells
153
+ wb_formulas = load_workbook(filename, data_only=False)
154
+ formula_count = 0
155
+ for sheet_name in wb_formulas.sheetnames:
156
+ ws = wb_formulas[sheet_name]
157
+ for row in ws.iter_rows():
158
+ for cell in row:
159
+ if cell.value and isinstance(cell.value, str) and cell.value.startswith('='):
160
+ formula_count += 1
161
+ wb_formulas.close()
162
+
163
+ result['total_formulas'] = formula_count
164
+
165
+ return result
166
+
167
+ except Exception as e:
168
+ return {'error': str(e)}
169
+
170
+
171
+ def main():
172
+ if len(sys.argv) < 2:
173
+ print("Usage: python recalc.py <excel_file> [timeout_seconds]")
174
+ print("\nRecalculates all formulas in an Excel file using LibreOffice")
175
+ print("\nReturns JSON with error details:")
176
+ print(" - status: 'success' or 'errors_found'")
177
+ print(" - total_errors: Total number of Excel errors found")
178
+ print(" - total_formulas: Number of formulas in the file")
179
+ print(" - error_summary: Breakdown by error type with locations")
180
+ print(" - #VALUE!, #DIV/0!, #REF!, #NAME?, #NULL!, #NUM!, #N/A")
181
+ sys.exit(1)
182
+
183
+ filename = sys.argv[1]
184
+ timeout = int(sys.argv[2]) if len(sys.argv) > 2 else 30
185
+
186
+ result = recalc(filename, timeout)
187
+ print(json.dumps(result, indent=2))
188
+
189
+
190
+ if __name__ == '__main__':
191
+ main()
@@ -1,55 +0,0 @@
1
- ---
2
- name: hapo:code
3
- description: Implement the next approved spec task and then hand off to hapo:test and hapo:review.
4
- version: 1.0.0
5
- argument-hint: <feature-name>
6
- ---
7
-
8
- # Code
9
-
10
- Implement the next pending task from an approved spec instead of coding from memory.
11
-
12
- ## Usage
13
-
14
- ```bash
15
- /hapo:code <feature-name>
16
- ```
17
-
18
- ## Load First
19
-
20
- - `references/execution-loop.md`
21
- - `.specs/$ARGUMENTS/tasks.md`
22
- - `.specs/$ARGUMENTS/design.md`
23
- - `.specs/$ARGUMENTS/requirements.md`
24
-
25
- ## Execute
26
-
27
- 1. Read `.specs/$ARGUMENTS/tasks.md` and identify the next pending task.
28
- 2. Read the related context from `design.md` and `requirements.md`.
29
- 3. Implement only that task. Keep scope tight.
30
- 4. Follow the project standards already present in the repo.
31
- 5. Update task status in the spec artifact if the workflow supports it.
32
- 6. Hand off immediately to:
33
- - `/hapo:test`
34
- - `/hapo:review`
35
-
36
- ## Output
37
-
38
- Return:
39
- - implemented task name
40
- - touched files
41
- - blockers or follow-up items
42
- - explicit handoff to `/hapo:test` and `/hapo:review`
43
-
44
- ## Rules
45
-
46
- - Do not implement multiple major tasks in one pass.
47
- - Stop if `tasks.md` is missing.
48
- - Prefer existing patterns over new abstractions.
49
- - Keep the work aligned to the spec.
50
-
51
- ## Related
52
-
53
- - Command: `/code`
54
- - Previous skill: `/hapo:spec-tasks`
55
- - Next skills: `/hapo:test`, `/hapo:review`
@@ -1,21 +0,0 @@
1
- # Execution Loop
2
-
3
- ## Goal
4
-
5
- Implement one approved task at a time and immediately validate it.
6
-
7
- ## Loop
8
-
9
- 1. Read the next pending task in `tasks.md`.
10
- 2. Read the matching context in `design.md` and `requirements.md`.
11
- 3. Implement only that task.
12
- 4. Run `/hapo:test`.
13
- 5. Run `/hapo:review`.
14
- 6. Move to the next task only after the current pass is clear.
15
-
16
- ## Guardrails
17
-
18
- - Keep scope tight.
19
- - Prefer existing project patterns.
20
- - Do not batch multiple major tasks into one pass.
21
- - Stop and report blockers instead of guessing.