@lucio-ai/docxtor 0.4.1 → 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 +272 -55
- package/dist/cli.mjs +89 -0
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +13 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +13 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -8
- package/logo.png +0 -0
package/README.md
CHANGED
|
@@ -1,69 +1,268 @@
|
|
|
1
|
-
<
|
|
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
|
[](https://www.npmjs.com/package/@lucio-ai/docxtor)
|
|
4
8
|
[](https://github.com/Eazydraft/docxtor/actions/workflows/ci.yml)
|
|
5
9
|
[](LICENSE)
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
**Precise, revision-aware editing for Microsoft Word documents. Built for AI agents.**
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
docxtor gives AI agents and applications a structured interface for reading, editing, and reviewing `.docx` files.
|
|
10
14
|
|
|
11
|
-
|
|
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
|
-
|
|
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 content edit emits `w:ins`, `w:del`, `w:rPrChange` or `w:pPrChange` markup; comments and header or footer removal are the exceptions, since Word does not track them. 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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
|
179
|
+
// Apply structured patches
|
|
45
180
|
const results = doc.applyPatches(
|
|
46
181
|
[
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
{
|
|
208
|
+
{
|
|
209
|
+
trackRevisions: true,
|
|
210
|
+
revisionAuthor: "AI Editor"
|
|
211
|
+
}
|
|
53
212
|
);
|
|
54
213
|
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
225
|
+
### Capabilities
|
|
63
226
|
|
|
64
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
281
|
+
The AST is never serialized back into the document.
|
|
83
282
|
|
|
84
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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).
|