@ansonlai/docx-redline-js 0.6.2 → 0.7.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/AGENTS.md +19 -9
- package/CHANGELOG.md +43 -0
- package/README.md +39 -6
- package/dist/docx-redline-js.esm.js +1 -1
- package/docs/AGENT_FAST_START.md +22 -24
- package/docs/AGENT_KNOWLEDGE_BASE.md +26 -14
- package/docs/SKILL_AUTHORING.md +55 -19
- package/docs/releases/0.7.0.md +199 -0
- package/docs/schemas/document-operations.schema.json +13 -0
- package/docs/validation-reports/2026-09-14-localized-patching-rollout.md +90 -0
- package/index.d.ts +2 -0
- package/node/cli-help.js +20 -2
- package/node/cli.js +259 -34
- package/package.json +5 -1
- package/services/batch-operation-orchestrator.js +25 -16
- package/services/document-operation-applier.js +68 -9
- package/services/document-operation-contract.js +56 -5
- package/services/localized-replacement-compiler.js +304 -0
- package/services/operation-batch-compiler.js +33 -1
- package/services/operation-preflight.js +10 -6
- package/services/standalone-operation-runner.d.ts +55 -3
package/AGENTS.md
CHANGED
|
@@ -21,10 +21,16 @@ specific advanced operation, API, or recovery topic you need.
|
|
|
21
21
|
|
|
22
22
|
## Ordinary document edits
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
For a literal mechanical edit with known old and new text, try one fail-closed
|
|
25
|
+
apply call. Use a visible heading plus a directional range when global matching
|
|
26
|
+
is too broad:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
docx-redline apply contract.docx --search "Section 4.1" --context-range 1:3 --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
For semantic drafting, inspect once and apply once. With a structured wrapper,
|
|
33
|
+
use revision-bound handles. For shell-only work, use serializer-backed stdin:
|
|
28
34
|
|
|
29
35
|
```bash
|
|
30
36
|
docx-redline extract contract.docx --search "termination" --around 3
|
|
@@ -39,10 +45,12 @@ Consolidate incompatible writes to the same source; use captures for intentional
|
|
|
39
45
|
created-content dependencies.
|
|
40
46
|
|
|
41
47
|
Require `completion: true`, `written: true`, a non-null output path, and no
|
|
42
|
-
per-operation errors.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
per-operation errors. Localized edits also require `change.committed: true` and
|
|
49
|
+
`change.verification.acceptedViewMatchesCompiledText: true`. Follow
|
|
50
|
+
`error.recovery.action` and `retryPlan`; never retry unchanged failed arguments.
|
|
51
|
+
Follow `selection.hint` for restorable text. Do not accept/reject another
|
|
52
|
+
reviewer's work or remove comments without explicit user authorization. The
|
|
53
|
+
source is never overwritten unless `--in-place` is explicit.
|
|
46
54
|
|
|
47
55
|
The agent profile preserves progressive execution and the ordinary revision
|
|
48
56
|
policy. Add `--atomic` or `--existing-revisions slice-cross-author` only when
|
|
@@ -64,7 +72,9 @@ targeting, revision allocation, comments, numbering, validation, or rollback.
|
|
|
64
72
|
The stateful wrapper in `examples/agent-session-wrapper.mjs` is a testable
|
|
65
73
|
development demonstration only. It is excluded from package files and exports.
|
|
66
74
|
Production harnesses own their transport and negotiate the minimum CLI
|
|
67
|
-
`contractVersion`/capabilities they use.
|
|
75
|
+
`contractVersion`/capabilities they use. The 0.7.0 localized fast path requires
|
|
76
|
+
contract 8 and its localized replacement, speculative apply, and change-summary
|
|
77
|
+
capabilities.
|
|
68
78
|
|
|
69
79
|
## Code map
|
|
70
80
|
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.7.0
|
|
6
|
+
|
|
7
|
+
### Agent Performance and Localized Editing
|
|
8
|
+
|
|
9
|
+
- **Localized exact replacements:** `redline`/`replace` operations may provide
|
|
10
|
+
`replacements: [{ find, replace, occurrence? }]` instead of a complete
|
|
11
|
+
`modified` paragraph. The compiler resolves the accepted-view source once,
|
|
12
|
+
applies non-overlapping exact replacements simultaneously, synthesizes the
|
|
13
|
+
canonical desired paragraph, and delegates to the unchanged OOXML engine.
|
|
14
|
+
- **One-turn speculative apply:** `docx-redline apply --find ... --replace ...`
|
|
15
|
+
can resolve a globally unique source literal without preliminary extraction.
|
|
16
|
+
`--search` plus signed `--context-range START:END` scopes visible headings and
|
|
17
|
+
multi-paragraph provisions; `--around N` is symmetric shorthand.
|
|
18
|
+
- **Fail-closed selection:** Missing anchors and patch sources, multiple eligible
|
|
19
|
+
paragraphs, ambiguous occurrences, overlaps, conflicts, and unsupported
|
|
20
|
+
localized shapes refuse mutation. A failed speculative command never writes
|
|
21
|
+
or truncates its output path.
|
|
22
|
+
- **Verified change evidence:** Localized operation results include a compact
|
|
23
|
+
`change` object with target location, contextual anchor/range, exact
|
|
24
|
+
replacement entries, bounded before/after excerpts, commit disposition, and
|
|
25
|
+
post-mutation accepted-view verification. Atomic rollback marks the evidence
|
|
26
|
+
non-committed and `rolled_back`.
|
|
27
|
+
- **CLI contract version 8:** Adds `localized-replacements-v1`,
|
|
28
|
+
`speculative-search-apply-v1`, and `localized-change-summary-v1`. Skills and
|
|
29
|
+
harnesses should pin version 0.7.0 and negotiate only the capabilities used.
|
|
30
|
+
- **Measured workflow reduction:** The checked benchmark records 50% fewer tool
|
|
31
|
+
turns and a 64.77%–78.98% smaller deterministic request-token proxy across
|
|
32
|
+
three literal-edit cases. Median native engine/I/O time remained effectively
|
|
33
|
+
neutral; provider reasoning and network latency were not estimated.
|
|
34
|
+
|
|
35
|
+
### Compatibility
|
|
36
|
+
|
|
37
|
+
- Existing `modified` operations, strong targets, operations files/stdin,
|
|
38
|
+
tracked-change generation, package validation, rollback, comments,
|
|
39
|
+
Accept/Reject, and revision policies remain supported.
|
|
40
|
+
- Localized replacement fields and successful `change` evidence are additive.
|
|
41
|
+
Wrappers that adopt them must require CLI contract 8; integrations using only
|
|
42
|
+
earlier capabilities can continue using their existing operation shapes.
|
|
43
|
+
- The implementation remains OOXML-only and adds no runtime dependency or Word,
|
|
44
|
+
Office automation, COM, or proprietary document API requirement.
|
|
45
|
+
|
|
46
|
+
## 0.6.0–0.6.2
|
|
47
|
+
|
|
5
48
|
### Safety Fixes
|
|
6
49
|
|
|
7
50
|
- **Foreign deleted-paragraph resurrection guard**: Refuses non-empty same-paragraph edits when another author owns the paragraph-mark deletion and all existing paragraph content is deleted. The operation now returns `FOREIGN_PARAGRAPH_MARK_DELETION` with the owning author instead of emitting lifecycle-unsafe OOXML; atomic document operations roll back byte-for-byte. `validateRedlineOoxml` reports already-authored instances as warnings.
|
package/README.md
CHANGED
|
@@ -15,9 +15,25 @@ Converts AI-generated or programmatic text/markdown edits into valid Office Open
|
|
|
15
15
|
- Comment management: delete comments by author or for all authors
|
|
16
16
|
- Highlights: apply highlight colors to runs
|
|
17
17
|
- Markdown and OOXML conversion in both directions
|
|
18
|
-
- Status/error result fields for parse, targeting, and existing-revision failures
|
|
19
|
-
-
|
|
20
|
-
-
|
|
18
|
+
- Status/error result fields for parse, targeting, and existing-revision failures
|
|
19
|
+
- Localized exact replacements and fail-closed one-turn CLI edits with verified before/after evidence
|
|
20
|
+
- Package plumbing helpers for numbering.xml, comments.xml, content types, and relationships
|
|
21
|
+
- Zero host dependencies: works in Node.js, browsers, Deno, and similar JS runtimes with DOM parsing support
|
|
22
|
+
|
|
23
|
+
## What's New in 0.7.0
|
|
24
|
+
|
|
25
|
+
Version 0.7.0 adds a contract-8 fast path for exact mechanical edits. Agents can
|
|
26
|
+
send a small `find`/`replace` request instead of reproducing a complete legal
|
|
27
|
+
paragraph, and may omit a strong target when the source literal resolves to one
|
|
28
|
+
accepted-view paragraph. Visible headings can narrow the attempt with a signed
|
|
29
|
+
directional window such as `--search "Section 4.1" --context-range 1:3`.
|
|
30
|
+
|
|
31
|
+
Speculative edits fail without writing when the anchor, paragraph, or source
|
|
32
|
+
span is missing or ambiguous. Successful localized results include a committed
|
|
33
|
+
`change` object with the selected legal location, bounded before/after excerpts,
|
|
34
|
+
and actual accepted-view verification. Existing full-paragraph operations,
|
|
35
|
+
tracked-change semantics, validation, rollback, and review policies remain
|
|
36
|
+
available unchanged. See the [complete 0.7.0 release notes](./docs/releases/0.7.0.md).
|
|
21
37
|
## Documentation Index
|
|
22
38
|
|
|
23
39
|
| Document | Description |
|
|
@@ -215,9 +231,23 @@ benchmark explicitly does not claim to measure LLM reasoning or provider/tool
|
|
|
215
231
|
latency. Checked comparative results are in the
|
|
216
232
|
[agent protocol rollout audit](./docs/validation-reports/2026-09-12-agent-protocol-rollout.md).
|
|
217
233
|
|
|
234
|
+
> **Pre-1.0 integration warning:** Agent skills, MCP servers, and harnesses
|
|
235
|
+
> should pin the exact `@ansonlai/docx-redline-js` release they were tested
|
|
236
|
+
> against and declare the CLI contract version/capabilities they require. Do
|
|
237
|
+
> not treat a newly installed release or contract as verified until the
|
|
238
|
+
> integration's compatibility tests pass. See the
|
|
239
|
+
> [skill-authoring contract](./docs/SKILL_AUTHORING.md#runtime-negotiation).
|
|
240
|
+
|
|
218
241
|
### Agent CLI
|
|
219
|
-
|
|
242
|
+
|
|
220
243
|
```bash
|
|
244
|
+
# One-turn exact mechanical edit; fails closed unless one paragraph matches
|
|
245
|
+
docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
246
|
+
|
|
247
|
+
# Directional context after a visible heading; repeated cross-references are safe
|
|
248
|
+
docx-redline apply contract.docx --search "Section 4.1" --context-range 1:3 --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
249
|
+
|
|
250
|
+
# Semantic drafting still starts with focused context
|
|
221
251
|
docx-redline extract contract.docx --search "termination" --around 3
|
|
222
252
|
docx-redline preflight contract.docx --operations operations.json --author "Editor"
|
|
223
253
|
docx-redline apply contract.docx --operations operations.json --author "Editor" --output reviewed.docx
|
|
@@ -252,6 +282,7 @@ All commands emit JSON on stdout. `apply` defaults:
|
|
|
252
282
|
- **Compact stdout**: `--compact` emits one-line mutation JSON. It changes serialization only, not operation semantics.
|
|
253
283
|
- **Tracked changes**: Defaults to `generateRedlines: true`. Pass `--no-redlines` when clean direct text edits are desired.
|
|
254
284
|
- **Inline edits**: Use `--target <text>` with `--modified <text>` or `--comment <text>` for quick one-liners without creating a JSON file.
|
|
285
|
+
- **Localized edits**: Use `--find`/`--replace` with a known strong target, or omit the target for fail-closed global resolution. Add `--search` with `--context-range 1:3` for text strictly after a visible heading; `--around 3` is symmetric. Successful localized results include bounded before/after excerpts and post-mutation accepted-view verification in `results[i].change`.
|
|
255
286
|
- **Compact mutation results**: `apply`, `accept`, `reject`, and `delete-comments` omit full OOXML/package payloads and inspection text from stdout. CLI operation results omit duplicate nested receipt bodies; the ordered top-level `receipts` array is authoritative. Successful exact target-match diagnostics are omitted and equivalent-whitespace matches retain only mode/count. Node and standalone-runner results remain unchanged. Use `validate` when full issue arrays are needed.
|
|
256
287
|
|
|
257
288
|
Inspection commands default to 20 direct matches and a 48 KiB soft response
|
|
@@ -266,12 +297,14 @@ marker. Machine `index` and `ref` fields are for targeting and pagination, not
|
|
|
266
297
|
user-facing Word locations; use `humanReference`, `provision`, or
|
|
267
298
|
`nearestHeading` in reports.
|
|
268
299
|
|
|
269
|
-
`docx-redline version` reports contract version
|
|
300
|
+
`docx-redline version` reports contract version 8 and the additive
|
|
270
301
|
`command-help-v1`, `inspection-context-v1`, `bounded-inspection-v1`,
|
|
271
302
|
`human-document-references-v1`, `batch-start-source-binding`,
|
|
272
303
|
`recovery-envelope-v1`, `require-complete-exit`, `operations-stdin`,
|
|
273
304
|
`agent-safety-profile-v2`, `deduplicated-cli-receipts`, and
|
|
274
|
-
`compact-cli-json-v1`
|
|
305
|
+
`compact-cli-json-v1`, `localized-replacements-v1`,
|
|
306
|
+
`speculative-search-apply-v1`, and `localized-change-summary-v1` capabilities.
|
|
307
|
+
Wrappers should negotiate only the
|
|
275
308
|
capabilities they use. Run `docx-redline <command> --help` for that command's
|
|
276
309
|
machine-readable options, behavior, exit codes, canonical GitHub documentation links, and compact examples.
|
|
277
310
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @ansonlai/docx-redline-js v0.
|
|
1
|
+
// @ansonlai/docx-redline-js v0.7.0 — https://github.com/AnsonLai/docx-redline-js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
package/docs/AGENT_FAST_START.md
CHANGED
|
@@ -7,53 +7,51 @@ Use this page for ordinary `.docx` edits. For source changes or unusual Word str
|
|
|
7
7
|
If your host provides a document-session wrapper:
|
|
8
8
|
|
|
9
9
|
1. Inspect/search once with enough surrounding context to draft the change.
|
|
10
|
-
2. Apply
|
|
11
|
-
|
|
12
|
-
3. Treat only `ok: true` as complete. A failed handle must be refreshed by
|
|
13
|
-
inspection; never reuse it against a changed document.
|
|
10
|
+
2. Apply with the revision-bound handle and complete desired text or exact replacements.
|
|
11
|
+
3. Treat only `ok: true` as complete; refresh failed handles before reuse.
|
|
14
12
|
|
|
15
13
|
The repository's `examples/agent-session-wrapper.mjs` demonstrates this pattern.
|
|
16
14
|
It is a development sample, not a package API.
|
|
17
15
|
|
|
18
16
|
## CLI fallback
|
|
19
17
|
|
|
20
|
-
1.
|
|
18
|
+
1. For a literal mechanical edit with known old and new text, try one-turn apply:
|
|
21
19
|
|
|
22
20
|
```bash
|
|
23
|
-
docx-redline
|
|
21
|
+
docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
The source must occur in one eligible paragraph. For text after a heading, add `--search "Section 4.1" --context-range 1:3`.
|
|
25
|
+
`--around 3` is symmetric; use it only when either side is eligible.
|
|
26
|
+
|
|
27
|
+
2. For semantic drafting such as “make this provision mutual,” extract enough
|
|
28
|
+
context, then copy `exactText` with `paragraphId` or `fingerprint`:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
docx-redline extract contract.docx --search "termination" --around 3
|
|
32
|
+
```
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
file or serializer-backed stdin, then apply once:
|
|
34
|
+
Search is case-insensitive; follow `selection.hint` and `selection.nextAfter`, and report `humanReference`. Apply once with a UTF-8 operations file or serializer-backed stdin:
|
|
30
35
|
|
|
31
36
|
```bash
|
|
32
37
|
node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
`
|
|
36
|
-
text through shell quoting. `modified` is the complete desired accepted-view
|
|
37
|
-
paragraph, not only the inserted words.
|
|
40
|
+
Use `JSON.stringify`, not shell interpolation. `modified` is the complete desired accepted-view paragraph.
|
|
38
41
|
|
|
39
42
|
The `agent` profile preserves progressive execution and the ordinary revision policy while making incomplete work exit nonzero. Add `--atomic` deliberately; check `effectiveOptions`. Run `docx-redline apply --help` for redline, comment, and rejected-view restore shapes.
|
|
40
43
|
|
|
41
44
|
## Batch and result rules
|
|
42
45
|
|
|
43
|
-
- Strong inspected targets
|
|
44
|
-
|
|
45
|
-
- Consolidate multiple desired texts for the same source paragraph. Follow an
|
|
46
|
-
explicit capture dependency for non-unique content created earlier in a batch.
|
|
46
|
+
- Strong inspected targets bind to the batch start; independent edits need no bottom-up sorting.
|
|
47
|
+
- Consolidate writes to one source; use captures for created-content dependencies.
|
|
47
48
|
- Require `completion: true`, `written: true`, a non-null `outputPath`, and no
|
|
48
|
-
per-operation error.
|
|
49
|
-
|
|
49
|
+
per-operation error. For localized edits also require `change.committed: true`
|
|
50
|
+
and `change.verification.acceptedViewMatchesCompiledText: true`. The source is
|
|
51
|
+
not overwritten unless `--in-place` is explicit.
|
|
50
52
|
- On failure, follow `error.recovery.action`. Never retry unchanged arguments.
|
|
51
|
-
- `retryPlan.base: "original"` means
|
|
52
|
-
|
|
53
|
-
reported failed or unattempted indexes.
|
|
54
|
-
- Never accept/reject revisions or remove comments without user authorization.
|
|
55
|
-
`slice-cross-author` is the history-preserving option for a surgical edit
|
|
56
|
-
inside another reviewer's pending insertion.
|
|
53
|
+
- `retryPlan.base: "original"` means replay the batch; `"output"` means retain committed work and retry reported indexes.
|
|
54
|
+
- Never accept/reject revisions or remove comments without user authorization. `slice-cross-author` preserves history for edits inside foreign insertions.
|
|
57
55
|
|
|
58
56
|
Advanced operations and recovery: [Agent Knowledge Base](AGENT_KNOWLEDGE_BASE.md); canonical contract: [document-operations.schema.json](schemas/document-operations.schema.json)
|
|
59
57
|
Wrapper design: [README](../README.md#example-agent-session-wrapper-development-only)
|
|
@@ -482,20 +482,26 @@ Use this for everything by default. `apply` is fast, progressive, and self-valid
|
|
|
482
482
|
|
|
483
483
|
The short route for a document-editing request is:
|
|
484
484
|
|
|
485
|
-
1.
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
485
|
+
1. For an exact mechanical change with known old and new literals, use localized
|
|
486
|
+
`--find`/`--replace`. Omit the target for global fail-closed resolution, or
|
|
487
|
+
scope a visible heading with `--search` and a directional range such as
|
|
488
|
+
`--context-range 1:3`. Repeated anchor matches are unioned; one eligible patch
|
|
489
|
+
paragraph is still required. `--occurrence` selects only within that paragraph.
|
|
490
|
+
2. For semantic drafting, run one focused `extract`. Add `--around 3` when
|
|
491
|
+
surrounding context on either side is needed, then copy `exactText` plus
|
|
492
|
+
`paragraphId` or `fingerprint`.
|
|
493
|
+
3. Build the final operations from the operation table above. Use one operation
|
|
489
494
|
per target paragraph, and consolidate multiple changes to that paragraph.
|
|
490
|
-
|
|
495
|
+
4. Run `apply` once per stable batch. Strong inspected targets are bound against
|
|
491
496
|
the batch-start document, so independent operations do not need manual
|
|
492
497
|
bottom-up sorting around structural edits. Consolidate multiple complete
|
|
493
498
|
desired states for the same source. A unique exact reference to paragraph
|
|
494
499
|
text created elsewhere in the batch is scheduled automatically; use explicit
|
|
495
500
|
captures/selectors for non-unique or advanced created-content dependencies.
|
|
496
|
-
|
|
497
|
-
per-operation error.
|
|
498
|
-
|
|
501
|
+
5. Walk every result and require `completion: true`, `written: true`, and no
|
|
502
|
+
per-operation error. For localized patches also require committed `change`
|
|
503
|
+
evidence and positive accepted-view verification.
|
|
504
|
+
6. Run a focused `extract` on changed clauses only when placement or list/table
|
|
499
505
|
structure needs confirmation.
|
|
500
506
|
|
|
501
507
|
Do not probe operation behavior with disposable apply commands or read a vendor
|
|
@@ -503,22 +509,28 @@ bundle before this route. If `apply` returns an error, use the recovery matrix
|
|
|
503
509
|
below and make one cause-specific correction.
|
|
504
510
|
|
|
505
511
|
```bash
|
|
506
|
-
# 1.
|
|
512
|
+
# 1. Globally unique mechanical edit in one call
|
|
513
|
+
docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
514
|
+
|
|
515
|
+
# 2. Mechanical edit strictly within three paragraphs after a visible heading
|
|
516
|
+
docx-redline apply contract.docx --search "Section 4.1" --context-range 1:3 --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
517
|
+
|
|
518
|
+
# 3. Focused contextual discovery for semantic drafting
|
|
507
519
|
docx-redline extract contract.docx --search "termination" --around 3
|
|
508
520
|
|
|
509
|
-
#
|
|
521
|
+
# 4. Inline complete-paragraph edit
|
|
510
522
|
docx-redline apply contract.docx --target "Original clause" --modified "New clause" --output reviewed.docx
|
|
511
523
|
|
|
512
|
-
#
|
|
524
|
+
# 5. Direct edit without tracked changes (clean text, no revision clutter)
|
|
513
525
|
docx-redline apply contract.docx --target "Typo fix" --modified "Fixed typo" --no-redlines --output clean.docx
|
|
514
526
|
|
|
515
|
-
#
|
|
527
|
+
# 6. Cross-author edit inside another reviewer's pending insertion
|
|
516
528
|
docx-redline apply contract.docx --target "Pending clause text" --modified "Updated clause text" --existing-revisions slice-cross-author --output reviewed.docx
|
|
517
529
|
|
|
518
|
-
#
|
|
530
|
+
# 7. Batch operations with ops.json
|
|
519
531
|
docx-redline apply contract.docx --operations operations.json --output reviewed.docx
|
|
520
532
|
|
|
521
|
-
#
|
|
533
|
+
# 8. Serializer-backed stdin with compact stdout
|
|
522
534
|
node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
|
|
523
535
|
```
|
|
524
536
|
|
package/docs/SKILL_AUTHORING.md
CHANGED
|
@@ -4,6 +4,31 @@ Use this page when creating or updating an agent skill, MCP server, or custom
|
|
|
4
4
|
harness for `@ansonlai/docx-redline-js`. Ordinary document-editing agents should
|
|
5
5
|
load [Agent Fast Start](AGENT_FAST_START.md), not this design contract.
|
|
6
6
|
|
|
7
|
+
> [!WARNING]
|
|
8
|
+
> Before 1.0, every skill or harness must identify and pin its exact tested
|
|
9
|
+
> library release and required CLI contract/capabilities. Treat any different
|
|
10
|
+
> release or contract as unverified until compatibility tests pass.
|
|
11
|
+
|
|
12
|
+
For example, an integration authored for the current contract-8 release should
|
|
13
|
+
record a compatibility declaration equivalent to:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"testedLibraryRelease": "0.7.0",
|
|
18
|
+
"requiredCliContractVersion": 8,
|
|
19
|
+
"requiredCapabilities": [
|
|
20
|
+
"command-help-v1",
|
|
21
|
+
"recovery-envelope-v1",
|
|
22
|
+
"localized-replacements-v1",
|
|
23
|
+
"speculative-search-apply-v1",
|
|
24
|
+
"localized-change-summary-v1"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The package pin anchors the release; runtime negotiation proves the executable
|
|
30
|
+
exposes the required contract. A new release cannot inherit an old claim.
|
|
31
|
+
|
|
7
32
|
## Runtime negotiation
|
|
8
33
|
|
|
9
34
|
Run this before the first document operation when the skill vendors or invokes
|
|
@@ -13,14 +38,11 @@ the CLI:
|
|
|
13
38
|
docx-redline version
|
|
14
39
|
```
|
|
15
40
|
|
|
16
|
-
Require contract version
|
|
17
|
-
typical shell skill should require
|
|
18
|
-
`bounded-inspection-v1`, `human-document-references-v1`,
|
|
41
|
+
Require contract version 8 (the currently declared contract) and only the
|
|
42
|
+
capabilities the integration uses. A typical shell skill should require
|
|
19
43
|
`agent-safety-profile-v2`, `deduplicated-cli-receipts`, and
|
|
20
|
-
`recovery-envelope-v1`. Require
|
|
21
|
-
when
|
|
22
|
-
a required capability is absent. Never inspect `dist/`, minified source, or ZIP
|
|
23
|
-
parts to compensate for a stale runtime.
|
|
44
|
+
`recovery-envelope-v1`. Require other capabilities only when used. Fail closed
|
|
45
|
+
when one is absent; never inspect bundles or ZIP parts as a fallback.
|
|
24
46
|
|
|
25
47
|
## Safety invariants
|
|
26
48
|
|
|
@@ -52,14 +74,6 @@ Choose and document these separately from safety invariants:
|
|
|
52
74
|
| Reviewer identity | flag, operation author, environment, or fallback | `AI Redliner` is a valid visible fallback. `DOCX_REDLINE_AUTHOR` is an optional harness preference, not a guard. |
|
|
53
75
|
| Output naming | derived sibling or explicit destination | Keep source immutability unless in-place mutation is deliberately authorized. |
|
|
54
76
|
|
|
55
|
-
Examples of valid profile composition:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
docx-redline apply input.docx --operations operations.json --profile agent --output reviewed.docx
|
|
59
|
-
docx-redline apply input.docx --operations operations.json --profile agent --atomic --output reviewed.docx
|
|
60
|
-
docx-redline apply input.docx --operations operations.json --profile agent --existing-revisions slice-cross-author --output reviewed.docx
|
|
61
|
-
```
|
|
62
|
-
|
|
63
77
|
Check `effectiveOptions` rather than assuming the resolved transaction,
|
|
64
78
|
revision, author, or redline policy.
|
|
65
79
|
|
|
@@ -80,11 +94,26 @@ return the full structured result rather than recreating the CLI serializer.
|
|
|
80
94
|
|
|
81
95
|
## Ordinary generated workflow
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
For an exact mechanical edit whose existing and replacement literals are known,
|
|
98
|
+
the first executable example should use the one-turn fast path:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
docx-redline apply input.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If the literal is not globally unique, scope it with a meaningful visible
|
|
105
|
+
anchor. A heading followed by a multi-paragraph provision should use a
|
|
106
|
+
directional window such as `--search "Section 4.1" --context-range 1:3`;
|
|
107
|
+
`--around 3` is symmetric and should be used only when either side is eligible.
|
|
108
|
+
Require the returned localized `change` evidence, including `committed: true`
|
|
109
|
+
and `verification.acceptedViewMatchesCompiledText: true`.
|
|
110
|
+
|
|
111
|
+
Semantic requests such as “make this provision mutual” still begin with focused
|
|
112
|
+
contextual extraction because the agent must identify and draft the complete
|
|
113
|
+
legal change:
|
|
85
114
|
|
|
86
115
|
```bash
|
|
87
|
-
docx-redline extract input.docx --search "
|
|
116
|
+
docx-redline extract input.docx --search "termination" --around 3
|
|
88
117
|
```
|
|
89
118
|
|
|
90
119
|
Use `selection.nextAfter` with `--after` when truncated. When a search for
|
|
@@ -119,8 +148,15 @@ an exact machine target with a human-facing reference.
|
|
|
119
148
|
|
|
120
149
|
## Generation checklist
|
|
121
150
|
|
|
151
|
+
- The exact tested library release is recorded and pinned; floating installs
|
|
152
|
+
are rejected while the library remains before 1.0.
|
|
153
|
+
- The required CLI contract version and minimum capability set are declared,
|
|
154
|
+
checked at runtime, and updated only after compatibility tests pass.
|
|
122
155
|
- Runtime version and required capabilities are checked once.
|
|
123
|
-
-
|
|
156
|
+
- Literal edits use localized replacements and one-turn speculative apply;
|
|
157
|
+
semantic drafting starts with focused extraction.
|
|
158
|
+
- Successful localized edits require committed, post-mutation `change`
|
|
159
|
+
verification before completion is reported.
|
|
124
160
|
- Safety invariants are not mixed with transaction or revision-policy choices.
|
|
125
161
|
- Operations-file and stdin examples use structured serialization.
|
|
126
162
|
- The four-field recovery contract precedes any diagnostic commentary.
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
## @ansonlai/docx-redline-js v0.7.0
|
|
2
|
+
|
|
3
|
+
Version 0.7.0 targets the remaining latency in AI-driven document editing: tool
|
|
4
|
+
turns and generated paragraph text. It adds exact localized replacements,
|
|
5
|
+
fail-closed one-turn apply, directional provision scoping, and compact verified
|
|
6
|
+
change evidence while retaining the existing OOXML mutation pipeline.
|
|
7
|
+
|
|
8
|
+
The engine remains OOXML-only and host-independent. This release adds no runtime
|
|
9
|
+
dependency and does not require Microsoft Word, Office automation, COM, or a
|
|
10
|
+
proprietary document API. Existing reconciliation, tracked-change generation,
|
|
11
|
+
package validation, rollback, comment preservation, and Accept/Reject semantics
|
|
12
|
+
remain authoritative.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
### Breaking Changes & Migration
|
|
17
|
+
|
|
18
|
+
- **CLI contract version 8:** Wrappers using the new fast path should require
|
|
19
|
+
`localized-replacements-v1`, `speculative-search-apply-v1`, and
|
|
20
|
+
`localized-change-summary-v1`. Negotiate only the capabilities actually used.
|
|
21
|
+
- **Pre-1.0 integration pinning:** Skills, MCP servers, and harnesses should pin
|
|
22
|
+
the exact `0.7.0` package release they tested and declare contract 8 plus their
|
|
23
|
+
minimum capability set. Treat another release or contract as unverified until
|
|
24
|
+
compatibility tests pass.
|
|
25
|
+
- **No operation-shape removal:** Existing operations with complete `modified`
|
|
26
|
+
content continue to work. Localized replacements and `change` results are
|
|
27
|
+
additive; consumers ignoring unknown result fields remain compatible.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### 1. Localized Exact Replacements
|
|
32
|
+
|
|
33
|
+
A text operation can now provide exact replacement instructions instead of
|
|
34
|
+
reproducing the complete paragraph:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"type": "redline",
|
|
39
|
+
"target": { "paragraphId": "1A2B3C4D" },
|
|
40
|
+
"replacements": [
|
|
41
|
+
{
|
|
42
|
+
"find": "thirty (30) days",
|
|
43
|
+
"replace": "sixty (60) days"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The compiler resolves the source paragraph against the immutable batch-start
|
|
50
|
+
accepted view, applies non-overlapping patches simultaneously, synthesizes the
|
|
51
|
+
complete desired text, and passes it through the ordinary reconciliation,
|
|
52
|
+
validation, receipt, and rollback pipeline.
|
|
53
|
+
|
|
54
|
+
V1 is deliberately narrow:
|
|
55
|
+
|
|
56
|
+
- one accepted-view paragraph;
|
|
57
|
+
- exact, case-sensitive source matching;
|
|
58
|
+
- optional positive, 1-based `occurrence` within that paragraph;
|
|
59
|
+
- an empty `replace` may delete a span;
|
|
60
|
+
- ambiguous, missing, no-op, overlapping, or conflicting patches fail before
|
|
61
|
+
mutation; and
|
|
62
|
+
- captures, rejected-view mutation, created-content dependencies, and
|
|
63
|
+
cross-paragraph patches remain outside localized-replacement v1.
|
|
64
|
+
|
|
65
|
+
### 2. One-Turn Speculative Apply
|
|
66
|
+
|
|
67
|
+
Globally unique literal edits no longer require preliminary extraction:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For a heading followed by a multi-paragraph provision, use a visible text anchor
|
|
74
|
+
and directional paragraph scope:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
docx-redline apply contract.docx --search "Section 4.1" --context-range 1:3 --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`1:3` means strictly the next three physical paragraphs, excluding the heading
|
|
81
|
+
and preceding paragraphs. Other supported forms include `0:0`, `0:3`,
|
|
82
|
+
`-3:-1`, and `-3:3`; offsets are inclusive, bounded to `-20..20`, and clamped at
|
|
83
|
+
document boundaries. `--around 3` is shorthand for `-3:3`.
|
|
84
|
+
|
|
85
|
+
Every matching search anchor contributes a window. The library unions and
|
|
86
|
+
deduplicates those windows, then requires exactly one eligible paragraph to
|
|
87
|
+
contain the exact `find` literal. Thus a visible section number may appear both
|
|
88
|
+
as a heading and in cross-references without the anchor itself deciding what is
|
|
89
|
+
edited. `--occurrence` may disambiguate only inside the uniquely selected
|
|
90
|
+
paragraph; it never chooses between paragraphs.
|
|
91
|
+
|
|
92
|
+
### 3. Refusal Without Output Damage
|
|
93
|
+
|
|
94
|
+
Speculation remains conservative:
|
|
95
|
+
|
|
96
|
+
- no contextual anchor returns `TARGET_NOT_FOUND`;
|
|
97
|
+
- no exact patch source returns `PATCH_SOURCE_NOT_FOUND`;
|
|
98
|
+
- multiple eligible paragraphs return `AMBIGUOUS_TARGET`;
|
|
99
|
+
- multiple source spans within one paragraph return
|
|
100
|
+
`AMBIGUOUS_PATCH_SOURCE`; and
|
|
101
|
+
- invalid ranges and mixed targeting forms return a request error.
|
|
102
|
+
|
|
103
|
+
These failures include machine recovery metadata and bounded candidates. They
|
|
104
|
+
occur before output writing, so an existing destination is not truncated or
|
|
105
|
+
overwritten. The source remains immutable unless `--in-place` is explicit.
|
|
106
|
+
|
|
107
|
+
### 4. Explicit Post-Mutation Change Evidence
|
|
108
|
+
|
|
109
|
+
Successful localized operations return a compact evidence object:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"change": {
|
|
114
|
+
"kind": "localized_replacement",
|
|
115
|
+
"committed": true,
|
|
116
|
+
"finalDisposition": "applied",
|
|
117
|
+
"target": {
|
|
118
|
+
"paragraphId": "1A2B3C4D",
|
|
119
|
+
"humanReference": "Section 4.1 — Termination"
|
|
120
|
+
},
|
|
121
|
+
"context": {
|
|
122
|
+
"search": "Section 4.1",
|
|
123
|
+
"range": "1:3",
|
|
124
|
+
"anchorMatchCount": 2
|
|
125
|
+
},
|
|
126
|
+
"replacements": [
|
|
127
|
+
{
|
|
128
|
+
"find": "thirty (30) days",
|
|
129
|
+
"replace": "sixty (60) days",
|
|
130
|
+
"beforeExcerpt": "...thirty (30) days...",
|
|
131
|
+
"afterExcerpt": "...sixty (60) days..."
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"verification": {
|
|
135
|
+
"acceptedViewMatchesCompiledText": true
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Evidence is derived from the resolved source and actual post-mutation accepted
|
|
142
|
+
view rather than simply echoing the request. Excerpts are deterministically
|
|
143
|
+
bounded to 120 characters. Agent completion additionally requires committed,
|
|
144
|
+
applied evidence and positive accepted-view verification. Atomic rollback marks
|
|
145
|
+
previously attempted evidence `committed: false` and `rolled_back`.
|
|
146
|
+
|
|
147
|
+
### 5. Agent Guidance and Development Wrapper
|
|
148
|
+
|
|
149
|
+
- Agent Fast Start, the repository launch card, Skill Authoring Contract,
|
|
150
|
+
README, CLI help, and the advanced knowledge base now distinguish exact
|
|
151
|
+
mechanical edits from semantic drafting.
|
|
152
|
+
- Literal names, dates, numbers, defined terms, and isolated phrase changes can
|
|
153
|
+
use localized one-turn apply. Semantic requests such as “make this provision
|
|
154
|
+
mutual” still begin with focused extraction and drafting.
|
|
155
|
+
- The skill-authoring contract warns pre-1.0 integrations to pin the exact
|
|
156
|
+
package release and required CLI contract/capabilities.
|
|
157
|
+
- `examples/agent-session-wrapper.mjs` remains a development-only illustration,
|
|
158
|
+
not a package export or alternate mutation engine.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### Performance Results
|
|
163
|
+
|
|
164
|
+
The controlled `npm run benchmark:localized` comparison uses the same runtime
|
|
165
|
+
for both paths, with 3 warmups and 11 measured iterations per case:
|
|
166
|
+
|
|
167
|
+
- tool turns fell from 2 to 1 (**50% reduction**);
|
|
168
|
+
- generated request bytes fell **65.06%–79.39%**;
|
|
169
|
+
- the deterministic request-token proxy fell **64.77%–78.98%**; and
|
|
170
|
+
- median native engine/I/O time ranged from **0.58% slower to 5.41% faster**,
|
|
171
|
+
confirming that the intended savings are primarily outside the OOXML engine.
|
|
172
|
+
|
|
173
|
+
The token proxy is `ceil(UTF-8 request bytes / 4)`, not a provider tokenizer or
|
|
174
|
+
billed-token measurement. Provider reasoning, streaming, network, and full
|
|
175
|
+
Claude/OpenCode wall time were not estimated. See the
|
|
176
|
+
[localized rollout audit](../validation-reports/2026-09-14-localized-patching-rollout.md).
|
|
177
|
+
|
|
178
|
+
### Verification
|
|
179
|
+
|
|
180
|
+
- `npm test`: **113 passed, 0 failed**
|
|
181
|
+
- `npm run check:types`: declarations verified for **123 runtime exports**
|
|
182
|
+
- `npm run test:isolation`: dependency and Word-API isolation passed
|
|
183
|
+
- Focused CLI/compiler/test/benchmark lint: passed
|
|
184
|
+
- Package dry run: compiler and published guidance included; development-only
|
|
185
|
+
benchmark and wrapper excluded
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### Installation
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npm install @ansonlai/docx-redline-js@0.7.0
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
CDN (ESM):
|
|
196
|
+
|
|
197
|
+
```html
|
|
198
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@ansonlai/docx-redline-js@0.7.0/dist/docx-redline-js.esm.min.js"></script>
|
|
199
|
+
```
|