@ansonlai/docx-redline-js 0.7.0 → 0.7.2
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 +22 -27
- package/CHANGELOG.md +21 -1
- package/README.md +43 -22
- package/dist/docx-redline-js.esm.js +3 -4
- package/dist/docx-redline-js.esm.js.map +2 -2
- package/dist/docx-redline-js.esm.min.js +51 -51
- package/dist/docx-redline-js.esm.min.js.map +2 -2
- package/docs/AGENT_FAST_START.md +31 -33
- package/docs/AGENT_KNOWLEDGE_BASE.md +67 -55
- package/docs/SKILL_AUTHORING.md +82 -100
- package/docs/releases/0.7.0.md +56 -36
- package/docs/schemas/document-operations.schema.json +1 -1
- package/docs/validation-reports/2026-09-14-agent-surface-simplification.md +75 -0
- package/node/cli-help.js +8 -6
- package/node/cli.js +57 -9
- package/package.json +4 -1
- package/services/document-inspection.js +2 -3
- package/services/document-operation-applier.js +12 -2
- package/services/document-operation-contract.js +49 -2
- package/services/document-operation-mutations.js +36 -36
- package/services/localized-replacement-compiler.js +73 -7
- package/services/operation-batch-compiler.js +9 -0
- package/services/standalone-operation-runner.d.ts +25 -4
package/AGENTS.md
CHANGED
|
@@ -21,43 +21,39 @@ specific advanced operation, API, or recovery topic you need.
|
|
|
21
21
|
|
|
22
22
|
## Ordinary document edits
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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:
|
|
24
|
+
Use one focused extraction and one apply call. With a structured wrapper, use
|
|
25
|
+
its revision-bound target handles. For shell-only work, use serializer-backed
|
|
26
|
+
stdin and the explicit agent profile:
|
|
34
27
|
|
|
35
28
|
```bash
|
|
36
29
|
docx-redline extract contract.docx --search "termination" --around 3
|
|
37
30
|
node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
|
|
38
31
|
```
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
created-content dependencies.
|
|
33
|
+
Retain inspected `exactText` for drafting and target with its compact
|
|
34
|
+
`paragraphId` plus `fingerprint`. Use complete `modified` text for a broad
|
|
35
|
+
semantic revision; for a small literal change, use `replacements` so the apply
|
|
36
|
+
payload need not repeat the whole paragraph. Independent strong targets bind to the batch start, so do
|
|
37
|
+
not manually sort around structural edits. Consolidate incompatible writes to
|
|
38
|
+
one source; use captures only for intentional created-content dependencies.
|
|
39
|
+
|
|
40
|
+
If the user requests restoration, search `--view rejected` directly. Otherwise
|
|
41
|
+
follow `selection.hint` if extraction identifies an alternate revision view.
|
|
42
|
+
Restore only the inspected strong target; do not infer adjacent content.
|
|
46
43
|
|
|
47
|
-
Require `completion: true
|
|
48
|
-
per-operation errors. Localized edits also require `change.committed: true` and
|
|
49
|
-
`change.verification.acceptedViewMatchesCompiledText: true`. Follow
|
|
44
|
+
Require `completion: true` and a non-null output path. Follow
|
|
50
45
|
`error.recovery.action` and `retryPlan`; never retry unchanged failed arguments.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
Do not accept/reject another reviewer's work or remove comments without explicit
|
|
47
|
+
user authorization. The source is never overwritten unless `--in-place` is
|
|
48
|
+
explicit.
|
|
54
49
|
|
|
55
50
|
The agent profile preserves progressive execution and the ordinary revision
|
|
56
51
|
policy. Add `--atomic` or `--existing-revisions slice-cross-author` only when
|
|
57
52
|
that policy is intended, and confirm the resolved `effectiveOptions`.
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
revision policies, and failure
|
|
54
|
+
Speculative apply, directional search ranges, advanced restore, rejected-view
|
|
55
|
+
insertion, list, table, formatting, comments, revision policies, and failure
|
|
56
|
+
examples live in the
|
|
61
57
|
[knowledge base](docs/AGENT_KNOWLEDGE_BASE.md#agent-document-workflow-cli) and
|
|
62
58
|
[operation schema](docs/schemas/document-operations.schema.json).
|
|
63
59
|
|
|
@@ -72,9 +68,8 @@ targeting, revision allocation, comments, numbering, validation, or rollback.
|
|
|
72
68
|
The stateful wrapper in `examples/agent-session-wrapper.mjs` is a testable
|
|
73
69
|
development demonstration only. It is excluded from package files and exports.
|
|
74
70
|
Production harnesses own their transport and negotiate the minimum CLI
|
|
75
|
-
`contractVersion
|
|
76
|
-
|
|
77
|
-
capabilities.
|
|
71
|
+
`contractVersion` and capabilities they actually use. Optional capabilities do
|
|
72
|
+
not belong in an ordinary editing prompt merely because the CLI supports them.
|
|
78
73
|
|
|
79
74
|
## Code map
|
|
80
75
|
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Localized replacement matching now tries exact case-sensitive text first,
|
|
6
|
+
then a narrow ASCII-space/non-breaking-space equivalent match. Ambiguous
|
|
7
|
+
equivalent matches still fail closed, and unchanged boundary NBSPs are
|
|
8
|
+
retained to avoid incidental whitespace redlines.
|
|
9
|
+
|
|
10
|
+
- Added a narrow single-paragraph restore shortcut. A restore with a strong
|
|
11
|
+
rejected-view target may omit `modified` for verbatim restoration or provide
|
|
12
|
+
exact `replacements`; the CLI exposes the same path through `apply --restore
|
|
13
|
+
--target-id ID`. Ranges, captures, weak targets, and inferred companion
|
|
14
|
+
content remain excluded.
|
|
15
|
+
|
|
16
|
+
- Fixed rejected-view restore receipts so `resolvedTarget` text, fingerprint,
|
|
17
|
+
revision view, and match diagnostics describe the view actually used to
|
|
18
|
+
resolve the target.
|
|
19
|
+
- Fixed alternate-view search hints to honor `--revised`, `--table`, and
|
|
20
|
+
`--body`, and retained compact revision authors plus `deleted`/`inserted` cues
|
|
21
|
+
in `extract` output so empty revision-view paragraphs are self-explanatory.
|
|
22
|
+
|
|
5
23
|
## 0.7.0
|
|
6
24
|
|
|
7
25
|
### Agent Performance and Localized Editing
|
|
@@ -14,7 +32,9 @@
|
|
|
14
32
|
- **One-turn speculative apply:** `docx-redline apply --find ... --replace ...`
|
|
15
33
|
can resolve a globally unique source literal without preliminary extraction.
|
|
16
34
|
`--search` plus signed `--context-range START:END` scopes visible headings and
|
|
17
|
-
|
|
35
|
+
nearby content; `--around N` is symmetric shorthand. Longer, distinctive
|
|
36
|
+
anchors are recommended because generic or repeated phrases widen the unioned
|
|
37
|
+
scope and may cost an ambiguity-recovery turn.
|
|
18
38
|
- **Fail-closed selection:** Missing anchors and patch sources, multiple eligible
|
|
19
39
|
paragraphs, ambiguous occurrences, overlaps, conflicts, and unsupported
|
|
20
40
|
localized shapes refuse mutation. A failed speculative command never writes
|
package/README.md
CHANGED
|
@@ -16,17 +16,16 @@ Converts AI-generated or programmatic text/markdown edits into valid Office Open
|
|
|
16
16
|
- Highlights: apply highlight colors to runs
|
|
17
17
|
- Markdown and OOXML conversion in both directions
|
|
18
18
|
- Status/error result fields for parse, targeting, and existing-revision failures
|
|
19
|
-
- Localized exact replacements
|
|
19
|
+
- Localized exact replacements against inspected targets, plus optional fail-closed speculative CLI edits
|
|
20
20
|
- Package plumbing helpers for numbering.xml, comments.xml, content types, and relationships
|
|
21
21
|
- Zero host dependencies: works in Node.js, browsers, Deno, and similar JS runtimes with DOM parsing support
|
|
22
22
|
|
|
23
23
|
## What's New in 0.7.0
|
|
24
24
|
|
|
25
|
-
Version 0.7.0 adds
|
|
26
|
-
|
|
27
|
-
paragraph
|
|
28
|
-
|
|
29
|
-
directional window such as `--search "Section 4.1" --context-range 1:3`.
|
|
25
|
+
Version 0.7.0 adds contract-8 localized edits. Agents can send a small
|
|
26
|
+
`find`/`replace` request against an inspected target instead of reproducing a
|
|
27
|
+
complete paragraph. An optional speculative form may omit the strong target
|
|
28
|
+
when the source literal resolves uniquely; advanced scoping is described below.
|
|
30
29
|
|
|
31
30
|
Speculative edits fail without writing when the anchor, paragraph, or source
|
|
32
31
|
span is missing or ambiguous. Successful localized results include a committed
|
|
@@ -167,6 +166,13 @@ limit output. Search is a case-insensitive substring match; `around` adds nearby
|
|
|
167
166
|
context, while `limit` and `after` page direct hits. When a search yields 0
|
|
168
167
|
matches in the active view, `selection.hint` provides guidance if matches exist
|
|
169
168
|
in the alternate revision view (such as searching for deleted text to restore).
|
|
169
|
+
Compact `extract --revised` output retains revision authors and marks paragraphs
|
|
170
|
+
whose content is wholly hidden in the selected view as `deleted` or `inserted`.
|
|
171
|
+
One such paragraph can be restored without restating it:
|
|
172
|
+
`docx-redline apply input.docx --restore --target-id ID --output reviewed.docx`.
|
|
173
|
+
Add one exact `--find`/`--replace` pair to make a localized correction while
|
|
174
|
+
restoring. The shortcut requires a strong rejected-view paragraph ID and does
|
|
175
|
+
not infer a range or adjacent content.
|
|
170
176
|
`revisionView` accepts `accepted`, `rejected`, or `current`. Returned
|
|
171
177
|
paragraphs identify matches versus context and include `humanReference` for
|
|
172
178
|
user-facing summaries.
|
|
@@ -241,18 +247,10 @@ latency. Checked comparative results are in the
|
|
|
241
247
|
### Agent CLI
|
|
242
248
|
|
|
243
249
|
```bash
|
|
244
|
-
#
|
|
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
|
|
250
|
+
# Default agent workflow: inspect once, then apply once
|
|
251
251
|
docx-redline extract contract.docx --search "termination" --around 3
|
|
252
|
-
docx-redline
|
|
253
|
-
|
|
254
|
-
docx-redline validate reviewed.docx
|
|
255
|
-
```
|
|
252
|
+
node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
|
|
253
|
+
```
|
|
256
254
|
|
|
257
255
|
```bash
|
|
258
256
|
# Inline one-liner edit (no operations file needed)
|
|
@@ -267,9 +265,9 @@ docx-redline apply contract.docx --target "Another author's clause" --modified "
|
|
|
267
265
|
# High-assurance atomic batch with nonzero exit on any incomplete result
|
|
268
266
|
docx-redline apply contract.docx --operations operations.json --atomic --require-complete --output reviewed.docx
|
|
269
267
|
|
|
270
|
-
#
|
|
271
|
-
|
|
272
|
-
```
|
|
268
|
+
# Optional read-only audit before a deliberately staged batch
|
|
269
|
+
docx-redline preflight contract.docx --operations operations.json --author "Editor"
|
|
270
|
+
```
|
|
273
271
|
|
|
274
272
|
All commands emit JSON on stdout. `apply` defaults:
|
|
275
273
|
- **Author**: Defaults to `'AI Redliner'` (or `DOCX_REDLINE_AUTHOR` environment variable).
|
|
@@ -282,7 +280,8 @@ All commands emit JSON on stdout. `apply` defaults:
|
|
|
282
280
|
- **Compact stdout**: `--compact` emits one-line mutation JSON. It changes serialization only, not operation semantics.
|
|
283
281
|
- **Tracked changes**: Defaults to `generateRedlines: true`. Pass `--no-redlines` when clean direct text edits are desired.
|
|
284
282
|
- **Inline edits**: Use `--target <text>` with `--modified <text>` or `--comment <text>` for quick one-liners without creating a JSON file.
|
|
285
|
-
- **Localized edits**:
|
|
283
|
+
- **Localized edits**: After extraction, use `replacements` with the inspected `paragraphId` plus `fingerprint` to avoid restating a long paragraph. Retain `exactText` locally for drafting. Targetless `--find`/`--replace` is an optional speculative path described below.
|
|
284
|
+
- **Invisible spaces**: Localized matching is case-sensitive and tries exact text first. If no exact span exists, ordinary spaces may match DOCX non-breaking spaces; ambiguous equivalent matches still fail closed, and `change.replacements[i].matchMode` reports `space_equivalent` when used.
|
|
286
285
|
- **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.
|
|
287
286
|
|
|
288
287
|
Inspection commands default to 20 direct matches and a 48 KiB soft response
|
|
@@ -303,10 +302,32 @@ user-facing Word locations; use `humanReference`, `provision`, or
|
|
|
303
302
|
`recovery-envelope-v1`, `require-complete-exit`, `operations-stdin`,
|
|
304
303
|
`agent-safety-profile-v2`, `deduplicated-cli-receipts`, and
|
|
305
304
|
`compact-cli-json-v1`, `localized-replacements-v1`,
|
|
306
|
-
`speculative-search-apply-v1`,
|
|
305
|
+
`speculative-search-apply-v1`, `localized-change-summary-v1`, and
|
|
306
|
+
`restore-shortcuts-v1`, plus `localized-space-equivalence-v1` capabilities.
|
|
307
307
|
Wrappers should negotiate only the
|
|
308
308
|
capabilities they use. Run `docx-redline <command> --help` for that command's
|
|
309
309
|
machine-readable options, behavior, exit codes, canonical GitHub documentation links, and compact examples.
|
|
310
|
+
|
|
311
|
+
#### Optional speculative CLI path
|
|
312
|
+
|
|
313
|
+
Harnesses with a measured confidence policy may attempt a targetless localized
|
|
314
|
+
edit. This is not the default agent workflow:
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# Globally unique literal
|
|
318
|
+
docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
319
|
+
|
|
320
|
+
# Optional directional scope using a longer, fairly unique nearby phrase
|
|
321
|
+
docx-redline apply contract.docx --search "distinctive nearby heading or phrase" --context-range 1:3 --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Generic or repeated anchors can widen the unioned scope until multiple
|
|
325
|
+
paragraphs contain `find`, causing a safe `AMBIGUOUS_TARGET` failure and a
|
|
326
|
+
recovery turn. `--around 3` is symmetric. On success,
|
|
327
|
+
`change.context.anchorMatchCount > 1` signals a repeated anchor; confirm the
|
|
328
|
+
returned location and bounded evidence. Matching remains case-sensitive and
|
|
329
|
+
exact-first, with a narrow ordinary-space/NBSP fallback that still refuses
|
|
330
|
+
ambiguity.
|
|
310
331
|
|
|
311
332
|
See the [compact agent fast start](./docs/AGENT_FAST_START.md), the
|
|
312
333
|
[skill/harness authoring contract](./docs/SKILL_AUTHORING.md), and the
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @ansonlai/docx-redline-js v0.7.
|
|
1
|
+
// @ansonlai/docx-redline-js v0.7.2 — 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;
|
|
@@ -11609,9 +11609,8 @@ function inspectDocumentParts(parts, options = {}) {
|
|
|
11609
11609
|
if (options.range && (index < rangeStart || index > rangeEnd)) continue;
|
|
11610
11610
|
if (Array.isArray(options.indexes) && !options.indexes.includes(index)) continue;
|
|
11611
11611
|
const pNode = paragraphNodes[i];
|
|
11612
|
-
if (options.
|
|
11613
|
-
if (options.
|
|
11614
|
-
if (options.revised && revisionAuthors(pNode).length === 0) continue;
|
|
11612
|
+
if (options.inTable != null && hasAncestor(pNode, "tc") !== !!options.inTable) continue;
|
|
11613
|
+
if (options.revisedOnly && revisionAuthors(pNode).length === 0) continue;
|
|
11615
11614
|
const altText = extractCanonicalParagraphText(pNode, { revisionView: alternateView });
|
|
11616
11615
|
if (options.skipEmpty && altText.length === 0) continue;
|
|
11617
11616
|
if (altText.toLowerCase().includes(needle)) {
|