@unieai/rabi-skill-office 0.0.0-stage → 0.2.1-rc.3
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.
- package/LICENSE +21 -0
- package/README.md +7 -2
- package/assets/office/SKILL.md +15 -0
- package/assets/office/references/sidecar.md +17 -0
- package/assets/office-docx/SKILL.md +40 -0
- package/assets/office-export-pdf/SKILL.md +18 -0
- package/assets/office-pptx/SKILL.md +64 -0
- package/assets/office-recalculate/SKILL.md +18 -0
- package/assets/office-render/SKILL.md +31 -0
- package/assets/office-xlsx/SKILL.md +52 -0
- package/lib/index.js +104 -0
- package/lib/types/index.d.ts +25 -0
- package/package.json +32 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unieai/rabi-skill-office
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bundled Word, PowerPoint, and Excel workflows and LibreOffice Kit operations
|
|
4
|
+
|
|
5
|
+
Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
|
|
6
|
+
not meant to be used on its own.
|
|
7
|
+
|
|
8
|
+
See LICENSE for the license and copyright of this package.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office
|
|
3
|
+
description: Create, edit, inspect, or convert Office documents, spreadsheets, presentations, and PDFs. Load to choose the relevant workflow.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Office task routing
|
|
7
|
+
|
|
8
|
+
Call the `skill` tool with the format skill name before creating, reading, or editing Office files. Standalone rendering, PDF export, and recalculation need only their operation skill.
|
|
9
|
+
|
|
10
|
+
- Create, read, or edit: `office-docx` (Word), `office-pptx` (PowerPoint), or `office-xlsx` (Excel).
|
|
11
|
+
- Images, visual inspection, or tasks primarily about layout, spacing, sizing, or alignment: `office-render`, even without an explicit visual-check request.
|
|
12
|
+
- Refresh spreadsheet formula results: `office-recalculate`.
|
|
13
|
+
- Export an Office file to PDF: `office-export-pdf`.
|
|
14
|
+
|
|
15
|
+
Honor requests to skip rendering. New files, content edits, formulas, and incidental formatting such as bold headers or number formats need no render unless visual inspection is requested. Do not reload skills.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Missing Office sidecar
|
|
2
|
+
|
|
3
|
+
These instructions apply in Web, Desktop, and SDK sessions. First check whether an existing LibreOffice Kit installation can serve the task; a missing `dsoffice` command on PATH alone does not establish that the sidecar is absent. If the required sidecar is missing and the user has not already authorized its download, use the available ask-question tool to ask whether they want to download the Office conversion engine. If that tool is unavailable, ask in the conversation. Wait for explicit agreement before downloading or installing; if the user declines, continue work that does not need the engine and report the unavailable operation.
|
|
4
|
+
|
|
5
|
+
After agreement, install `@unieai/libreoffice-kit` together with the matching engine package, using the engine version declared by the main package's optional dependencies. Use an available npm or pnpm in a task-local tools directory, with `--ignore-scripts`: the packages provide prebuilt binaries and do not need installation scripts. Keep the package manager's cache or store in that writable task directory too (for npm, pass `--cache <task-tools-directory>/.npm-cache`). Select the package for the operating system and architecture of the Node.js process that will run the CLI, including when Node runs under emulation:
|
|
6
|
+
|
|
7
|
+
| Runtime platform | Engine package |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| Windows x64 | `@unieai/libreoffice-kit-win32-x64` |
|
|
10
|
+
| Windows ARM64 | `@unieai/libreoffice-kit-win32-arm64` |
|
|
11
|
+
| macOS Apple Silicon | `@unieai/libreoffice-kit-darwin-arm64` |
|
|
12
|
+
| macOS Intel | `@unieai/libreoffice-kit-darwin-x64` |
|
|
13
|
+
| No matching native package, including Linux | `@unieai/libreoffice-kit-wasm` |
|
|
14
|
+
|
|
15
|
+
Prefer the matching native package; otherwise use WASM when its package supports the current platform. Check package platform restrictions before installation rather than forcing an incompatible package. The published WASM package currently declares Linux support.
|
|
16
|
+
|
|
17
|
+
Reuse the bundled Node.js and pnpm paths from `load_workspace_dependencies` when available, or the user's configured Node.js and package manager. Permission to download the Office sidecar does not include installing Python, Node.js, or a package manager. If those prerequisites are missing, explain what is needed. Run the new installation's `dsoffice` entry, or its `lib/cli.js` with the selected Node executable, by path; do not assume installation changed the session's PATH. Check `dsoffice capabilities` before continuing the requested operation.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office-docx
|
|
3
|
+
description: Create, read, edit, and validate Word documents (.docx).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Word documents
|
|
7
|
+
|
|
8
|
+
Use `python-docx` for DOCX creation and ordinary edits. Follow an explicit user or applicable AGENTS.md requirement for a project environment or another library. Otherwise call `load_workspace_dependencies` and execute the returned Python path with its bundled libraries. Do not install packages or discover a system Python for the default workflow. If the tool is unavailable, use an already configured environment and report a missing dependency only when it prevents the requested operation.
|
|
9
|
+
|
|
10
|
+
Keep source scripts, intermediate files, and final documents in the task workspace; the runtime and this skill directory are read-only resources. Use the user's requested language and preserve an existing document's design unless a redesign is requested.
|
|
11
|
+
|
|
12
|
+
Name Python scripts for their task, such as `edit_docx.py`; avoid module names such as `inspect.py`, `docx.py`, or `zipfile.py` that shadow imported libraries.
|
|
13
|
+
|
|
14
|
+
## Create and edit
|
|
15
|
+
|
|
16
|
+
For text edits, locate the target by its text or position and inspect only its runs and formatting. A title can be an ordinary paragraph without a Title style or document-property title. Update the relevant runs; assigning paragraph `.text` destroys run formatting. Save a new file unless an in-place edit is requested. Read other structures only when the edit involves them; rebuilding a document can lose unsupported features.
|
|
17
|
+
|
|
18
|
+
Use paragraph styles for headings and body text. Size tables for the section that contains them, and account for merged cells and nested tables. Chinese, Japanese, and Korean text may need an explicit `w:eastAsia` font assignment in addition to `run.font.name`; font names alone do not establish glyph availability or rendered appearance.
|
|
19
|
+
|
|
20
|
+
For a new document, use the selected Python executable:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from docx import Document
|
|
24
|
+
|
|
25
|
+
document = Document()
|
|
26
|
+
document.add_heading("Project report", level=0)
|
|
27
|
+
document.add_paragraph("Summary", style="Heading 1")
|
|
28
|
+
document.add_paragraph("The requested findings go here.")
|
|
29
|
+
document.save("report.docx")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
python-docx does not paginate or render documents. Do not represent ordinary replacement, colored text, or comments as tracked changes. When real revisions or unsupported OOXML features matter, preserve their package parts and verify the requested operation rather than silently discarding them. When writing package parts directly, create a new ZIP and copy each unchanged member once; appending a replacement member duplicates its name and corrupts the package.
|
|
33
|
+
|
|
34
|
+
## Check and deliver
|
|
35
|
+
|
|
36
|
+
Reopen the saved document with python-docx and verify the requested content, related formatting, and unchanged content that must be preserved. Deliver when these checks pass. Investigate package-level details only for a concrete failure, ambiguous edit target, unsupported feature, or explicit user requirement.
|
|
37
|
+
|
|
38
|
+
Creating a file or changing content with incidental basic formatting does not require additional operations. Load `office-render` for requested images or visual inspection. When styling, font color, spacing, sizing, or text alignment is the requested edit, load `office-render` and inspect the changed page even without a separate visual-check request, unless the user explicitly skips rendering. For PDF output load `office-export-pdf`.
|
|
39
|
+
|
|
40
|
+
Call `present({"files":[{"path":"report.docx"}]})` with the actual final DOCX path. It exposes the current source file without copying or preserving its bytes, so keep that file in place and do not present temporary QA reports unless requested. If `present` is unavailable, provide the final workspace path using the session's supported file delivery method.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office-export-pdf
|
|
3
|
+
description: Convert an Office document to a requested PDF with LibreOffice Kit.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Export an Office document to PDF
|
|
7
|
+
|
|
8
|
+
Use the installed LibreOffice Kit CLI through the shell with the absolute Node and CLI paths supplied below. In Bash, invoke `"<node>" "<cli>"`; in PowerShell, invoke `& "<node>" "<cli>"`. Prefer bundled LibreOffice unless the user requests another installation. If the Office sidecar is missing, follow [sidecar setup](../office/references/sidecar.md): ask whether the user wants to download it and install only after they agree. Do not invoke system soffice, use npx, or install a replacement to work around a failed conversion with an installed sidecar.
|
|
9
|
+
|
|
10
|
+
Convert the final saved Office file to a new PDF in the task workspace. Preserve the source. Quote each input and output path.
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
"<node>" "<cli>" convert --input <final-office-file> --output <new-file.pdf>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Check the command result, nonempty output, and `%PDF-` file signature, then report that extent of validation. Unless the user requests deeper checks, do not search for PDF readers, generate images, or install tools to validate a conversion. Spreadsheet PDF pages follow workbook print settings; change those settings only when requested. Conversion may differ from the native application's pagination or fonts.
|
|
17
|
+
|
|
18
|
+
If export fails, preserve the usable source and report the export limitation. Do not repeatedly convert an unchanged source or use conversion to investigate a failed preview. For PDF export alone, stop after these checks. Only a request for images or visual inspection calls for `office-render`; load it before that separate operation. Deliver the requested PDF through `present` when available, keeping the file in place.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office-pptx
|
|
3
|
+
description: Create, read, edit, and validate PowerPoint presentations (.pptx).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PowerPoint presentations
|
|
7
|
+
|
|
8
|
+
Follow an explicit user or applicable AGENTS.md requirement for an environment or library. Otherwise call `load_workspace_dependencies` and use its Python executable and bundled presentation libraries. Do not install npm or pip packages or locate a system interpreter for the default workflow. If the tool is unavailable, use an already configured environment and report a missing dependency only when it prevents the requested operation.
|
|
9
|
+
|
|
10
|
+
Keep scripts and output files in the task workspace. The runtime and skill directory contain shared read-only resources. Match the requested slide language and the supplied presentation's design when editing it.
|
|
11
|
+
|
|
12
|
+
Name Python scripts for their task, such as `edit_pptx.py`; avoid module names such as `inspect.py`, `pptx.py`, or `zipfile.py` that shadow imported libraries.
|
|
13
|
+
|
|
14
|
+
## Create and edit
|
|
15
|
+
|
|
16
|
+
Use `python-pptx` to inspect or modify an existing presentation. Inspect slide layouts, text runs, images, tables, and charts before editing. Change only the requested content, preserve mixed text formatting, and save to a new file unless the user requests an in-place edit. Rebuilding slides can discard unsupported animation, SmartArt, or other extension content.
|
|
17
|
+
|
|
18
|
+
For a new deck, use `python-pptx` with editable text, tables, and charts. Use local image assets rather than network-dependent image URLs. Set slide dimensions, text sizes, and chart data explicitly.
|
|
19
|
+
|
|
20
|
+
A minimal editable deck, run with the selected Python executable:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from pptx import Presentation
|
|
24
|
+
from pptx.chart.data import CategoryChartData
|
|
25
|
+
from pptx.enum.chart import XL_CHART_TYPE
|
|
26
|
+
from pptx.util import Inches, Pt
|
|
27
|
+
|
|
28
|
+
presentation = Presentation()
|
|
29
|
+
presentation.slide_width = Inches(13.333)
|
|
30
|
+
presentation.slide_height = Inches(7.5)
|
|
31
|
+
slide = presentation.slides.add_slide(presentation.slide_layouts[6])
|
|
32
|
+
title = slide.shapes.add_textbox(Inches(0.6), Inches(0.4), Inches(12), Inches(0.8))
|
|
33
|
+
run = title.text_frame.paragraphs[0].add_run()
|
|
34
|
+
run.text = "Quarterly report"
|
|
35
|
+
run.font.size = Pt(30)
|
|
36
|
+
data = CategoryChartData()
|
|
37
|
+
data.categories = ["Q1", "Q2"]
|
|
38
|
+
data.add_series("Revenue", [12, 18])
|
|
39
|
+
slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED,
|
|
40
|
+
Inches(0.8), Inches(1.6), Inches(11.5), Inches(4.8), data)
|
|
41
|
+
presentation.save("report.pptx")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use `Inches` or `Cm` for positions and sizes and `Pt` for font sizes. To edit a generated title while retaining its other slides and charts:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from pptx import Presentation
|
|
48
|
+
|
|
49
|
+
presentation = Presentation("report.pptx")
|
|
50
|
+
for shape in presentation.slides[0].shapes:
|
|
51
|
+
if shape.has_text_frame and shape.text == "Quarterly report":
|
|
52
|
+
shape.text_frame.paragraphs[0].runs[0].text = "Quarterly results"
|
|
53
|
+
presentation.save("report-edited.pptx")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Check that text and images fit the slide dimensions, titles form a useful sequence, and chart labels agree with source values. Paragraph alignment does not move a text box: when a title must be centered on the slide, center both its paragraph and the text box against `presentation.slide_width`, then reopen to verify both. A native chart's embedded workbook is part of the deliverable and must contain the intended data. Library support for writing PPTX is not a rendering engine or a guarantee that every PowerPoint feature survives editing.
|
|
57
|
+
|
|
58
|
+
## Check and deliver
|
|
59
|
+
|
|
60
|
+
Reopen the saved presentation with python-pptx to verify the requested slide count, content, formatting, chart data, and notes, including unchanged content that must be preserved. These checks do not establish text fit, readable contrast, or rendering fidelity.
|
|
61
|
+
|
|
62
|
+
Deliver after the requested edits are verified. Creating a file or changing content with incidental basic formatting does not require additional operations. Load `office-render` for requested images or visual inspection and for appearance-focused styling, spacing, sizing, or alignment changes unless the user explicitly skips rendering. For PDF output load `office-export-pdf`.
|
|
63
|
+
|
|
64
|
+
Call `present({"files":[{"path":"report-edited.pptx"}]})` with the actual final PPTX path. It exposes the current source file without copying or preserving its bytes, so keep that file in place and leave intermediate images and reports out of delivery unless requested. If `present` is unavailable, use the session's supported file delivery method.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office-recalculate
|
|
3
|
+
description: Refresh spreadsheet formula caches and verify calculated values with LibreOffice Kit.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Recalculate spreadsheet formulas
|
|
7
|
+
|
|
8
|
+
Use the installed LibreOffice Kit CLI through the shell with the absolute Node and CLI paths supplied below. In Bash, invoke `"<node>" "<cli>"`; in PowerShell, invoke `& "<node>" "<cli>"`. Prefer bundled LibreOffice unless the user requests another installation. If the Office sidecar is missing, follow [sidecar setup](../office/references/sidecar.md): ask whether the user wants to download it and install only after they agree. Do not invoke system soffice, use npx, or install a replacement to work around a failed recalculation with an installed sidecar.
|
|
9
|
+
|
|
10
|
+
Keep the original workbook and write a new file in the task workspace. Quote each input and output path.
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
"<node>" "<cli>" recalculate --input <workbook.xlsx> --output <recalculated.xlsx>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Verify the saved result with openpyxl, using `load_workspace_dependencies` for the Python path unless a project environment is required. Open it with both `data_only=False` and `data_only=True`. Check that formulas survive and cached results match the requested logic, expected totals, and cell types. Check required unchanged sheets, styles, and data. Recalculation does not validate business logic or guarantee Excel-specific feature compatibility.
|
|
17
|
+
|
|
18
|
+
If no supported recalculation engine is available or the command fails, preserve the workbook and explain that calculated values could not be refreshed. Do not replace requested formulas with constants or present stale/absent caches as fresh results. Deliver the verified output through `present` when available, keeping the file in place.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office-render
|
|
3
|
+
description: Render requested document images or inspect visual layout with LibreOffice Kit.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Document images and visual inspection
|
|
7
|
+
|
|
8
|
+
Use the installed LibreOffice Kit CLI through the shell with the absolute Node and CLI paths supplied below. In Bash, invoke `"<node>" "<cli>"`; in PowerShell, invoke `& "<node>" "<cli>"`. Prefer bundled LibreOffice unless the user requests another installation. If the Office sidecar is missing, follow [sidecar setup](../office/references/sidecar.md): ask whether the user wants to download it and install only after they agree. Do not invoke system soffice, use npx, install a replacement renderer, or build an alternative rendering pipeline to work around a failed render with an installed sidecar.
|
|
9
|
+
|
|
10
|
+
Before generating images only for inspection, establish that the current model accepts images. Otherwise finish the applicable content and structure checks and report the requested visual check as unavailable. Do not generate unreadable previews, retry image reads, or choose a second model. Requested image exports can still be delivered.
|
|
11
|
+
|
|
12
|
+
## Render the saved deliverable
|
|
13
|
+
|
|
14
|
+
Keep the saved deliverable in the task workspace. For requested image exports, use the requested output directory and retain the images. For inspection-only previews, create a private, uniquely named temporary parent inside that workspace and pass a child path that does not yet exist as `--output-dir`; the CLI creates that child. On POSIX, use `preview_root=$(mktemp -d "./.rabi-office.XXXXXXXX")` (owner-only permissions) and `--output-dir "$preview_root/render"`. On PowerShell, create a parent named `.rabi-office-` plus `[guid]::NewGuid().ToString('N')` under the task workspace and pass an uncreated `render` child; it inherits the workspace ACL. Quote each input and output path. Retain the parent until image inspection finishes, then remove only that parent, including after a failed render. Never use a fixed directory name or remove the workspace itself. Report inspection results in text; the reply must not link or embed removed previews.
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
"<node>" "<cli>" render --input <final-file> --output-dir <new-directory> --pages "1,3,4"
|
|
18
|
+
"<node>" "<cli>" render --input <final-workbook.xlsx> --output-dir <new-directory> --sheet <exact-name> --range <A1-range>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For DOCX, PPTX, or PDF, batch requested pages/slides in one call. In PowerShell, quote comma-separated `--pages` values so they remain one argument. Inspect all pages only for a requested whole-document review. For worksheets, choose the exact affected range, including chart/drawing regions; worksheet numbers are not PDF page numbers. Inspect the final saved file, reuse existing images for an unchanged source, and rerender only after requested source changes or for previously unrendered regions. Change print areas or scaling only when the user requests print layout.
|
|
22
|
+
|
|
23
|
+
Read the returned JSON manifest for image paths, page counts, fragment rectangles, and missing-font diagnostics. Use the session's image-reading tool to inspect the requested images. Check clipping, alignment, headings, table widths, contrast, chart labels, and number formats as relevant to the task. A successful command or image read alone does not establish a usable preview; guessed text geometry does not establish overflow.
|
|
24
|
+
|
|
25
|
+
## Failed or blank previews
|
|
26
|
+
|
|
27
|
+
For populated content, a fully transparent or uniformly blank image is a renderer failure. If a pixel check is needed, composite RGBA onto white first; raw RGB under transparent pixels can look nonblank. Check once and do not reread the same image. Stop visual checks for the task immediately after a blank result. This overrides the rerender-after-edit guidance above: do not render or read images again, even after editing or copying the source, or try another range, page, sheet, DPI, output format, diagnostic export, or print setting. Preserve the usable source and requested outputs and finish applicable content/data checks.
|
|
28
|
+
|
|
29
|
+
If content and structure checks pass, name the saved file and verified edits as needed, then include exactly one visual-status sentence: "Content and structure checks passed; visual inspection was not completed." in English, or "内容与结构检查通过;视觉检查未完成。" in Chinese. Do not add a render or preview bullet, explain why inspection stopped, or describe the image or pixels. Report content or structure failures separately; never say all checks passed or claim visual verification.
|
|
30
|
+
|
|
31
|
+
LibreOffice output can differ from Word, PowerPoint, or Excel. Images do not certify animation/media playback, refresh formula caches in the source workbook, or guarantee native application fidelity. Deliver requested files through `present` when available; keep the files in place. Do not deliver inspection images or reports unless requested.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: office-xlsx
|
|
3
|
+
description: Read, create, edit, and validate Excel workbooks, data, and formulas (.xlsx).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Excel workbooks
|
|
7
|
+
|
|
8
|
+
Follow an explicit user or applicable AGENTS.md requirement for an environment or library. Otherwise call `load_workspace_dependencies` and run its Python executable with bundled `openpyxl` and `pandas`. Do not install packages or search for a system Python for the default workflow. If the tool is unavailable, use an already configured environment and report a missing dependency only when it prevents the requested operation.
|
|
9
|
+
|
|
10
|
+
Keep scripts, working files, and outputs in the task workspace. The runtime and skill directory are shared read-only resources. Save to a new workbook unless the user requests an in-place edit.
|
|
11
|
+
|
|
12
|
+
Name Python scripts for their task, such as `edit_xlsx.py`; avoid module names such as `inspect.py`, `openpyxl.py`, or `pandas.py` that shadow imported libraries.
|
|
13
|
+
|
|
14
|
+
## Read and modify
|
|
15
|
+
|
|
16
|
+
Use `openpyxl` for existing XLSX workbooks and targeted cell or style changes. Load with `data_only=False` when formulas must survive. Inspect sheet names, the affected cell types, formulas, styles, merged ranges, and referenced ranges before editing. Check the saved file by reopening it, including unchanged content that the request requires preserving.
|
|
17
|
+
|
|
18
|
+
Use pandas for data analysis and transformations. A DataFrame is not the workbook: exporting it over an existing file can lose sheets, formulas, charts, and formatting. Write analysis results back to the intended ranges with openpyxl. `XlsxWriter` can create new workbooks, but cannot read or modify existing ones.
|
|
19
|
+
|
|
20
|
+
For a new workbook, the selected Python environment can write editable values, styles, and formulas directly:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from openpyxl import Workbook
|
|
24
|
+
from openpyxl.styles import Font
|
|
25
|
+
|
|
26
|
+
workbook = Workbook()
|
|
27
|
+
sheet = workbook.active
|
|
28
|
+
sheet.title = "Revenue"
|
|
29
|
+
for row in [("Quarter", "Revenue"), ("Q1", 12), ("Q2", 18), ("Total", "=SUM(B2:B3)")]:
|
|
30
|
+
sheet.append(row)
|
|
31
|
+
for cell in sheet[1]:
|
|
32
|
+
cell.font = Font(bold=True)
|
|
33
|
+
sheet.column_dimensions["A"].width = 18
|
|
34
|
+
sheet.column_dimensions["B"].width = 18
|
|
35
|
+
workbook.save("report.xlsx")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Preserve numbers, dates, booleans, and identifiers as the intended cell types; formatting is not a type conversion. For modifications, load the existing file with `openpyxl.load_workbook("input.xlsx", data_only=False)`, change the requested ranges, and save a separate result. Avoid a DataFrame round trip when workbook features must survive.
|
|
39
|
+
|
|
40
|
+
Writing a formula does not calculate its result. openpyxl and XlsxWriter do not evaluate formulas; `data_only=True` returns cached values that may be absent or stale. When calculated results must be refreshed, load `office-recalculate`. Do not replace requested formulas with constants or report stale values as newly calculated results.
|
|
41
|
+
|
|
42
|
+
Do not rename `.xls`, `.xlsb`, encrypted files, or macro-enabled files to `.xlsx`. They need an appropriate supported operation. `keep_vba=True` can preserve VBA package content in an XLSM workflow, but does not execute or edit macros and does not guarantee every advanced workbook feature survives. Preserve the original and verify such requirements explicitly.
|
|
43
|
+
|
|
44
|
+
## Check and deliver
|
|
45
|
+
|
|
46
|
+
Reopen the saved workbook with openpyxl and verify the requested sheet names, values, types, formulas, styles, and totals against the source data, including unchanged content that must be preserved. These checks do not calculate formulas or judge workbook appearance.
|
|
47
|
+
|
|
48
|
+
Load `office-render` for requested images or visual inspection and whenever the user's primary task targets appearance, including cell fill colors, text alignment, spacing, or sizing. These appearance changes require rendering even without a separate visual-check request, unless the user explicitly skips it. New workbooks and data or formula edits do not require rendering solely because they include incidental basic formatting. In particular, bold headers and number formats accompanying data edits do not require loading `office-render` or running its commands.
|
|
49
|
+
|
|
50
|
+
Load `office-recalculate` when refreshed calculated values are needed and `office-export-pdf` for PDF output. Deliver after the requested data checks pass and the required operations finish.
|
|
51
|
+
|
|
52
|
+
Call `present({"files":[{"path":"report.xlsx"}]})` with the actual final workbook path. It exposes the current source file without copying or preserving its bytes, so keep that file in place and omit intermediate scripts and reports unless requested. If `present` is unavailable, use the session's supported file delivery method.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, join, sep } from "node:path";
|
|
4
|
+
import { isSea } from "node:sea";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import z from "@unieai/schemastery";
|
|
7
|
+
import { BUNDLED_SKILL_RANK } from "@unieai/rabi-skill";
|
|
8
|
+
import { parse } from "yaml";
|
|
9
|
+
//#region lib/types/index.js
|
|
10
|
+
/** Bundled Office workflows and filesystem resources for document authoring and operations. */
|
|
11
|
+
const SKILL_NAMES = [
|
|
12
|
+
"office",
|
|
13
|
+
"office-docx",
|
|
14
|
+
"office-pptx",
|
|
15
|
+
"office-xlsx",
|
|
16
|
+
"office-render",
|
|
17
|
+
"office-recalculate",
|
|
18
|
+
"office-export-pdf"
|
|
19
|
+
];
|
|
20
|
+
/** Validated resource configuration. */
|
|
21
|
+
const Config = z.object({
|
|
22
|
+
assetRoot: z.string().min(1),
|
|
23
|
+
node: z.string().min(1),
|
|
24
|
+
cli: z.union([z.string().min(1), z.const(false)])
|
|
25
|
+
});
|
|
26
|
+
/** Cordis plugin identity. */
|
|
27
|
+
const name = "skill-office";
|
|
28
|
+
/** Registry used by the bundled provider. */
|
|
29
|
+
const inject = ["skills"];
|
|
30
|
+
function parseSkill(raw, path) {
|
|
31
|
+
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(raw);
|
|
32
|
+
if (frontmatter?.[1] === void 0) throw new Error(`skill-office: ${path} has no YAML frontmatter`);
|
|
33
|
+
const metadata = parse(frontmatter[1]);
|
|
34
|
+
const description = typeof metadata === "object" && metadata !== null && "description" in metadata ? metadata.description : void 0;
|
|
35
|
+
if (typeof description !== "string" || description.length === 0) throw new Error(`skill-office: ${path} has no description`);
|
|
36
|
+
return {
|
|
37
|
+
description,
|
|
38
|
+
content: raw.slice(frontmatter[0].length).trim()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function officeRuntime(config) {
|
|
42
|
+
if (config.cli === false) return "\n\nLibreOffice Kit is disabled in this deployment.";
|
|
43
|
+
if (config.node === void 0 && (isSea() || process.versions.electron !== void 0)) throw new Error("skill-office: packaged applications must supply a standalone Node executable");
|
|
44
|
+
const node = config.node ?? process.execPath;
|
|
45
|
+
let cli = config.cli;
|
|
46
|
+
if (cli === void 0) cli = join(dirname(fileURLToPath(import.meta.resolve("@unieai/libreoffice-kit/package.json"))), "lib", "cli.js");
|
|
47
|
+
for (const path of [node, cli]) if (!isAbsolute(path) || !statSync(path).isFile()) throw new Error(`skill-office: expected an absolute executable file: ${path}`);
|
|
48
|
+
return `\n\n## Installed LibreOffice Kit\n\nUse these absolute paths for every LibreOffice Kit command. Pass the CLI entry as the first argument to Node.\n\n${JSON.stringify({ libreofficeKit: {
|
|
49
|
+
node,
|
|
50
|
+
cli
|
|
51
|
+
} }, void 0, 2)}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Register Office skills with resources readable by the script interpreter.
|
|
55
|
+
* @param ctx - Context carrying the skill registry.
|
|
56
|
+
* @param config - Optional external assets directory for packaged applications.
|
|
57
|
+
*/
|
|
58
|
+
function apply(ctx, config = {}) {
|
|
59
|
+
const assetRoot = config.assetRoot ?? fileURLToPath(new URL("../assets/", import.meta.url));
|
|
60
|
+
if (!isAbsolute(assetRoot)) throw new Error("skill-office: assetRoot must be an absolute directory");
|
|
61
|
+
const candidates = SKILL_NAMES.map((skillName) => {
|
|
62
|
+
const directory = join(assetRoot, skillName);
|
|
63
|
+
const path = join(directory, "SKILL.md");
|
|
64
|
+
const { description } = parseSkill(readFileSync(path, "utf8"), path);
|
|
65
|
+
return {
|
|
66
|
+
name: skillName,
|
|
67
|
+
description,
|
|
68
|
+
invocation: {
|
|
69
|
+
modelInvocable: true,
|
|
70
|
+
userInvocable: true
|
|
71
|
+
},
|
|
72
|
+
provider: "rabi-office",
|
|
73
|
+
source: "bundled",
|
|
74
|
+
rank: BUNDLED_SKILL_RANK,
|
|
75
|
+
resourceBase: {
|
|
76
|
+
kind: "directory",
|
|
77
|
+
path: directory.split(sep).join("/")
|
|
78
|
+
},
|
|
79
|
+
locator: path
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
const provider = {
|
|
83
|
+
name: "rabi-office",
|
|
84
|
+
list: () => Promise.resolve(candidates),
|
|
85
|
+
async get(candidate, options) {
|
|
86
|
+
const { rank: _rank, locator, ...summary } = candidate;
|
|
87
|
+
const content = parseSkill(await readFile(locator, {
|
|
88
|
+
encoding: "utf8",
|
|
89
|
+
signal: options.signal
|
|
90
|
+
}), locator).content + ([
|
|
91
|
+
"office-render",
|
|
92
|
+
"office-recalculate",
|
|
93
|
+
"office-export-pdf"
|
|
94
|
+
].includes(candidate.name) ? officeRuntime(config) : "");
|
|
95
|
+
return {
|
|
96
|
+
...summary,
|
|
97
|
+
content
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
ctx.skills.registerProvider(() => provider);
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { Config, apply, inject, name };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Bundled Office workflows and filesystem resources for document authoring and operations. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
import z from '@unieai/schemastery';
|
|
4
|
+
/** Office skill resource location. */
|
|
5
|
+
export interface Config {
|
|
6
|
+
/** Absolute assets directory containing skill folders; defaults to packaged assets. */
|
|
7
|
+
assetRoot?: string;
|
|
8
|
+
/** Standalone Node executable; defaults to the current executable outside Electron and SEA. */
|
|
9
|
+
node?: string;
|
|
10
|
+
/** Absolute LibreOffice Kit CLI entry; false explicitly disables CLI access. */
|
|
11
|
+
cli?: string | false;
|
|
12
|
+
}
|
|
13
|
+
/** Validated resource configuration. */
|
|
14
|
+
export declare const Config: z<Config>;
|
|
15
|
+
/** Cordis plugin identity. */
|
|
16
|
+
export declare const name = "skill-office";
|
|
17
|
+
/** Registry used by the bundled provider. */
|
|
18
|
+
export declare const inject: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Register Office skills with resources readable by the script interpreter.
|
|
21
|
+
* @param ctx - Context carrying the skill registry.
|
|
22
|
+
* @param config - Optional external assets directory for packaged applications.
|
|
23
|
+
*/
|
|
24
|
+
export declare function apply(ctx: Context, config?: Config): void;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-skill-office",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Bundled Word, PowerPoint, and Excel workflows and LibreOffice Kit operations",
|
|
4
|
+
"version": "0.2.1-rc.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib/index.js",
|
|
20
|
+
"assets",
|
|
21
|
+
"lib/types/**/*.d.ts",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@unieai/rabi-skill": "0.2.1-rc.3",
|
|
27
|
+
"@unieai/cordis": "4.0.5"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@unieai/libreoffice-kit": "0.1.5",
|
|
31
|
+
"@unieai/schemastery": "3.18.5",
|
|
32
|
+
"yaml": "^2.4.2"
|
|
33
|
+
}
|
|
34
|
+
}
|