@lucio-ai/docxtor 0.4.0 → 0.5.0

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/README.md CHANGED
@@ -1,69 +1,268 @@
1
- <img src="logo.png" alt="Docxtor logo" />
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Eazydraft/docxtor/main/assets/logo-dark.svg">
3
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Eazydraft/docxtor/main/assets/logo-light.svg">
4
+ <img src="https://raw.githubusercontent.com/Eazydraft/docxtor/main/assets/logo-light.svg" alt="docxtor" width="360">
5
+ </picture>
2
6
 
3
7
  [![npm](https://img.shields.io/npm/v/@lucio-ai/docxtor)](https://www.npmjs.com/package/@lucio-ai/docxtor)
4
8
  [![CI](https://github.com/Eazydraft/docxtor/actions/workflows/ci.yml/badge.svg)](https://github.com/Eazydraft/docxtor/actions/workflows/ci.yml)
5
9
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
10
 
7
- Surgical, LLM-friendly DOCX editing. Load a `.docx`, get a normalized view an LLM can read, apply the patches the LLM produces, and write out a valid `.docx`, with formatting, styles, numbering, headers and tables left exactly as they were.
11
+ **Precise, revision-aware editing for Microsoft Word documents. Built for AI agents.**
8
12
 
9
- Built for workflows where a model proposes edits and a human reviews them in Word: every patch can land as a tracked change, with author and date, that the reviewer accepts or rejects.
13
+ docxtor gives AI agents and applications a structured interface for reading, editing, and reviewing `.docx` files.
10
14
 
11
- ## Features
15
+ Create tracked changes, add comments anchored to specific passages, resolve revisions individually, and modify document content without rewriting the entire file.
12
16
 
13
- - **Stable ids for every element.** Paragraphs, table cells, headers and footers get positional ids (`p12`, `tbl0.r1.c0.p0`) plus Word's native `w14:paraId`, so patches target exactly one place.
14
- - **Patches, not rewrites.** Replace, insert and delete text, insert and delete paragraphs, add comments, tables, rows, lists, headers and footers, apply formatting and styles. Twenty-three patch types in all.
15
- - **Tracked changes.** Turn on `trackRevisions` and every patch emits `w:ins`, `w:del`, `w:rPrChange` or `w:pPrChange` markup. Accept or reject all revisions, optionally per author.
16
- - **Projections for models.** Markdown or JSON views with ids, inline formatting markers, revision marks, page breaks and a filter for runs by colour.
17
- - **Inline formatting in patch text.** `**bold**`, `_italic_`, `~~strike~~`, `<u>underline</u>`, `{{PAGE}}` style fields, markdown tables and lists, or verbatim text when you need it.
18
- - **Atomic batches and validation.** Validate a batch before applying it, or run it all-or-nothing.
19
- - **Two runtime dependencies.** [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) and [JSZip](https://stuk.github.io/jszip/). ESM and CommonJS builds with types.
17
+ Unlike approaches that convert documents to plain text and reconstruct them, docxtor applies targeted patches directly to the underlying document XML. Formatting, styles, numbering, headers, footers, tables, and everything else outside the edited regions are preserved.
20
18
 
21
- ## Install
19
+ Works with Claude, Codex, Cursor, Gemini CLI, GitHub Copilot, and any agent that supports skills.
20
+
21
+ ## What can you do?
22
+
23
+ Ask your agent to make changes in plain language:
24
+
25
+ > Change the payment terms to net 60 days and the delivery window to ten business days. Mark both as tracked changes and save the result as a new file.
26
+
27
+ > Review the counterparty's revisions. Reject changes involving monetary amounts or dates, accept everything else, and summarize what was rejected.
28
+
29
+ > Add a comment to the liability clause asking the other party to reconsider the proposed cap.
30
+
31
+ The resulting document opens directly in Microsoft Word, with native tracked changes and comments.
32
+
33
+ ## Installation
34
+
35
+ ### AI agents
36
+
37
+ docxtor ships with a self-contained agent skill that teaches compatible agents how to inspect and edit Word documents.
38
+
39
+ **Claude Cowork / Claude.ai**
40
+
41
+ 1. Download `docxtor-skill.zip` from the [latest release](https://github.com/Eazydraft/docxtor/releases/latest).
42
+ 2. Upload it under Customize → Skills.
43
+ 3. Enable code execution.
44
+
45
+ **Codex, Cursor, Gemini CLI, GitHub Copilot, and other skill-compatible agents**
46
+
47
+ Copy the skill into your agent's skills directory:
22
48
 
23
49
  ```bash
24
- npm install @lucio-ai/docxtor
25
- # or
26
- pnpm add @lucio-ai/docxtor
50
+ git clone --depth 1 https://github.com/Eazydraft/docxtor.git /tmp/docxtor
51
+
52
+ mkdir -p ~/.agents/skills
53
+ cp -r /tmp/docxtor/plugin/skills/docxtor ~/.agents/skills/
54
+ ```
55
+
56
+ Gemini CLI also supports direct installation:
57
+
58
+ ```bash
59
+ gemini skills install https://github.com/Eazydraft/docxtor.git \
60
+ --path plugin/skills/docxtor
61
+ ```
62
+
63
+ The skill is self-contained and requires Node.js 20 or newer.
64
+
65
+ ### CLI
66
+
67
+ Install globally:
68
+
69
+ ```bash
70
+ npm install -g @lucio-ai/docxtor
27
71
  ```
28
72
 
29
- Requires Node.js 20.19 or newer.
73
+ Or run directly with npx:
74
+
75
+ ```bash
76
+ npx @lucio-ai/docxtor
77
+ ```
78
+
79
+ ## CLI
80
+
81
+ The `docxtor` CLI provides a structured interface for inspecting and modifying documents.
82
+
83
+ ```bash
84
+ # Inspect a document and find a particular clause
85
+ docxtor view contract.docx --grep "payment terms"
86
+
87
+ # Replace text using tracked changes
88
+ docxtor replace contract.docx -o redline.docx \
89
+ --author "Acme" \
90
+ --find "within thirty (30) days" \
91
+ --replace "within sixty (60) days"
92
+
93
+ # Add an anchored comment
94
+ docxtor comment contract.docx -o commented.docx \
95
+ --find "shall not exceed" \
96
+ --text "Cap is too low."
97
+
98
+ # Inspect existing revisions
99
+ docxtor revisions counterparty.docx
100
+
101
+ # Resolve selected revisions
102
+ docxtor reject counterparty.docx -o resolved.docx \
103
+ --ids 14,15 --others accept
104
+ ```
105
+
106
+ ### Command reference
107
+
108
+ | Command | Description |
109
+ |---|---|
110
+ | `view` | Inspect document contents, including paragraphs, tables, headers, footers, and inline revision markers. Supports `--grep`. |
111
+ | `revisions` | List tracked changes with their IDs, authors, and surrounding context. |
112
+ | `replace` | Find and replace text using native tracked changes. Only differing text is marked. |
113
+ | `comment` | Add a Word comment anchored to a specific passage. |
114
+ | `comments` | Inspect existing comments and their associated passages. |
115
+ | `edit` | Apply structured JSON patches to document content. |
116
+ | `accept` / `reject` | Resolve all revisions or selected revisions by ID or author. |
117
+ | `metadata` | Read or modify document properties and scrub author/company information. |
118
+
119
+ **Safety guarantees:**
120
+ - `replace` and `edit` write tracked changes by default, attributed with `--author`. Use `--untracked` to edit directly.
121
+ - `comment` adds a comment, attributed with `--author`; it changes no text.
122
+ - `accept` and `reject` resolve existing tracked changes, and `metadata` changes document properties; neither creates tracked changes.
123
+ - Failed operations do not produce partially written output.
124
+ - Ambiguous text matches are rejected unless the intended match is specified.
125
+
126
+ See the [CLI reference](docs/cli.md) for all commands and options.
127
+
128
+ ## Benchmark
129
+
130
+ We evaluated docxtor using [docx-agent-bench](https://github.com/clauseo-ai/docx-agent-bench), a benchmark of realistic document-editing tasks involving real contracts.
131
+
132
+ The benchmark compares an AI agent equipped with the docxtor skill against the same agent without a document-editing plugin.
133
+
134
+ **Evaluation setup**
135
+
136
+ - 7 short tasks, 2 runs each.
137
+ - Two models: Claude Haiku 5.5 and Claude Opus 5.5.
138
+ - Evaluation date: November 6, 2026.
139
+ - Benchmark commit: `e214567`.
140
+
141
+ Tasks covered tracked-change redlines, bulk renaming, comments, chained edits, revision resolution, multi-turn editing, and document reading.
142
+
143
+ The benchmark's document-comparison task was excluded because docxtor does not currently implement document comparison.
144
+
145
+ ### Results
146
+
147
+ | Model | Configuration | Grader-correct | Median time | Median tool calls | Median tool errors |
148
+ |---|---|---:|---:|---:|---:|
149
+ | Claude Haiku 5.5 | With docxtor | 14/14 | 17 s | 5 | 0 |
150
+ | Claude Haiku 5.5 | Without plugin | 14/14 | 30.5 s | 8.5 | 1 |
151
+ | Claude Opus 5.5 | With docxtor | 14/14 | 22 s | 5 | 0 |
152
+ | Claude Opus 5.5 | Without plugin | 13/13 | 36 s | 5 | 0 |
153
+
154
+ With docxtor, agents completed tasks approximately **40% faster**, with zero tool errors across the evaluated runs.
155
+
156
+ ## TypeScript API
30
157
 
31
- ## Quick start
158
+ docxtor is also available as a TypeScript library.
159
+
160
+ Applications can use it to expose document structure to a model, receive structured editing instructions, and apply those instructions as native Word revisions.
161
+
162
+ Install:
163
+
164
+ ```bash
165
+ npm install @lucio-ai/docxtor
166
+ ```
167
+
168
+ ### Example
32
169
 
33
170
  ```ts
34
171
  import { Docxtor } from "@lucio-ai/docxtor";
35
172
 
173
+ // Load an existing document
36
174
  const doc = await Docxtor.load("contract.docx");
37
175
 
38
- // A view the model can read. Every line carries the id patches target.
176
+ // Project the document into a model-readable representation
39
177
  console.log(doc.project("markdown"));
40
- // [p0] (Heading1) Service Agreement
41
- // [p1] This agreement is valid from January 1, 2025...
42
- // [p2] The parties agree to the following terms:
43
178
 
44
- // Apply the patches the model produced, as tracked changes.
179
+ // Apply structured patches
45
180
  const results = doc.applyPatches(
46
181
  [
47
- { type: "replace_text", target: "p1", find: "valid", replace: "enforceable" },
48
- { type: "insert_text", target: "p2", position: "after", anchor: "terms:", text: " and conditions:" },
49
- { type: "apply_formatting", target: "p1", find: "enforceable", formatting: { bold: true } },
50
- { type: "add_comment", target: "p1", find: "enforceable", text: "Confirm with counsel." },
182
+ {
183
+ type: "replace_text",
184
+ target: "p1",
185
+ find: "valid",
186
+ replace: "enforceable"
187
+ },
188
+ {
189
+ type: "insert_text",
190
+ target: "p2",
191
+ position: "after",
192
+ anchor: "terms:",
193
+ text: " and conditions:"
194
+ },
195
+ {
196
+ type: "apply_formatting",
197
+ target: "p1",
198
+ find: "enforceable",
199
+ formatting: { bold: true }
200
+ },
201
+ {
202
+ type: "add_comment",
203
+ target: "p1",
204
+ find: "enforceable",
205
+ text: "Confirm this wording."
206
+ }
51
207
  ],
52
- { trackRevisions: true, revisionAuthor: "AI Editor" },
208
+ {
209
+ trackRevisions: true,
210
+ revisionAuthor: "AI Editor"
211
+ }
53
212
  );
54
213
 
55
- for (const r of results) {
56
- if (!r.success) console.error(`Patch failed: ${r.error}`);
214
+ // Inspect individual patch results
215
+ for (const result of results) {
216
+ if (!result.success) {
217
+ console.error(`Patch failed: ${result.error}`);
218
+ }
57
219
  }
58
220
 
221
+ // Export the edited document
59
222
  await doc.toFile("contract-redline.docx");
60
223
  ```
61
224
 
62
- Open the result in Word and the edits show up as redlines from "AI Editor". Drop the options argument to apply the same patches directly.
225
+ ### Capabilities
63
226
 
64
- ## How it works
227
+ **Structured document representation**
65
228
 
66
- ```
229
+ - Stable positional IDs for paragraphs, table cells, headers, and footers.
230
+ - Access to native Word `w14:paraId` identifiers, with support for assigning them when absent.
231
+ - Markdown and JSON projections for LLM consumption.
232
+ - Inline formatting markers, revision markers, page breaks, and run filtering by colour.
233
+
234
+ **Targeted editing**
235
+
236
+ - 23 patch types covering text, paragraphs, comments, tables, rows, lists, formatting, styles, headers, and footers.
237
+ - Fine-grained text replacement that marks only the differing text.
238
+ - Native Word tracked changes, including `w:ins`, `w:del`, `w:rPrChange`, and `w:pPrChange`.
239
+ - Accept or reject all revisions, or selectively resolve them by author or ID.
240
+
241
+ **Execution guarantees**
242
+
243
+ - Atomic patch batches and validation before application.
244
+ - Structured success and failure results for individual patches.
245
+ - All-or-nothing execution when requested.
246
+ - Unmodified document content remains untouched.
247
+
248
+ **Runtime**
249
+
250
+ - Node.js 20.19 or newer.
251
+ - ESM and CommonJS builds.
252
+ - TypeScript declarations included.
253
+ - Two runtime dependencies: [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) and [JSZip](https://stuk.github.io/jszip/).
254
+
255
+ ## Architecture
256
+
257
+ docxtor is designed around a simple principle:
258
+
259
+ **Never reconstruct what you can modify in place.**
260
+
261
+ Traditional document-editing approaches often convert DOCX content into an intermediate representation and regenerate the document afterward. This can introduce unintended changes to formatting, styles, relationships, and other document structures.
262
+
263
+ docxtor takes a different approach.
264
+
265
+ ```text
67
266
  DOCX --> XML --> Normalized AST (read-only, with xmlRef pointers) --> LLM projection
68
267
  | |
69
268
  | model produces
@@ -75,40 +274,58 @@ DOCX --> XML --> Normalized AST (read-only, with xmlRef pointers) --> LLM projec
75
274
  Serialize --> DOCX
76
275
  ```
77
276
 
78
- The AST is never written back. It is a read-only lens with `xmlRef` pointers into the parsed XML. Patches follow those pointers and mutate the XML in place, and serializing the result produces the output document. Anything a patch does not touch survives untouched. See [docs/design.md](docs/design.md) for the invariants this rests on.
277
+ The normalized AST is a read-only representation of the document. Each node retains an `xmlRef` pointer to its corresponding object in the parsed XML.
79
278
 
80
- ## Benchmark
279
+ Models operate on projections of this AST and produce structured patch objects. The patch engine resolves these patches through their references and modifies the underlying XML directly.
81
280
 
82
- docxtor was run through [docx-agent-bench](https://github.com/clauseo-ai/docx-agent-bench), an agent benchmark of realistic edits to real contracts (tracked-change redlines, a bulk rename, comments, chained edits, resolving a counterparty's tracked changes, a version compare, and a reading task), graded on the `.docx` the agent writes. The agent got docxtor through a thin CLI over the library and a skill describing it; the baseline is the same agent with no document tool. Eight short tasks, two runs each, 3 November 2026, benchmark commit `e214567`.
281
+ The AST is never serialized back into the document.
83
282
 
84
- | Model | Arm | Grader-correct runs | Median wall time | Median tool calls | Median tool errors |
85
- |---|---|---|---|---|---|
86
- | Claude Haiku 5.5 | docxtor | 16/16 | 19 s | 5 | 0 |
87
- | Claude Haiku 5.5 | no tool | 16/16 | 42.5 s | 9 | 1 |
88
- | Claude Opus 5.5 | docxtor | 16/16 | 34 s | 5 | 0 |
89
- | Claude Opus 5.5 | no tool | 16/16 | 41 s | 5.5 | 0 |
90
-
91
- Every file docxtor wrote passed the benchmark's schema check with no new findings. The two tasks docxtor has no primitive for, per-revision accept/reject and document compare, were solved by the agent from the existing primitives and are where its wall time goes; the other tasks ran two to four times faster than the baseline. Word-based validity and the benchmark's long tasks were not part of this run.
283
+ This separation allows docxtor to provide a structured, model-friendly editing interface while preserving document content and structure outside the scope of an edit.
92
284
 
93
285
  ## Documentation
94
286
 
95
- - [API reference](docs/api.md): `load`, `create`, `project`, `applyPatches`, accept and reject revisions, metadata, export, low-level exports
96
- - [Patch types](docs/patches.md): every patch with its fields and behaviour
97
- - [ID scheme](docs/ids.md): positional ids and native `w14:paraId`
98
- - [Revision tracking](docs/revisions.md): what each patch emits as tracked changes, reading revision marks
99
- - [LLM integration pattern](docs/llm-integration.md): a system prompt and validate-then-apply loop
100
- - [Feature coverage](docs/coverage.md): what is handled and what is not yet
101
- - [Design](docs/design.md): architecture and invariants
102
- - [Examples](examples/): an interactive chat CLI that edits a document with a model
287
+ | Resource | Description |
288
+ |---|---|
289
+ | [CLI reference](docs/cli.md) | Commands, arguments, and options |
290
+ | [API reference](docs/api.md) | Loading, creating, projecting, patching, and exporting documents |
291
+ | [Patch types](docs/patches.md) | Complete patch reference and behaviour |
292
+ | [ID scheme](docs/ids.md) | Positional IDs and native `w14:paraId` |
293
+ | [Revision tracking](docs/revisions.md) | Tracked-change generation and revision inspection |
294
+ | [LLM integration](docs/llm-integration.md) | System prompts and validate-then-apply workflows |
295
+ | [Feature coverage](docs/coverage.md) | Supported functionality and known limitations |
296
+ | [Examples](examples/) | Interactive chat CLI demonstrating model-driven editing |
297
+
298
+ ## Current limitations
299
+
300
+ The following are not currently supported:
103
301
 
104
- ## Not handled yet
302
+ - Merged cells.
303
+ - Images.
304
+ - Creating new styles.
305
+ - Reading existing comments through the library API (the CLI supports listing comments).
306
+ - Document comparison.
307
+ - Mathematical equations.
105
308
 
106
- Merged cells, images, creating new styles, reading existing comments, document compare, and math equations. The full list is in [feature coverage](docs/coverage.md). Contributions are welcome.
309
+ See [feature coverage](docs/coverage.md) for the complete breakdown.
310
+
311
+ Contributions are welcome.
107
312
 
108
313
  ## Contributing
109
314
 
110
- See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, the invariants to keep, and the DCO sign-off every commit needs.
315
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, architectural invariants, and contribution requirements.
316
+
317
+ The CLI source lives in [`cli/`](cli/).
318
+
319
+ ```bash
320
+ # Build the npm package
321
+ pnpm build
322
+
323
+ # Rebuild the self-contained agent skill
324
+ pnpm build:skill
325
+ ```
326
+
327
+ Every commit requires DCO sign-off.
111
328
 
112
329
  ## License
113
330
 
114
- [MIT](LICENSE)
331
+ docxtor is released under the [MIT License](LICENSE).