@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.
@@ -1,57 +1,55 @@
1
1
  # Agent Fast Start
2
2
 
3
- Use this page for ordinary `.docx` edits. For source changes or unusual Word structures, follow the links at the end.
3
+ Use this page for ordinary `.docx` edits. For unusual Word structures or optional shortcuts, follow the links at the end.
4
4
 
5
5
  ## Structured agent tool
6
6
 
7
- If your host provides a document-session wrapper:
7
+ If the host provides a document-session wrapper:
8
8
 
9
- 1. Inspect/search once with enough surrounding context to draft the change.
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.
9
+ 1. Inspect once with enough surrounding context to draft the change.
10
+ 2. Apply once with the returned revision-bound handle.
11
+ 3. Accept only the wrapper's complete-success result; refresh failed handles.
12
12
 
13
- The repository's `examples/agent-session-wrapper.mjs` demonstrates this pattern.
14
- It is a development sample, not a package API.
13
+ The repository's `examples/agent-session-wrapper.mjs` is a development sample, not a package API.
15
14
 
16
- ## CLI fallback
15
+ ## CLI workflow
17
16
 
18
- 1. For a literal mechanical edit with known old and new text, try one-turn apply:
19
-
20
- ```bash
21
- docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
22
- ```
23
-
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`:
17
+ 1. Extract the relevant clause or range:
29
18
 
30
19
  ```bash
31
20
  docx-redline extract contract.docx --search "termination" --around 3
32
21
  ```
33
22
 
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:
23
+ Search is case-insensitive. Follow `selection.nextAfter` when truncated. Preserve `selection`, `humanReference`, target descriptors, and revision cues when reshaping output. Report `humanReference`, not a machine paragraph number.
24
+
25
+ 2. Retain inspected `exactText` for drafting and target with its `paragraphId` plus `fingerprint`, then apply once with a UTF-8 operations file or serializer-backed stdin:
35
26
 
36
27
  ```bash
37
28
  node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
