@nomad-e/bluma-cli 0.26.3 → 2026.27.0-darwin-arm64

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 (117) hide show
  1. package/LICENSE +189 -70
  2. package/README.md +2 -162
  3. package/THIRD-PARTY-NOTICES.txt +46201 -0
  4. package/bin/bluma-core +0 -0
  5. package/package.json +24 -124
  6. package/third-party/option-ext/.cargo_vcs_info.json +6 -0
  7. package/third-party/option-ext/Cargo.toml +22 -0
  8. package/third-party/option-ext/LICENSE.txt +373 -0
  9. package/third-party/option-ext/README.md +67 -0
  10. package/third-party/option-ext/src/impl.rs +20 -0
  11. package/third-party/option-ext/src/lib.rs +71 -0
  12. package/assets/bg.png +0 -0
  13. package/assets/bg1.png +0 -0
  14. package/assets/bluma.png +0 -0
  15. package/assets/image.png +0 -0
  16. package/dist/assets/bg.png +0 -0
  17. package/dist/assets/bg1.png +0 -0
  18. package/dist/assets/bluma.png +0 -0
  19. package/dist/assets/image.png +0 -0
  20. package/dist/config/native_tools.json +0 -1151
  21. package/dist/config/plan_mode_instructions.md +0 -218
  22. package/dist/config/skills/factorai-sh/SKILL.md +0 -98
  23. package/dist/config/skills/git-commit/LICENSE.txt +0 -18
  24. package/dist/config/skills/git-commit/SKILL.md +0 -300
  25. package/dist/config/skills/git-commit/references/REFERENCE.md +0 -253
  26. package/dist/config/skills/git-commit/scripts/validate_commit_msg.py +0 -163
  27. package/dist/config/skills/git-pr/LICENSE.txt +0 -18
  28. package/dist/config/skills/git-pr/SKILL.md +0 -293
  29. package/dist/config/skills/git-pr/references/REFERENCE.md +0 -256
  30. package/dist/config/skills/git-pr/scripts/validate_commits.py +0 -120
  31. package/dist/config/skills/git-release/LICENSE.txt +0 -18
  32. package/dist/config/skills/git-release/SKILL.md +0 -408
  33. package/dist/config/skills/pdf/LICENSE.txt +0 -26
  34. package/dist/config/skills/pdf/SKILL.md +0 -736
  35. package/dist/config/skills/pdf/references/DOCUMENT_TYPES.md +0 -59
  36. package/dist/config/skills/pdf/references/FORMS.md +0 -69
  37. package/dist/config/skills/pdf/references/REFERENCE.md +0 -52
  38. package/dist/config/skills/pdf/scripts/__pycache__/create_report.cpython-312.pyc +0 -0
  39. package/dist/config/skills/pdf/scripts/create_report.py +0 -936
  40. package/dist/config/skills/pdf/scripts/merge_pdfs.py +0 -48
  41. package/dist/config/skills/skill-creator/LICENSE.txt +0 -26
  42. package/dist/config/skills/skill-creator/SKILL.md +0 -229
  43. package/dist/config/skills/xlsx/LICENSE.txt +0 -18
  44. package/dist/config/skills/xlsx/SKILL.md +0 -340
  45. package/dist/config/skills/xlsx/references/REFERENCE.md +0 -337
  46. package/dist/config/skills/xlsx/scripts/office/__init__.py +0 -2
  47. package/dist/config/skills/xlsx/scripts/office/pack.py +0 -58
  48. package/dist/config/skills/xlsx/scripts/office/soffice.py +0 -180
  49. package/dist/config/skills/xlsx/scripts/office/unpack.py +0 -63
  50. package/dist/config/skills/xlsx/scripts/office/validate.py +0 -122
  51. package/dist/config/skills/xlsx/scripts/recalc.py +0 -152
  52. package/dist/main.js +0 -47932
  53. package/dist/native/bluma-clipboard.linux-x64-gnu.node +0 -0
  54. package/dist/native/index.d.ts +0 -38
  55. package/dist/native/index.js +0 -319
  56. package/dist/native/package.json +0 -38
  57. package/dist/scaffold/.eslintrc.json +0 -3
  58. package/dist/scaffold/app/globals.css +0 -46
  59. package/dist/scaffold/app/layout.tsx +0 -19
  60. package/dist/scaffold/app/page.tsx +0 -124
  61. package/dist/scaffold/components/ui/README.md +0 -12
  62. package/dist/scaffold/components/ui/accordion.jsx +0 -42
  63. package/dist/scaffold/components/ui/alert-dialog.jsx +0 -80
  64. package/dist/scaffold/components/ui/alert.jsx +0 -33
  65. package/dist/scaffold/components/ui/aspect-ratio.jsx +0 -5
  66. package/dist/scaffold/components/ui/avatar.jsx +0 -28
  67. package/dist/scaffold/components/ui/badge.jsx +0 -24
  68. package/dist/scaffold/components/ui/breadcrumb.jsx +0 -72
  69. package/dist/scaffold/components/ui/button.jsx +0 -40
  70. package/dist/scaffold/components/ui/calendar.jsx +0 -56
  71. package/dist/scaffold/components/ui/card.jsx +0 -38
  72. package/dist/scaffold/components/ui/carousel.jsx +0 -168
  73. package/dist/scaffold/components/ui/chart.jsx +0 -76
  74. package/dist/scaffold/components/ui/checkbox.jsx +0 -22
  75. package/dist/scaffold/components/ui/collapsible.jsx +0 -7
  76. package/dist/scaffold/components/ui/command.jsx +0 -100
  77. package/dist/scaffold/components/ui/context-menu.jsx +0 -137
  78. package/dist/scaffold/components/ui/dialog.jsx +0 -72
  79. package/dist/scaffold/components/ui/drawer.jsx +0 -68
  80. package/dist/scaffold/components/ui/dropdown-menu.jsx +0 -143
  81. package/dist/scaffold/components/ui/form.jsx +0 -88
  82. package/dist/scaffold/components/ui/hover-card.jsx +0 -22
  83. package/dist/scaffold/components/ui/input-otp.jsx +0 -49
  84. package/dist/scaffold/components/ui/input.jsx +0 -19
  85. package/dist/scaffold/components/ui/label.jsx +0 -15
  86. package/dist/scaffold/components/ui/menubar.jsx +0 -161
  87. package/dist/scaffold/components/ui/navigation-menu.jsx +0 -95
  88. package/dist/scaffold/components/ui/pagination.jsx +0 -77
  89. package/dist/scaffold/components/ui/popover.jsx +0 -25
  90. package/dist/scaffold/components/ui/progress.jsx +0 -19
  91. package/dist/scaffold/components/ui/radio-group.jsx +0 -29
  92. package/dist/scaffold/components/ui/resizable.jsx +0 -27
  93. package/dist/scaffold/components/ui/scroll-area.jsx +0 -31
  94. package/dist/scaffold/components/ui/select.jsx +0 -117
  95. package/dist/scaffold/components/ui/separator.jsx +0 -22
  96. package/dist/scaffold/components/ui/sheet.jsx +0 -81
  97. package/dist/scaffold/components/ui/skeleton.jsx +0 -7
  98. package/dist/scaffold/components/ui/slider.jsx +0 -19
  99. package/dist/scaffold/components/ui/sonner.jsx +0 -22
  100. package/dist/scaffold/components/ui/switch.jsx +0 -23
  101. package/dist/scaffold/components/ui/table.jsx +0 -61
  102. package/dist/scaffold/components/ui/tabs.jsx +0 -43
  103. package/dist/scaffold/components/ui/textarea.jsx +0 -18
  104. package/dist/scaffold/components/ui/toast.jsx +0 -85
  105. package/dist/scaffold/components/ui/toaster.jsx +0 -33
  106. package/dist/scaffold/components/ui/toggle-group.jsx +0 -41
  107. package/dist/scaffold/components/ui/toggle.jsx +0 -30
  108. package/dist/scaffold/components/ui/tooltip.jsx +0 -22
  109. package/dist/scaffold/hooks/use-toast.ts +0 -101
  110. package/dist/scaffold/lib/utils.ts +0 -6
  111. package/dist/scaffold/next.config.js +0 -5
  112. package/dist/scaffold/next.config.mjs +0 -15
  113. package/dist/scaffold/next.config.ts +0 -19
  114. package/dist/scaffold/package.json +0 -70
  115. package/dist/scaffold/postcss.config.js +0 -6
  116. package/dist/scaffold/tailwind.config.ts +0 -57
  117. package/dist/scaffold/tsconfig.json +0 -20
