@ansonlai/docx-redline-js 0.7.0 → 0.7.1

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 CHANGED
@@ -22,13 +22,18 @@ specific advanced operation, API, or recovery topic you need.
22
22
  ## Ordinary document edits
23
23
 
24
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:
25
+ apply call. When global matching is too broad, use a longer, fairly unique
26
+ nearby phrase plus a directional range:
27
27
 
28
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
29
+ 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
30
30
  ```
31
31
 
32
+ Generic or repeated anchors widen the unioned scope and may return
33
+ `AMBIGUOUS_TARGET`, costing a recovery turn. On success, treat
34
+ `results[i].change.context.anchorMatchCount > 1` as a signal to confirm the
35
+ returned location and excerpts.
36
+
32
37
  For semantic drafting, inspect once and apply once. With a structured wrapper,
33
38
  use revision-bound handles. For shell-only work, use serializer-backed stdin:
34
39
 
@@ -37,6 +42,10 @@ docx-redline extract contract.docx --search "termination" --around 3
37
42
  node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
38
43
  ```
39
44
 
45
+ A single deleted paragraph found in rejected view can be restored verbatim with
46
+ `apply --restore --target-id ID`; add one `--find`/`--replace` pair for a small
47
+ exact correction. This shortcut does not infer ranges or companion paragraphs.
48
+
40
49
  For every ordinary text operation, `modified` is the complete desired
41
50
  accepted-view content. Copy inspected `exactText` verbatim and include
42
51
  `paragraphId` or `fingerprint`. Independent strong targets are bound against the
@@ -45,8 +54,9 @@ Consolidate incompatible writes to the same source; use captures for intentional
45
54
  created-content dependencies.
46
55
 
47
56
  Require `completion: true`, `written: true`, a non-null output path, and no
48
- per-operation errors. Localized edits also require `change.committed: true` and
49
- `change.verification.acceptedViewMatchesCompiledText: true`. Follow
57
+ per-operation errors. Localized edits also require
58
+ `results[i].change.committed: true`, `finalDisposition: "applied"`, and
59
+ `verification.acceptedViewMatchesCompiledText: true`. Follow
50
60
  `error.recovery.action` and `retryPlan`; never retry unchanged failed arguments.
51
61
  Follow `selection.hint` for restorable text. Do not accept/reject another
52
62
  reviewer's work or remove comments without explicit user authorization. The
@@ -74,7 +84,8 @@ development demonstration only. It is excluded from package files and exports.
74
84
  Production harnesses own their transport and negotiate the minimum CLI
75
85
  `contractVersion`/capabilities they use. The 0.7.0 localized fast path requires
76
86
  contract 8 and its localized replacement, speculative apply, and change-summary
77
- capabilities.
87
+ capabilities; the narrow restore shortcut additionally requires
88
+ `restore-shortcuts-v1`.
78
89
 
79
90
  ## Code map
80
91
 
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Added a narrow single-paragraph restore shortcut. A restore with a strong
6
+ rejected-view target may omit `modified` for verbatim restoration or provide
7
+ exact `replacements`; the CLI exposes the same path through `apply --restore
8
+ --target-id ID`. Ranges, captures, weak targets, and inferred companion
9
+ content remain excluded.
10
+
11
+ - Fixed rejected-view restore receipts so `resolvedTarget` text, fingerprint,
12
+ revision view, and match diagnostics describe the view actually used to
13
+ resolve the target.
14
+ - Fixed alternate-view search hints to honor `--revised`, `--table`, and
15
+ `--body`, and retained compact revision authors plus `deleted`/`inserted` cues
16
+ in `extract` output so empty revision-view paragraphs are self-explanatory.
17
+
5
18
  ## 0.7.0
6
19
 
7
20
  ### Agent Performance and Localized Editing
@@ -14,7 +27,9 @@
14
27
  - **One-turn speculative apply:** `docx-redline apply --find ... --replace ...`
15
28
  can resolve a globally unique source literal without preliminary extraction.
16
29
  `--search` plus signed `--context-range START:END` scopes visible headings and
17
- multi-paragraph provisions; `--around N` is symmetric shorthand.
30
+ nearby content; `--around N` is symmetric shorthand. Longer, distinctive
31
+ anchors are recommended because generic or repeated phrases widen the unioned
32
+ scope and may cost an ambiguity-recovery turn.
18
33
  - **Fail-closed selection:** Missing anchors and patch sources, multiple eligible
19
34
  paragraphs, ambiguous occurrences, overlaps, conflicts, and unsupported