38
29
  ```
39
30
 
40
- Use `JSON.stringify`, not shell interpolation. `modified` is the complete desired accepted-view paragraph.
31
+ Use complete `modified` text for a broad semantic revision. For a small literal change in that inspected target, use
32
+ `replacements: [{ "find": "old text", "replace": "new text" }]` instead.
33
+ Use `JSON.stringify`; never interpolate document text through shell quoting. Preserve intentionally relative wording unless the user asks for a concrete value.
34
+
35
+ ## Restore branch
41
36
 
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.
37
+ If the user requests deleted text, search with `--view rejected` first. Otherwise follow `selection.hint` only when it identifies an alternate revision view. Restore the inspected strong target; do not infer adjacent content. Run `docx-redline apply --help` for canonical restore shapes.
43
38
 
44
- ## Batch and result rules
39
+ ## Completion and recovery
45
40
 
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.
48
- - Require `completion: true`, `written: true`, a non-null `outputPath`, and no
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.
52
- - On failure, follow `error.recovery.action`. Never retry unchanged arguments.
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.
41
+ - Require `completion: true` and a non-null `outputPath`; the CLI computes this from write, operation, commit, and localized-verification results.
42
+ - On failure, follow `error.recovery.action`; never retry unchanged arguments.
43
+ - Use `retryPlan.base: "original"` to replay a batch and `"output"` to retain
44
+ committed progressive work and retry the reported indexes.
45
+ - The source is not overwritten unless `--in-place` is explicit.
46
+ - Never accept/reject revisions or remove comments without authorization.
47
+ - Add `--atomic` or a non-default revision policy only when deliberately needed;
48
+ confirm `effectiveOptions`.
49
+ - Strong inspected targets bind to batch start. Consolidate writes to one source
50
+ and use captures only for intentional created-content dependencies.
55
51
 
56
- Advanced operations and recovery: [Agent Knowledge Base](AGENT_KNOWLEDGE_BASE.md); canonical contract: [document-operations.schema.json](schemas/document-operations.schema.json)
52
+ Advanced speculative apply, directional scoping, operation constraints, and
53
+ recovery: [Agent Knowledge Base](AGENT_KNOWLEDGE_BASE.md). Canonical schema:
54
+ [document-operations.schema.json](schemas/document-operations.schema.json).
57
55
  Wrapper design: [README](../README.md#example-agent-session-wrapper-development-only)
@@ -476,63 +476,41 @@ The canonical machine-readable contract is
476
476
  `docs/schemas/document-operations.schema.json`. Read that schema or the examples
477
477
  here instead of grepping bundled implementation code.
478
478
 
479
- #### Standard Workflow (Fast & Direct)
480
-
481
- Use this for everything by default. `apply` is fast, progressive, and self-validating by default—it validates the resulting package and revision markup internally before writing. **Do not insert a `preflight` or baseline `validate` step on top of it "to be safe"**; `apply` already covers that internally. It supports inline one-liners as well as batch operations files:
482
-
483
- The short route for a document-editing request is:
484
-
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
494
- per target paragraph, and consolidate multiple changes to that paragraph.
495
- 4. Run `apply` once per stable batch. Strong inspected targets are bound against
496
- the batch-start document, so independent operations do not need manual
497
- bottom-up sorting around structural edits. Consolidate multiple complete
498
- desired states for the same source. A unique exact reference to paragraph
499
- text created elsewhere in the batch is scheduled automatically; use explicit
500
- captures/selectors for non-unique or advanced created-content dependencies.
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
505
- structure needs confirmation.
506
-
507
- Do not probe operation behavior with disposable apply commands or read a vendor
508
- bundle before this route. If `apply` returns an error, use the recovery matrix
509
- below and make one cause-specific correction.
510
-
511
- ```bash
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
479
+ #### Standard Workflow (Extract Then Apply)
480
+
481
+ Use this for ordinary edits. `apply` validates the resulting package and
482
+ revision markup internally before writing, so do not add `preflight` or baseline
483
+ `validate` merely for reassurance.
484
+
485
+ 1. Run one focused `extract`. Add `--around 3` when surrounding context is
486
+ needed. Retain `exactText` for drafting and target with `paragraphId` plus
487
+ `fingerprint`.
488
+ 2. Build one final operation per target. Use complete `modified` text for broad
489
+ semantic revisions or localized `replacements` for small literal changes in
490
+ an inspected target. Consolidate multiple changes to one paragraph.
491
+ 3. Run `apply` once per stable batch. Independent strong targets bind against
492
+ the batch-start document and do not need bottom-up sorting. Use captures only
493
+ for intentional created-content dependencies.
494
+ 4. Require `completion: true` and a non-null `outputPath`. The CLI derives
495
+ completion from write status, operation outcomes, commit disposition, and
496
+ localized accepted-view verification.
497
+ 5. Run a focused post-apply extraction only when placement or structural output
498
+ needs confirmation.
499
+
500
+ If `apply` returns an error, follow the recovery envelope below and make one
501
+ cause-specific correction. Do not probe behavior with disposable mutations or
502
+ read a vendor bundle.
514
503
 
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
504
+ ```bash
505
+ # 1. Focused contextual discovery
519
506
  docx-redline extract contract.docx --search "termination" --around 3
520
507
 
521
- # 4. Inline complete-paragraph edit
522
- docx-redline apply contract.docx --target "Original clause" --modified "New clause" --output reviewed.docx
523
-
524
- # 5. Direct edit without tracked changes (clean text, no revision clutter)
525
- docx-redline apply contract.docx --target "Typo fix" --modified "Fixed typo" --no-redlines --output clean.docx
526
-
527
- # 6. Cross-author edit inside another reviewer's pending insertion
528
- docx-redline apply contract.docx --target "Pending clause text" --modified "Updated clause text" --existing-revisions slice-cross-author --output reviewed.docx
529
-
530
- # 7. Batch operations with ops.json
531
- docx-redline apply contract.docx --operations operations.json --output reviewed.docx
532
-
533
- # 8. Serializer-backed stdin with compact stdout
508
+ # 2. Serializer-backed apply against the inspected target
534
509
  node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
535
- ```
510
+
511
+ # Optional clean edit without tracked changes
512
+ docx-redline apply contract.docx --target "Typo fix" --modified "Fixed typo" --no-redlines --output clean.docx
513
+ ```
536
514
 
537
515
  Key CLI defaults and behaviors:
538
516
  - **Author**: Automatically defaults to `'AI Redliner'` (overridable via `--author` or `DOCX_REDLINE_AUTHOR` environment variable).
@@ -544,9 +522,36 @@ Key CLI defaults and behaviors:
544
522
  - **Agent profile**: `--profile agent` enables complete-success exit behavior but preserves progressive execution and the ordinary revision policy. Compose it with `--atomic` or an explicit `--existing-revisions` choice when intended; resolved values appear in `effectiveOptions`.
545
523
  - **Operation transport**: A UTF-8 operations file and serializer-backed `--operations -` are peers. Use whichever the host can construct without interpolating legal text in the shell.
546
524
  - **Compact mutation JSON**: `apply`, `accept`, `reject`, and `delete-comments` omit document/package XML, full validation arrays, and duplicate nested receipts. Top-level `receipts` is authoritative. Pass `--compact` for one-line JSON; run `validate` for full issue records.
547
- - Check `completion: true`, `written: true`, and a non-null `outputPath` on stdout. `completion` is derived from the write result, top-level status, and every operation status, so failed, partial, and unwritten work cannot appear complete. If an error occurs, inspect `error.code` or `results[i].error.code` (e.g. `TARGET_NOT_FOUND`, `ANCHOR_NOT_FOUND`) before correcting the cause and re-applying.
525
+ - Check `completion: true` and a non-null `outputPath` on stdout. Failed,
526
+ partial, rolled-back, unverified, and unwritten work cannot appear complete.
527
+ If an error occurs, follow `error.recovery.action` before correcting the cause.
548
528
 
549
- For multi-clause or multi-page reviews, apply edits **section-by-section** or clause-by-clause (e.g., using `--in-place` on a working copy) rather than bundling dozens of edits into one massive batch. This keeps context compact, simplifies error diagnosis, and prevents cascading anchor drift.
529
+ For multi-clause or multi-page reviews, use focused batches rather than one
530
+ massive batch. This keeps context compact and simplifies error diagnosis.
531
+
532
+ #### Optional Speculative Localized Apply
533
+
534
+ Targetless localized apply remains available to expert users and harnesses with
535
+ a measured confidence policy. It is not the ordinary agent workflow:
536
+
537
+ ```bash
538
+ # Globally unique literal
539
+ docx-redline apply contract.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
540
+
541
+ # Optional directional scope using a longer, fairly unique phrase
542
+ 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
543
+ ```
544
+
545
+ Omitting a target asks the CLI to resolve one eligible paragraph. Generic or
546
+ repeated anchors union their windows and may produce `AMBIGUOUS_TARGET`, costing
547
+ a recovery turn. `--around 3` is symmetric; `--occurrence` disambiguates only
548
+ inside an already selected paragraph. `anchorMatchCount > 1` signals a repeated
549
+ anchor even after a successful edit. Matching is exact and case-sensitive first,
550
+ then permits only ASCII-space/NBSP equivalence; ambiguity still fails closed.
551
+
552
+ Localized `change` evidence retains bounded before/after excerpts, commit
553
+ disposition, and accepted-view verification for audit consumers. Ordinary
554
+ agents rely on the computed top-level `completion` signal.
550
555
 
551
556
  #### High-Assurance / Staged Verification Workflow (Optional)
552
557
 
@@ -590,6 +595,13 @@ Paragraph indexes are 1-based. Inspection filters are `--index 12`,
590
595
  case-insensitive. When a search returns 0 matches in the active view but matches
591
596
  exist in the alternate view (such as searching for a deleted clause to restore),
592
597
  `selection.hint` provides immediate guidance to re-run with `--view rejected`.
598
+ Compact `extract --revised` results retain `hasRevisions`, `revisionAuthors`,
599
+ and `deleted`/`inserted` cues, so an empty `exactText` is identifiable as content
600
+ hidden by the selected revision view rather than a failed filter.
601
+ For one strongly identified rejected-view paragraph, `apply --restore
602
+ --target-id ID` restores the rejected text verbatim. One exact
603
+ `--find`/`--replace` pair may adjust it without restating the paragraph. The
604
+ shortcut refuses ranges, captures, weak targets, and inferred adjacent content.
593
605
  Add `--around N` (`--context N` or `-C N`) to a search;
594
606
  context records are labeled separately and do not consume the direct-hit
595
607
  `--limit`. Continue a bounded result with `--after <paragraph-index>`. Ordinary
@@ -1,86 +1,76 @@
1
1
  # Skill and Harness Authoring Contract
2
2
 
3
- Use this page when creating or updating an agent skill, MCP server, or custom
4
- harness for `@ansonlai/docx-redline-js`. Ordinary document-editing agents should
5
- load [Agent Fast Start](AGENT_FAST_START.md), not this design contract.
3
+ Use this page to create or update an agent skill, MCP server, or custom harness
4
+ for `@ansonlai/docx-redline-js`. Ordinary editing agents should load
5
+ [Agent Fast Start](AGENT_FAST_START.md), not this design contract.
6
6
 
7
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.
8
+ > Before 1.0, every integration must identify and pin its exact tested library
9
+ > release and required CLI contract/capabilities. Treat any different release or
10
+ > contract as unverified until compatibility tests pass.
11
11
 
12
- For example, an integration authored for the current contract-8 release should
13
- record a compatibility declaration equivalent to:
12
+ Example declaration for a contract-8 shell integration that uses localized
13
+ operations over stdin:
14
14
 
15
15
  ```json
