@ansonlai/docx-redline-js 0.7.1 → 0.8.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.
@@ -1,58 +1,56 @@
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 (or directly calls `openDocx` from `@ansonlai/docx-redline-js` with `Uint8Array` binary payloads):
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 universal `DocxDocument` and `openDocx` facade operates natively on `Uint8Array` across Node, browsers, edge workers, and sandboxes without requiring Node built-ins.
14
+ The repository's `examples/agent-session-wrapper.mjs` is a development sample, not a package API.
15
15
 
16
- ## CLI fallback
16
+ ## CLI workflow
17
17
 
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. To narrow it, use a longer, fairly unique phrase: `--search "distinctive nearby heading or phrase" --context-range 1:3`.
25
- Generic/repeated anchors can cause `AMBIGUOUS_TARGET` and waste a recovery turn. If `anchorMatchCount > 1`, confirm the returned location and excerpts. `--around 3` is symmetric.
26
-
27
- 2. For semantic drafting such as “make this provision mutual,” extract enough
28
- context, then copy `exactText` with `paragraphId` or `fingerprint`:
18
+ 1. Extract the relevant clause or range:
29
19
 
30
20
  ```bash
31
21
  docx-redline extract contract.docx --search "termination" --around 3
32
22
  ```
33
23
 
34
- Search is case-insensitive; follow `selection.hint` and `selection.nextAfter`, and report `humanReference`. With `--revised`, use `hasRevisions`, `revisionAuthors`, and `deleted` or `inserted` to interpret paragraphs whose active-view `exactText` is empty. Restore one rejected-view paragraph verbatim with `apply --restore --target-id ID`; add one `--find`/`--replace` pair for an exact correction. The shortcut never expands to adjacent paragraphs. Otherwise, apply once with a UTF-8 operations file or serializer-backed stdin:
24
+ 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.
25
+
26
+ 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
27
 
36
28
  ```bash
37
29
  node emit-operations.mjs | docx-redline apply contract.docx --operations - --profile agent --compact --output reviewed.docx
38
30
  ```
39
31
 
40
- Use `JSON.stringify`, not shell interpolation. `modified` is the complete desired accepted-view paragraph.
32
+ Use complete `modified` text for a broad semantic revision. For a small literal change in that inspected target, use
33
+ `replacements: [{ "find": "old text", "replace": "new text" }]` instead.
34
+ Use `JSON.stringify`; never interpolate document text through shell quoting. Preserve intentionally relative wording unless the user asks for a concrete value.
35
+
36
+ ## Restore branch
41
37
 
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.
38
+ 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
39
 
44
- ## Batch and result rules
40
+ ## Completion and recovery
45
41
 
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
50
- `results[i].change.committed: true`, `finalDisposition: "applied"`, and
51
- `verification.acceptedViewMatchesCompiledText: true`. The source is
52
- not overwritten unless `--in-place` is explicit.
53
- - On failure, follow `error.recovery.action`. Never retry unchanged arguments.
54
- - `retryPlan.base: "original"` means replay the batch; `"output"` means retain committed work and retry reported indexes.
55
- - Never accept/reject revisions or remove comments without user authorization. `slice-cross-author` preserves history for edits inside foreign insertions.
42
+ - Require `completion: true` and a non-null `outputPath`; the CLI computes this from write, operation, commit, and localized-verification results.
43
+ - On failure, follow `error.recovery.action`; never retry unchanged arguments.
44
+ - Use `retryPlan.base: "original"` to replay a batch and `"output"` to retain
45
+ committed progressive work and retry the reported indexes.
46
+ - The source is not overwritten unless `--in-place` is explicit.
47
+ - Never accept/reject revisions or remove comments without authorization.
48
+ - Add `--atomic` or a non-default revision policy only when deliberately needed;
49
+ confirm `effectiveOptions`.
50
+ - Strong inspected targets bind to batch start. Consolidate writes to one source
51
+ and use captures only for intentional created-content dependencies.
56
52
 
57
- Advanced operations and recovery: [Agent Knowledge Base](AGENT_KNOWLEDGE_BASE.md); canonical contract: [document-operations.schema.json](schemas/document-operations.schema.json)
53
+ Advanced speculative apply, directional scoping, operation constraints, and
54
+ recovery: [Agent Knowledge Base](AGENT_KNOWLEDGE_BASE.md). Canonical schema:
55
+ [document-operations.schema.json](schemas/document-operations.schema.json).
58
56
  Wrapper design: [README](../README.md#example-agent-session-wrapper-development-only)