libreoffice/agent-harness/LIBREOFFICE.md
The LibreOffice CLI harness provides command-line document editing for Writer (word processor), Calc (spreadsheet), and Impress (presentations). It produces real ODF files (ZIP archives with XML) that can be opened by LibreOffice and other ODF-compatible applications.
cli/
__init__.py
__main__.py # python3 -m cli.libreoffice_cli entry point
libreoffice_cli.py # Click CLI with groups and REPL
core/
__init__.py
document.py # create/open/save/info/profiles
writer.py # paragraphs, headings, lists, tables, page breaks
calc.py # sheets, cells, formulas
impress.py # slides, elements
styles.py # named styles, apply to content
export.py # ODF, HTML, text export
session.py # undo/redo state management
utils/
__init__.py
odf_utils.py # ODF XML generation and ZIP packaging
tests/
__init__.py
test_core.py # 60+ unit tests
test_full_e2e.py # 40+ E2E tests with ODF validation
Documents are stored as JSON project files (.lo-cli.json) with this structure:
{"type": "writer", "content": [...], "styles": {...}, "settings": {...}}{"type": "calc", "sheets": [...], "styles": {...}, "settings": {...}}{"type": "impress", "slides": [...], "styles": {...}, "settings": {...}}--json flag for agent consumptioncd /root/cli-anything/libreoffice/agent-harness
pip install click
python3 -m cli.libreoffice_cli --help
python3 -m pytest cli/tests/ -v
python3 -m cli.libreoffice_cli document new --type writer -n "Report" -o report.json
python3 -m cli.libreoffice_cli --project report.json writer add-heading -t "Title" -l 1
python3 -m cli.libreoffice_cli --project report.json writer add-paragraph -t "Body text"
python3 -m cli.libreoffice_cli --project report.json export render report.odt -p odt --overwrite
python3 -m cli.libreoffice_cli document new --type calc -o budget.json
python3 -m cli.libreoffice_cli --project budget.json calc set-cell A1 "Revenue" --type string
python3 -m cli.libreoffice_cli --project budget.json calc set-cell B1 "50000" --type float
python3 -m cli.libreoffice_cli --project budget.json export render budget.ods -p ods --overwrite
python3 -m cli.libreoffice_cli document new --type impress -o deck.json
python3 -m cli.libreoffice_cli --project deck.json impress add-slide -t "Welcome" -c "Hello"
python3 -m cli.libreoffice_cli --project deck.json export render deck.odp -p odp --overwrite