20
35
  localized shapes refuse mutation. A failed speculative command never writes
package/README.md CHANGED
@@ -25,8 +25,9 @@ Converts AI-generated or programmatic text/markdown edits into valid Office Open
25
25
  Version 0.7.0 adds a contract-8 fast path for exact mechanical edits. Agents can
26
26
  send a small `find`/`replace` request instead of reproducing a complete legal
27
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`.
28
+ accepted-view paragraph. A longer, fairly unique nearby phrase can narrow the
29
+ attempt with a signed directional window. Generic or repeated anchors widen the
30
+ unioned scope and may cause a safe ambiguity failure and another tool turn.
30
31
 
31
32
  Speculative edits fail without writing when the anchor, paragraph, or source
32
33
  span is missing or ambiguous. Successful localized results include a committed
@@ -167,6 +168,13 @@ limit output. Search is a case-insensitive substring match; `around` adds nearby
167
168
  context, while `limit` and `after` page direct hits. When a search yields 0
168
169
  matches in the active view, `selection.hint` provides guidance if matches exist
169
170
  in the alternate revision view (such as searching for deleted text to restore).
171
+ Compact `extract --revised` output retains revision authors and marks paragraphs
172
+ whose content is wholly hidden in the selected view as `deleted` or `inserted`.
173
+ One such paragraph can be restored without restating it:
174
+ `docx-redline apply input.docx --restore --target-id ID --output reviewed.docx`.
175
+ Add one exact `--find`/`--replace` pair to make a localized correction while
176
+ restoring. The shortcut requires a strong rejected-view paragraph ID and does
177
+ not infer a range or adjacent content.
170
178
  `revisionView` accepts `accepted`, `rejected`, or `current`. Returned
171
179
  paragraphs identify matches versus context and include `humanReference` for
172
180
  user-facing summaries.
@@ -244,8 +252,8 @@ latency. Checked comparative results are in the
244
252
  # One-turn exact mechanical edit; fails closed unless one paragraph matches
245
253
  docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
246
254
 
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
255
+ # Directional context using a longer phrase with a higher chance of uniqueness
256
+ 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
249
257
 
250
258
  # Semantic drafting still starts with focused context
251
259
  docx-redline extract contract.docx --search "termination" --around 3
@@ -282,7 +290,7 @@ All commands emit JSON on stdout. `apply` defaults:
282
290
  - **Compact stdout**: `--compact` emits one-line mutation JSON. It changes serialization only, not operation semantics.
283
291
  - **Tracked changes**: Defaults to `generateRedlines: true`. Pass `--no-redlines` when clean direct text edits are desired.
284
292
  - **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`.
293
+ - **Localized edits**: Use `--find`/`--replace` with a known strong target, or omit the target for fail-closed global resolution. Add a longer, fairly unique `--search` phrase with `--context-range 1:3` for directional scope; `--around 3` is symmetric. Generic or repeated anchors can widen the unioned scope until multiple paragraphs contain `find`, producing a safe `AMBIGUOUS_TARGET` failure and an extra recovery turn. On success, `results[i].change.context.anchorMatchCount > 1` signals a non-unique anchor; confirm the returned location and bounded before/after evidence.
286
294
  - **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
295
 
288
296
  Inspection commands default to 20 direct matches and a 48 KiB soft response
@@ -303,7 +311,8 @@ user-facing Word locations; use `humanReference`, `provision`, or
303
311
  `recovery-envelope-v1`, `require-complete-exit`, `operations-stdin`,
304
312
  `agent-safety-profile-v2`, `deduplicated-cli-receipts`, and
305
313
  `compact-cli-json-v1`, `localized-replacements-v1`,
306
- `speculative-search-apply-v1`, and `localized-change-summary-v1` capabilities.
314
+ `speculative-search-apply-v1`, `localized-change-summary-v1`, and
315
+ `restore-shortcuts-v1` capabilities.
307
316
  Wrappers should negotiate only the
308
317
  capabilities they use. Run `docx-redline <command> --help` for that command's
309
318
  machine-readable options, behavior, exit codes, canonical GitHub documentation links, and compact examples.
@@ -1,4 +1,4 @@
1
- // @ansonlai/docx-redline-js v0.7.0 — https://github.com/AnsonLai/docx-redline-js
1
+ // @ansonlai/docx-redline-js v0.7.1 — 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.table && !hasAncestor(pNode, "tc")) continue;
11613
- if (options.body && hasAncestor(pNode, "tc")) continue;
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)) {