16
16
  {
17
- "testedLibraryRelease": "0.7.0",
17
+ "testedLibraryRelease": "0.7.1",
18
18
  "requiredCliContractVersion": 8,
19
19
  "requiredCapabilities": [
20
- "command-help-v1",
20
+ "operations-stdin",
21
+ "agent-safety-profile-v2",
21
22
  "recovery-envelope-v1",
22
- "localized-replacements-v1",
23
- "speculative-search-apply-v1",
24
- "localized-change-summary-v1"
23
+ "localized-replacements-v1"
25
24
  ]
26
25
  }
27
26
  ```
28
27
 
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
-
32
28
  ## Runtime negotiation
33
29
 
34
- Run this before the first document operation when the skill vendors or invokes
35
- the CLI:
36
-
37
- ```bash
38
- docx-redline version
39
- ```
30
+ Run `docx-redline version` before the first document operation. Require CLI
31
+ contract version 8 and only the capabilities the integration actually uses. Check once per stable
32
+ runtime, fail closed when a requirement is absent, and never inspect bundles or
33
+ ZIP parts as a fallback.
40
34
 
41
- Require contract version 8 (the currently declared contract) and only the
42
- capabilities the integration uses. A typical shell skill should require
43
- `agent-safety-profile-v2`, `deduplicated-cli-receipts`, and
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.
35
+ Do not expose negotiated but unused capabilities as choices in the editing
36
+ prompt. `command-help-v1`, restore shortcuts, speculative apply, and localized
37
+ change summaries are optional requirements only for integrations that use them.
46
38
 
47
39
  ## Safety invariants
48
40
 
49
- Every generated integration must preserve these rules:
41
+ Every generated integration must:
50
42
 
51
- - Inspect narrowly and copy `exactText` plus `paragraphId` or `fingerprint`.
52
- - Treat `modified` as the complete desired accepted-view target content.
53
- - Use strict targeting, package validation, and a derived output path; never
54
- overwrite the source unless the caller explicitly requests `--in-place`.
55
- - Require `completion: true`, `written: true`, a non-null `outputPath`, and no
56
- per-operation error before reporting completion.
57
- - Never accept or reject another reviewer's work or delete comments without
58
- explicit user authorization.
59
- - Never retry unchanged failed arguments.
43
+ - inspect narrowly, retain `exactText`, and target with `paragraphId` plus
44
+ `fingerprint`;
45
+ - use strict targeting, package validation, and a derived output path;
46
+ - never overwrite the source unless `--in-place` is explicitly requested;
47
+ - require `completion: true` and a non-null `outputPath` before reporting
48
+ success;
49
+ - follow `error.recovery.action` and never retry unchanged failed arguments; and
50
+ - require explicit authorization before accepting/rejecting another reviewer's
51
+ work or deleting comments.
60
52
 
61
- The `agent` profile enables complete-success exit behavior and retains the
62
- ordinary progressive default. It does not select atomic execution or a special
63
- existing-revision policy. A skill must state those choices explicitly when its
64
- workflow needs them.
53
+ The CLI computes `completion` from write status, operation outcomes, commit
54
+ disposition, and localized accepted-view verification. Preserve the detailed
55
+ results for audit and recovery, but do not make the editing agent re-evaluate
56
+ those fields during ordinary success handling.
65
57
 
66
58
  ## Workflow policy choices
67
59
 
68
- Choose and document these separately from safety invariants:
60
+ Keep these exceptions separate from the default workflow:
69
61
 
70
- | Choice | Options | Guidance |
62
+ | Choice | Default | Override only when |
71
63
  |---|---|---|
72
- | Transaction | progressive default or `--atomic` | Use progressive for independent edits; use atomic when partial output is unacceptable. |
73
- | Existing revisions | `merge-same-author` default or explicit policy | Use `slice-cross-author` only when editing inside another reviewer's pending insertion is intended. |
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. |
75
- | Output naming | derived sibling or explicit destination | Keep source immutability unless in-place mutation is deliberately authorized. |
64
+ | Transaction | progressive | Partial output is unacceptable (`--atomic`). |
65
+ | Existing revisions | `merge-same-author` | Editing inside another reviewer's pending insertion is intended (`slice-cross-author`). |
66
+ | Reviewer identity | `AI Redliner` is a valid visible fallback | The host supplies a preferred flag, operation author, or environment value. |
67
+ | Output | derived sibling | The caller deliberately selects another destination. |
76
68
 
77
- Check `effectiveOptions` rather than assuming the resolved transaction,
78
- revision, author, or redline policy.
69
+ Check `effectiveOptions` when an integration deliberately sets a policy.
79
70
 
80
71
  ## Transport choices
81
72
 
82
- A UTF-8 operations file and serializer-backed stdin are peer transports. Choose
83
- the form the host can construct safely:
73
+ A UTF-8 operations file and serializer-backed stdin are peer transports:
84
74
 
85
75
  ```bash
