@lumifai/harness-tool-pack-office-editing
v1.1.0
Published
Headless, format-aware editing for DOCX, XLSX, PPTX, and PDF files.
Readme
@lumifai/harness-tool-pack-office-editing
Headless, format-aware editing for DOCX, XLSX, PPTX, and PDF files.
import {
createOfficeDocument,
createOfficeEditingToolPack,
} from '@lumifai/harness-tool-pack-office-editing';
const officeEditing = createOfficeEditingToolPack();Register it alongside the existing Docling pack when the agent needs both broad document retrieval and authoritative file mutation. The two packs are independent: Docling converts files for reading, while this pack rereads the original file and owns editing, revision checks, atomic output, and verification. This package does not import or copy GenOffice source; it is a clean-room implementation of the relevant headless design patterns.
The pack exposes office_inspect, office_outline, office_find, office_read,
office_propose_edits, office_apply_edits, and office_verify.
Edits use a validated JSON operation DSL. The public createOfficeDocument
factory is the pack seam: inspect, find, read, propose, apply, and verify.
Direct apply is the normal mutation path:
const document = createOfficeDocument();
const receipt = await document.apply(
{
sourcePath: 'documents/report.docx',
revision: { sha256: sourceSha256, mtime: sourceMtime },
operations: [{ op: 'replace_text', target: '10 million', replacement: '12 million' }],
},
context,
);For workflows needing a reviewable plan, call propose first and pass its plan
to apply. Plans use the lumif.office-edit-plan discriminator and include a
digest-covered, format-native preview. OOXML previews record output hash,
changed parts, and untouched-part verification; PDF previews omit package fields
and do not treat output hash as a stable fingerprint. Plans are rejected when the strict source SHA-256 or
mtime revision is stale, when the digest or preview is tampered with, or when
verification cannot be rerun. New output files are written below edited/ by
default; outputPath, overwrite, and inPlace are apply-time options, and
in-place writes require explicit host configuration.
Supported headless mutations include depth-aware DOCX text replacement/insertion (including rich runs, text boxes, tables, headers, footers, comments, footnotes, and endnotes), block replacement with style-template preservation, and basic run styling; XLSX typed cells, formulas, ranges, hyperlinks, bounded find/replace, sheet renames, and safe row/column shifts; PPTX shape/picture/table/group text and geometry edits; and PDF page operations, text overlays, persistent highlight/underline/strikeout annotations, and typed AcroForm fields.
DOCX replace_text is first-match by default; pass all: true when a plan
intentionally targets every occurrence. PDF markup_text is the persistent
counterpart to the read-only evidence anchors returned by office_find.
XLSX structural edits fail closed when tables or defined names are present. Formula values are not calculated by this package; formula writes mark the workbook for recalculation on open and report a warning. Unsupported OOXML parts are preserved through the internal OOXML package preservation seam and untouched-entry hash checks, but complex visual layouts should still be reviewed. PDF editing remains independent of that seam.
Evidence anchors from office_find include a source quote; DOCX/PPTX anchors
include character offsets, and PDF anchors include character spans plus
approximate page boxes. These anchors support temporary source highlighting and
citations without mutating the source.