@@ -1,48 +0,0 @@
1
- """
2
- Merge multiple PDF files into a single output PDF.
3
-
4
- Usage:
5
- python merge_pdfs.py --output merged.pdf file1.pdf file2.pdf file3.pdf
6
- python merge_pdfs.py --output ./.bluma/artifacts/combined.pdf *.pdf
7
- """
8
- import argparse
9
- import sys
10
-
11
- MIN_PYTHON = (3, 10)
12
- if sys.version_info < MIN_PYTHON:
13
- print(
14
- f"Error: Python {'.'.join(map(str, MIN_PYTHON))}+ is required "
15
- f"(found {'.'.join(map(str, sys.version_info[:3]))})",
16
- file=sys.stderr,
17
- )
18
- sys.exit(1)
19
-
20
- def merge_pdfs(input_files: list[str], output_path: str) -> None:
21
- try:
22
- from pypdf import PdfWriter, PdfReader
23
- except ImportError:
24
- print("Error: pypdf is required. Install with: pip install pypdf", file=sys.stderr)
25
- sys.exit(1)
26
-
27
- writer = PdfWriter()
28
- for pdf_file in input_files:
29
- try:
30
- reader = PdfReader(pdf_file)
31
- for page in reader.pages:
32
- writer.add_page(page)
33
- print(f"Added: {pdf_file} ({len(reader.pages)} pages)")
34
- except Exception as e:
35
- print(f"Error reading {pdf_file}: {e}", file=sys.stderr)
36
- sys.exit(1)
37
-
38
- with open(output_path, "wb") as f:
39
- writer.write(f)
40
-
41
- print(f"Merged {len(input_files)} files -> {output_path}")
42
-
43
- if __name__ == "__main__":
44
- parser = argparse.ArgumentParser(description="Merge PDF files")
45
- parser.add_argument("files", nargs="+", help="PDF files to merge")
46
- parser.add_argument("--output", "-o", required=True, help="Output file path")
47
- args = parser.parse_args()
48
- merge_pdfs(args.files, args.output)
@@ -1,26 +0,0 @@
1
- © 2026 NomadEngenuity LDA. All rights reserved.
2
-
3
- LICENSE: Use of these materials (including all code, prompts, assets, files,
4
- and other components of this Skill) is governed by your agreement with
5
- NomadEngenuity LDA regarding use of NomadEngenuity LDA's services. If no
6
- separate agreement exists, use is governed by NomadEngenuity LDA's applicable
7
- Terms of Service.
8
-
9
- ADDITIONAL RESTRICTIONS: Notwithstanding anything in the Agreement to the
10
- contrary, users may not:
11
-
12
- - Extract these materials from the Services or retain copies of these
13
- materials outside the Services
14
- - Reproduce or copy these materials, except for temporary copies created
15
- automatically during authorized use of the Services
16
- - Create derivative works based on these materials
17
- - Distribute, sublicense, or transfer these materials to any third party
18
- - Make, offer to sell, sell, or import any inventions embodied in these
19
- materials
20
- - Reverse engineer, decompile, or disassemble these materials
21
-
22
- The receipt, viewing, or possession of these materials does not convey or
23
- imply any license or right beyond those expressly granted above.
24
-
25
- NomadEngenuity LDA retains all right, title, and interest in these materials,
26
- including all copyrights, patents, and other intellectual property rights.
@@ -1,229 +0,0 @@
1
- ---
2
- name: skill-creator
3
- description: >
4
- Use this skill when the user wants to create, write, build, or author a new
5
- BluMa skill. Triggers include: "create a skill", "make a new skill",
6
- "build a skill for X", "I need a skill that does Y", "skill template",
7
- or any request to package knowledge/workflows as a reusable skill module.
8
- license: Proprietary. LICENSE.txt has complete terms
9
- ---
10
-
11
- # Instructions
12
-
13
- ## Context
14
- You are a Skill Builder. You create new BluMa skills with the full Progressive Disclosure structure. Every skill you create MUST follow the standard layout.
15
-
16
- ## Standard Skill Layout
17
-
18
- Every skill is a directory with this structure:
19
-
20
- ```
21
- skill-name/
22
- SKILL.md # Core instructions (Level 2)
23
- LICENSE.txt # License terms
24
- references/ # Additional docs loaded on-demand (Level 3a)
25
- REFERENCE.md # Advanced guide (if applicable)
26
- scripts/ # Ready-made scripts (Level 3b)
27
- (domain-relevant scripts)
28
- ```
29
-
30
- The 3 levels of Progressive Disclosure:
31
- - **Level 1**: `description` in frontmatter — always visible in the skills list, acts as a trigger
32
- - **Level 2**: Body of SKILL.md — loaded when the skill is activated via `load_skill`
33
- - **Level 3**: `references/` and `scripts/` — accessed only when the task requires them
34
-
35
- ## Procedure
36
-
37
- ### Step 1: Ask Location (REQUIRED)
38
-
39
- Before anything else, ask the user where to create the skill:
40
-
41
- ```
42
- message({
43
- content: "Where should I create this skill?\n\n**1. Project** (`.bluma/skills/`) - Only available in THIS project\n**2. Global** (`~/.bluma/skills/`) - Available in ALL projects\n\nChoose 1 or 2:",
44
- message_type: "result"
45
- })
46
- ```
47
-
48
- Wait for user response before continuing.
49
-
50
- ### Step 2: Analyze User Input
51
-
52
- Extract from user's content:
53
- - Purpose/domain
54
- - Responsibilities and workflows
55
- - Rules/constraints
56
- - Error scenarios
57
- - Whether the content is short (<100 lines) or extensive (>100 lines)
58
-
59
- ### Step 3: Generate Skill Name
60
-
61
- Create kebab-case name from domain:
62
- - "git workflow" -> `git-workflow`
63
- - "api testing" -> `api-testing`
64
- - "pdf processing" -> `pdf`
65
-
66
- ### Step 4: Determine Path
67
-
68
- Based on user's choice in Step 1:
69
- - **Project (1)**: `.bluma/skills/{name}/`
70
- - **Global (2)**: `~/.bluma/skills/{name}/`
71
-
72
- ### Step 5: Check Directory
73
-
74
- ```
75
- ls_tool({ path: "{chosen-path}/{name}" })
76
- ```
77
-
78
- Verify directory doesn't exist (or confirm overwrite with user).
79
-
80
- ### Step 6: Plan Content Split
81
-
82
- Decide what goes where based on content size:
83
-
84
- **If content is SHORT (<100 lines):**
85
- - Everything goes in SKILL.md body
86
- - references/ gets a minimal REFERENCE.md placeholder
87
- - scripts/ stays empty (or gets a single utility script if applicable)
88
-
89
- **If content is EXTENSIVE (>100 lines):**
90
- - SKILL.md body gets: overview, quick start, core procedure (the essentials)
91
- - references/ gets: advanced docs, detailed API guides, specialized topics
92
- - scripts/ gets: reusable scripts the agent can execute
93
-
94
- ### Step 7: Create the Skill Structure
95
-
96
- Create the following files in order:
97
-
98
- **7a. Create SKILL.md**
99
-
100
- Use `edit_tool` with this template:
101
-
102
- ```markdown
103
- ---
104
- name: {kebab-case-name}
105
- description: >
106
- Use this skill for any task involving {domain}. Triggers include: {list
107
- of trigger phrases and keywords that should activate this skill}. Use
108
- this skill whenever the user mentions {key terms} or any {domain}-related
109
- task.
110
- license: Proprietary. LICENSE.txt has complete terms
111
- ---
112
-
113
- # {Domain} Guide
114
-
115
- ## Overview
116
-
117
- {Brief description of what this skill covers and when to use it.}
118
- {If extensive content exists in references/, mention it here:}
119
- {For advanced features, see references/REFERENCE.md.}
120
-
121
- ## Quick Start
122
-
123
- {Minimal example to get started — 5-10 lines max.}
124
-
125
- ## Procedure
126
-
127
- ### Step 1: {First Action}
128
- {Instructions}
129
-
130
- ### Step 2: {Second Action}
131
- {Instructions}
132
-
133
- ## Error Reference
134
-
135
- | Error | Cause | Fix |
136
- |-------|-------|-----|
137
- | {error} | {cause} | {fix} |
138
-
139
- ## Available References
140
-
141
- {List each reference file with when to use it:}
142
- - REFERENCE.md: For advanced features and detailed API docs
143
- {Add more as needed}
144
-
145
- ## Available Scripts
146
-
147
- {List each script with what it does:}
148
- - {script_name.py}: {one-line description}
149
- {Or "No scripts available for this skill." if none}
150
-
151
- ## Next Steps
152
-
153
- {Point to references/ for advanced topics.}
154
- {Point to scripts/ for automation.}
155
- ```
156
-
157
- **7b. Create LICENSE.txt**
158
-
159
- ```
160
- edit_tool({
161
- file_path: "{path}/{name}/LICENSE.txt",
162
- old_string: "",
163
- new_string: "© 2026 NomadEngenuity LDA. All rights reserved.\n\nLICENSE: Use of these materials..."
164
- })
165
- ```
166
-
167
- Use the standard NomadEngenuity proprietary license (same as other native skills).
168
-
169
- **7c. Create references/REFERENCE.md**
170
-
171
- If extensive content exists, put advanced documentation here.
172
- If content is short, create a placeholder:
173
-
174
- ```markdown
175
- # {Domain} — Advanced Reference
176
-
177
- {Advanced documentation, detailed examples, specialized topics.}
178
- {This file is loaded on-demand when the task requires deeper knowledge.}
179
- ```
180
-
181
- **7d. Create scripts/ (if applicable)**
182
-
183
- If the domain benefits from ready-made scripts, create them.
184
- Each script should:
185
- - Be self-contained and executable with `python script.py [args]`
186
- - Include a docstring explaining what it does
187
- - Accept arguments via argparse or sys.argv
188
- - Print results to stdout or write to a specified output path
189
-
190
- Example script header:
191
- ```python
192
- """
193
- {description of what this script does}
194
-
195
- Usage:
196
- python {script_name}.py --input data.csv --output ./.bluma/artifacts/result.pdf
197
- """
198
- import argparse
199
- ```
200
-
201
- ### Step 8: Report Result
202
-
203
- ```
204
- message({
205
- content: "Skill **{name}** created at `{path}/{name}/`\n\nStructure:\n- SKILL.md (core instructions)\n- LICENSE.txt\n- references/REFERENCE.md\n- scripts/ {list or empty}\n\nLocation: {Project|Global}\nThe skill is now available and will appear in the skills list.",
206
- message_type: "result"
207
- })
208
- ```
209
-
210
- ## Location Reference
211
-
212
- | Location | Path | Scope | Use When |
213
- |----------|------|-------|----------|
214
- | Project | `.bluma/skills/` | This project only | Skill is specific to this codebase |
215
- | Global | `~/.bluma/skills/` | All projects | Skill is generic and reusable |
216
-
217
- ## Guidelines
218
-
219
- - ALWAYS ask location first with `message_type: "result"`
220
- - ALWAYS create the full structure: SKILL.md + LICENSE.txt + references/ + scripts/
221
- - The `description` field is CRITICAL — it is the only text always visible and determines when the skill is activated. Include trigger words and phrases.
222
- - SKILL.md body should contain only the essentials (quick start + procedure). Advanced docs go in references/.
223
- - Scripts should be self-contained, executable, and well-documented.
224
- - Use lists not tables where possible (saves tokens)
225
- - No emojis in skill content
226
- - English only for skill content (translate user input if needed)
227
- - Professional, specific language
228
- - Extract ALL information from user input
229
- - NEVER create a skill with the same name as a native BluMa skill (check available_skills list first)
@@ -1,18 +0,0 @@
1
- BluMa — Base Language Unit · Model Agent
2
- Proprietary License
3
-
4
- Copyright (c) 2024-2026 BluMa Contributors
5
-
6
- This skill is part of the BluMa CLI distribution.
7
- It is provided as a bundled native skill and may not be
8
- redistributed, modified, or used outside of the BluMa agent
9
- framework without prior written permission.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
13
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
16
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
18
- OTHER DEALINGS IN THE SOFTWARE.
@@ -1,340 +0,0 @@
1
- ---
2
- name: xlsx
3
- description: >
4
- Use this skill any time a spreadsheet file is the primary input or output.
5
- Triggers: open, read, edit, create, fix, or convert .xlsx, .xlsm, .csv,
6
- or .tsv files — including adding columns, computing formulas, formatting,
7
- charting, cleaning messy data, restructuring tabular data, or building
8
- financial models. Prefer normal Excel formulas in cells (visible in the
9
- formula bar, human-auditable), not hidden logic or pasted numeric results.
10
- Also trigger when the user references a spreadsheet by name or path and
11
- wants something done to it. The deliverable must be a spreadsheet file.
12
- Do NOT trigger when the primary deliverable is a Word document, HTML
13
- report, or standalone script.
14
- license: Proprietary. LICENSE.txt has complete terms
15
- ---
16
-
17
- # XLSX — Spreadsheet Creation, Editing & Analysis
18
-
19
- ## Prerequisites
20
-
21
- - **Python 3.10+** installed and available in PATH
22
- - Install dependencies: `pip install openpyxl pandas`
23
- - **LibreOffice** installed (required by `recalc.py` for formula recalculation)
24
- - If any script fails with `command not found` or `ModuleNotFoundError`, Python or its
25
- packages are missing — install them before proceeding
26
-
27
- ## Core Principle
28
-
29
- > **Formulas, not hardcodes.** Every calculated value MUST be an Excel
30
- > formula so the spreadsheet stays dynamic. Never compute in Python and
31
- > paste the result into a cell.
32
-
33
- ### Human-readable formulas — everything visible in Excel
34
-
35
- The workbook must behave like one a **human analyst** would open and audit:
36
-
37
- - **Visible in the formula bar:** Any cell that depends on other cells MUST
38
- store a real Excel formula (string starting with `=`). When the user
39
- selects the cell, they see the formula — not a magic number that was
40
- computed offline.
41
- - **No “black box” outputs:** Do not replace formulas with static values
42
- except for true inputs (assumptions, imported facts). Intermediate and
43
- final calculated columns = formulas referencing cells/sheets.
44
- - **Readable structure:** Prefer clear, conventional functions (`SUM`,
45
- `AVERAGE`, `IF`, `SUMIF`, `XLOOKUP`/`VLOOKUP`, etc.) and broken-out
46
- helper columns over one impenetrable mega-formula, when that makes the
47
- model easier to follow — same as a careful human would build.
48
- - **Auditable trail:** Another person should trace “this total → those
49
- lines → those inputs” using only Excel (Show Formulas / following
50
- references), without reading Python.
51
- - **openpyxl:** Assign formulas as strings, e.g. `ws['D2'] = '=B2*C2'`, so
52
- they remain formulas in the saved file. Never save a workbook opened with
53
- `data_only=True` if you need formulas preserved (see Reading section).
54
-
55
- ## Output Quality Standards
56
-
57
- ### Professional Appearance
58
- - Consistent font throughout (Arial or Calibri, 10-11pt)
59
- - Headers bold with subtle background fill
60
- - Column widths auto-fitted to content
61
- - Number formatting applied to all numeric cells
62
- - Borders and alignment used consistently
63
-
64
- ### Zero Formula Errors
65
- Every deliverable MUST have ZERO formula errors. After writing formulas,
66
- always run `scripts/recalc.py` and fix any errors before delivering.
67
-
68
- ### Preserve Existing Templates
69
- When modifying an existing file, study and EXACTLY match its format,
70
- style, and conventions. Existing patterns override these guidelines.
71
-
72
- ## Reading & Analyzing Data
73
-
74
- ### Quick Analysis with pandas
75
-
76
- ```python
77
- import pandas as pd
78
-
79
- df = pd.read_excel('file.xlsx')
80
- all_sheets = pd.read_excel('file.xlsx', sheet_name=None)
81
-
82
- df.head()
83
- df.info()
84
- df.describe()
85
-
86
- df.to_excel('output.xlsx', index=False)
87
- ```
88
-
89
- ### Reading with openpyxl (preserves formulas)
90
-
91
- ```python
92
- from openpyxl import load_workbook
93
-
94
- wb = load_workbook('file.xlsx')
95
- ws = wb.active
96
-
97
- for row in ws.iter_rows(min_row=1, max_row=5, values_only=True):
98
- print(row)
99
-
100
- wb_data = load_workbook('file.xlsx', data_only=True)
101
- ```
102
-
103
- **Warning**: Never open with `data_only=True` and save — formulas are
104
- permanently replaced with cached values.
105
-
106
- ## Creating New Excel Files
107
-
108
- ```python
109
- from openpyxl import Workbook
110
- from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
111
- from openpyxl.utils import get_column_letter
112
-
113
- wb = Workbook()
114
- ws = wb.active
115
- ws.title = "Data"
116
-
117
- header_font = Font(bold=True, size=11, name='Arial')
118
- header_fill = PatternFill('solid', fgColor='D9E1F2')
119
- header_align = Alignment(horizontal='center', vertical='center')
120
-
121
- headers = ['Item', 'Qty', 'Unit Price', 'Total']
122
- for col, h in enumerate(headers, 1):
123
- cell = ws.cell(row=1, column=col, value=h)
124
- cell.font = header_font
125
- cell.fill = header_fill
126
- cell.alignment = header_align
127
-
128
- ws['D2'] = '=B2*C2'
129
-
130
- for col in range(1, len(headers) + 1):
131
- ws.column_dimensions[get_column_letter(col)].width = 15
132
-
133
- wb.save('output.xlsx')
134
- ```
135
-
136
- ## Editing Existing Files
137
-
138
- ```python
139
- from openpyxl import load_workbook
140
-
141
- wb = load_workbook('existing.xlsx')
142
- ws = wb['SheetName']
143
-
144
- ws['A1'] = 'New Value'
145
- ws.insert_rows(2)
146
- ws.delete_cols(3)
147
-
148
- new_ws = wb.create_sheet('Summary')
149
- new_ws['A1'] = '=SUM(Data!B2:B100)'
150
-
151
- wb.save('modified.xlsx')
152
- ```
153
-
154
- ## Formula Rules
155
-
156
- ### Always Use Excel Formulas
157
-
158
- ```python
159
- # WRONG — hardcoded calculation
160
- total = sum(values)
161
- ws['B10'] = total
162
-
163
- # CORRECT — Excel formula
164
- ws['B10'] = '=SUM(B2:B9)'
165
- ```
166
-
167
- This applies to ALL calculations: totals, averages, percentages,
168
- growth rates, ratios, conditional aggregations.
169
-
170
- ### Visibility checklist (model must self-verify)
171
-
172
- - Opening the file in Excel/LibreOffice: calculated cells show **formulas**
173
- in the formula bar, not only final numbers with no `=`.
174
- - Totals, subtotals, ratios, and lookups reference **cell addresses** or
175
- structured ranges — not constants copied from a script.
176
- - If the user asked for “Excel they can trust,” err on the side of **more
177
- rows/columns with simpler formulas** rather than fewer cells with opaque
178
- nested functions.
179
-
180
- ### Common Formula Patterns
181
-
182
- | Operation | Formula |
183
- |-----------|---------|
184
- | Sum | `=SUM(B2:B9)` |
185
- | Average | `=AVERAGE(B2:B9)` |
186
- | Count non-empty | `=COUNTA(B2:B9)` |
187
- | Percentage | `=B2/B$10` |
188
- | Year-over-year growth | `=(C2-B2)/B2` |
189
- | Conditional sum | `=SUMIF(A:A,"Category",B:B)` |
190
- | Lookup | `=VLOOKUP(A2,Data!A:C,3,FALSE)` |
191
- | If/then | `=IF(B2>0,B2*C2,0)` |
192
- | Error handling | `=IFERROR(B2/C2,0)` |
193
-
194
- ### Cross-Sheet References
195
-
196
- ```python
197
- ws['A1'] = "=Summary!B5"
198
- ws['A2'] = "=VLOOKUP(A1,Data!A:C,3,FALSE)"
199
- ```
200
-
201
- ## Recalculating Formulas (MANDATORY)
202
-
203
- After creating or editing formulas with openpyxl, values are NOT
204
- calculated. You MUST run recalculation:
205
-
206
- ```bash
207
- python scripts/recalc.py output.xlsx
208
- ```
209
-
210
- The script returns JSON:
211
-
212
- ```json
213
- {
214
- "status": "success",
215
- "total_errors": 0,
216
- "total_formulas": 42,
217
- "sheets_processed": ["Sheet1", "Summary"]
218
- }
219
- ```
220
-
221
- If errors are found:
222
-
223
- ```json
224
- {
225
- "status": "errors_found",
226
- "total_errors": 3,
227
- "total_formulas": 42,
228
- "error_summary": {
229
- "#REF!": {"count": 2, "locations": ["Sheet1!B5", "Sheet1!C10"]},
230
- "#DIV/0!": {"count": 1, "locations": ["Summary!D4"]}
231
- }
232
- }
233
- ```
234
-
235
- **Fix all errors and recalculate again until status is "success".**
236
-
237
- Common error fixes:
238
- - `#REF!` — Invalid cell reference; check if rows/columns were deleted
239
- - `#DIV/0!` — Wrap with `=IFERROR(formula, 0)`
240
- - `#VALUE!` — Wrong data type; check cell contents
241
- - `#NAME?` — Typo in function name or missing quotes on strings
242
- - `#N/A` — VLOOKUP/MATCH found no result; use `=IFERROR()`
243
-
244
- ## Financial Model Standards
245
-
246
- ### Color Coding (Industry Standard)
247
-
248
- | Color | RGB | Usage |
249
- |-------|-----|-------|
250
- | Blue text | `0000FF` | Hardcoded inputs and assumptions |
251
- | Black text | `000000` | All formulas and calculations |
252
- | Green text | `008000` | Links to other sheets in same workbook |
253
- | Red text | `FF0000` | External links to other files |
254
- | Yellow background | `FFFF00` | Key assumptions needing attention |
255
-
256
- ```python
257
- from openpyxl.styles import Font, PatternFill
258
-
259
- input_font = Font(color='0000FF', name='Arial', size=11)
260
- formula_font = Font(color='000000', name='Arial', size=11)
261
- crossref_font = Font(color='008000', name='Arial', size=11)
262
- attention_fill = PatternFill('solid', fgColor='FFFF00')
263
- ```
264
-
265
- ### Number Formatting
266
-
267
- | Data Type | Format Code | Example |
268
- |-----------|-------------|---------|
269
- | Currency | `$#,##0;($#,##0);"-"` | $1,500 / ($200) / - |
270
- | Percentage | `0.0%` | 15.3% |
271
- | Multiples | `0.0x` | 8.5x |
272
- | Years | `@` (text) | 2024 (not 2,024) |
273
- | Large numbers | `$#,##0.0,,"mm"` | $1.5mm |
274
- | Integers | `#,##0;(#,##0);"-"` | 1,500 / (200) / - |
275
-
276
- ```python
277
- ws['B2'].number_format = '$#,##0;($#,##0);"-"'
278
- ws['C2'].number_format = '0.0%'
279
- ws['D2'].number_format = '0.0x'
280
- ```
281
-
282
- ### Assumptions Placement
283
-
284
- Place ALL assumptions in dedicated cells with blue text. Never
285
- hardcode values inside formulas:
286
-
287
- ```python
288
- ws['B3'] = 0.05
289
- ws['B3'].font = input_font
290
- ws['B3'].number_format = '0.0%'
291
- ws['B3'].comment = openpyxl.comments.Comment(
292
- 'Revenue growth assumption — Source: Management guidance FY2025',
293
- 'BluMa'
294
- )
295
-
296
- ws['C5'] = '=C4*(1+$B$3)'
297
- ws['C5'].font = formula_font
298
- ```
299
-
300
- ### Documentation for Hardcoded Values
301
-
302
- Every hardcoded number needs a source comment:
303
- - `Source: Company 10-K, FY2024, Page 45, Revenue Note`
304
- - `Source: Bloomberg Terminal, 2025-08-15, AAPL US Equity`
305
- - `Source: FactSet, Consensus Estimates, 2025-08-20`
306
-
307
- ## Verification Checklist
308
-
309
- Before delivering any xlsx file:
310
-
311
- 1. Run `scripts/recalc.py` — status must be "success"
312
- 2. Spot-check 3-5 formulas against expected values
313
- 3. Verify column mappings (Excel columns are 1-indexed)
314
- 4. Check row offsets (DataFrame row 5 = Excel row 6 with header)
315
- 5. Confirm no NaN or None values leaked into cells
316
- 6. Validate number formatting on all numeric columns
317
- 7. Ensure all hardcodes have source comments (financial models)
318
- 8. Test edge cases: zero values, empty cells, negative numbers
319
-
320
- ## Library Selection Guide
321
-
322
- | Task | Use |
323
- |------|-----|
324
- | Data analysis, filtering, grouping | pandas |
325
- | Formulas, formatting, styles | openpyxl |
326
- | Complex formatting + data analysis | Both (pandas to process, openpyxl to format) |
327
- | Read calculated values (no edit) | openpyxl with `data_only=True` |
328
- | Very large files (read-only) | openpyxl with `read_only=True` |
329
-
330
- ## Available References
331
-
332
- - REFERENCE.md: Advanced financial modeling patterns, chart creation, pivot tables, conditional formatting, data validation, print layout
333
-
334
- ## Available Scripts
335
-
336
- - recalc.py: Recalculate all formulas via LibreOffice and scan for errors (MANDATORY after formula changes)
337
- - office/soffice.py: LibreOffice process management for sandboxed environments (internal)
338
- - office/pack.py: Compress Office XML files into .xlsx (internal)
339
- - office/unpack.py: Decompress .xlsx into Office XML structure (internal)
340
- - office/validate.py: Validate Office XML structure against schemas (internal)