86
76
  docx-redline apply input.docx --operations operations.json --profile agent --output reviewed.docx
@@ -88,45 +78,46 @@ node emit-operations.mjs | docx-redline apply input.docx --operations - --profil
88
78
  ```
89
79
 
90
80
  Use `JSON.stringify` or a structured tool API. Never demonstrate `echo`, a
91
- heredoc, or shell-interpolated legal text. `--compact` changes stdout formatting,
92
- not result semantics. A Node byte-oriented wrapper should call `openDocx` and
93
- return the full structured result rather than recreating the CLI serializer.
81
+ heredoc, or shell-interpolated document text. A Node byte-oriented wrapper should
82
+ call `openDocx` and return the structured result instead of recreating CLI
83
+ serialization, ZIP handling, targeting, validation, or rollback.
94
84
 
95
85
  ## Ordinary generated workflow
96
86
 
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:
87
+ The first executable editing example in a generated skill must be focused
88
+ extraction:
99
89
 
100
90
  ```bash
101
- docx-redline apply input.docx --find "thirty (30) days" --replace "sixty (60) days" --profile agent --output reviewed.docx
91
+ docx-redline extract input.docx --search "renewal notice" --around 3
102
92
  ```
103
93
 
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`.
94
+ Then apply once using the inspected strong target. Use complete `modified` text
95
+ for a broad semantic revision or `replacements` for a small literal change in
96
+ that target. Keep requested relative wording relative unless the user asks for
97
+ a concrete value.
110
98
 
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:
99
+ Follow `selection.nextAfter` when extraction is truncated. Output projections must retain
100
+ `selection`, target descriptors, `humanReference`, and revision
101
+ cues.
114
102
 
115
- ```bash
116
- docx-redline extract input.docx --search "termination" --around 3
117
- ```
103
+ ### Observed restore branch
104
+
105
+ If the user requests restoration, search `--view rejected` first. Otherwise
106
+ follow an alternate-view `selection.hint` when returned. Restore only the
107
+ inspected strong target. Require `restore-shortcuts-v1` only if the integration
108
+ uses inline `--restore`; canonical operations remain available.
109
+
110
+ ### Optional speculative execution
118
111
 
119
- Use `selection.nextAfter` with `--after` when truncated. When a search for
120
- deleted or restorable content yields 0 matches in accepted view, follow
121
- `selection.hint` and re-run with `--view rejected`. Apply once per stable batch.
122
- Run `docx-redline apply --help` for canonical redline, whole-paragraph comment,
123
- and rejected-view restore shapes; CLI help documentation fields return canonical
124
- GitHub URLs. The operation schema remains
125
- [document-operations.schema.json](schemas/document-operations.schema.json).
112
+ Do not make speculative apply part of an ordinary generated workflow. A harness
113
+ may opt into `speculative-search-apply-v1` only when it owns a measured confidence
114
+ policy and accepts the recovery cost of a miss. Keep anchor selection,
115
+ directional windows, occurrence handling, and exact matching semantics out of
116
+ the ordinary editing prompt; link to the knowledge base or CLI help instead.
126
117
 
127
118
  ## Recovery contract
128
119
 
129
- Lead error handling with exactly these runtime fields:
120
+ Lead failure handling with these runtime fields:
130
121
 
131
122
  1. `error.recovery.action`
132
123
  2. `error.recovery.requiresReinspection`
@@ -134,32 +125,23 @@ Lead error handling with exactly these runtime fields:
134
125
  4. `error.recovery.sameArgumentsSafe`
135
126
 
136
127
  Use `retryPlan.base` and its operation indexes to select the original or partial
137
- output package. Do not generate a second prose decision tree for every error
138
- code; error messages and bounded diagnostics explain the cause, while the four
139
- fields above determine the next action.
128
+ output package. Do not reproduce an error-code decision tree in the skill.
140
129
 
141
130
  ## Presentation rules
142
131
 
143
- Use `humanReference`, `provision`, or `nearestHeading` in user-facing completion
144
- reports. `P55`, `index: 55`, and phrases such as “the 55th paragraph” are machine
145
- targeting and pagination coordinates, not locations a Word user can follow.
146
- When no formal heading exists, use the returned short text lead. Never replace
147
- an exact machine target with a human-facing reference.
132
+ Use `humanReference`, `provision`, or `nearestHeading` in completion reports.
133
+ Paragraph indexes and `P55`-style references are machine coordinates, not
134
+ locations a document user can follow. Keep the exact machine target internally.
148
135
 
149
136
  ## Generation checklist
150
137
 
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.
155
- - Runtime version and required capabilities are checked once.
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.
160
- - Safety invariants are not mixed with transaction or revision-policy choices.
161
- - Operations-file and stdin examples use structured serialization.
162
- - The four-field recovery contract precedes any diagnostic commentary.
163
- - Completion prose uses legal references rather than machine ordinals.
164
- - The wrapper delegates mutation, validation, rollback, comments, numbering,
165
- receipts, and OOXML packaging to the library.
138
+ - Exact tested release, contract 8, and the minimum capability set are pinned.
139
+ - Runtime compatibility is checked once.
140
+ - The first ordinary command is focused extraction.
141
+ - Apply uses the inspected target with `modified` or localized `replacements`.
142
+ - Restore appears only as a user-requested or observed-view branch.
143
+ - Speculative execution is absent unless the harness owns a measured policy.
144
+ - Ordinary success requires `completion: true` and a non-null `outputPath`.
145
+ - Recovery, authorization, source immutability, and structured serialization
146
+ invariants are preserved.
147
+ - Wrappers delegate mutation and OOXML packaging to the library.