@ansonlai/docx-redline-js 0.7.2 → 0.8.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.
Files changed (53) hide show
  1. package/AGENTS.md +15 -10
  2. package/ARCHITECTURE.md +30 -10
  3. package/CHANGELOG.md +539 -431
  4. package/README.md +331 -309
  5. package/adapters/xml-adapter.js +84 -56
  6. package/core/sha256.js +120 -0
  7. package/dist/docx-redline-js.esm.js +8982 -693
  8. package/dist/docx-redline-js.esm.js.map +4 -4
  9. package/dist/docx-redline-js.esm.min.js +102 -89
  10. package/dist/docx-redline-js.esm.min.js.map +4 -4
  11. package/dist/docx-redline.bundle.cjs +28305 -0
  12. package/dist/docx-redline.bundle.cjs.map +7 -0
  13. package/dist/docx-redline.bundle.js +28296 -0
  14. package/dist/docx-redline.bundle.js.map +7 -0
  15. package/docs/AGENT_FAST_START.md +2 -1
  16. package/docs/AGENT_KNOWLEDGE_BASE.md +480 -393
  17. package/docs/SKILL_AUTHORING.md +5 -2
  18. package/docs/TESTING.md +2 -1
  19. package/docs/schemas/document-operations.schema.json +29 -0
  20. package/document/docx-document.d.ts +39 -0
  21. package/document/docx-document.js +1010 -0
  22. package/document/zip-archive.js +258 -0
  23. package/engine/reconstruction-writer.js +18 -0
  24. package/index.d.ts +598 -531
  25. package/index.js +349 -340
  26. package/node/cli-help.js +5 -5
  27. package/node/cli.js +760 -754
  28. package/node/docx-document.js +11 -355
  29. package/node/index.d.ts +1 -1
  30. package/node/zip-archive.js +28 -38
  31. package/package.json +14 -11
  32. package/scripts/build.mjs +40 -5
  33. package/scripts/generate-word-comment-edge-case-fixture.ps1 +58 -0
  34. package/scripts/generate-word-comment-thread-fixture.ps1 +36 -0
  35. package/scripts/generate-word-header-footer-fixture.ps1 +32 -0
  36. package/scripts/generate-word-multi-section-fixture.ps1 +27 -0
  37. package/scripts/generate-word-package-integrity-cases.mjs +141 -0
  38. package/scripts/generate-word-thread-state-fixtures.ps1 +50 -0
  39. package/scripts/word-com-package-integrity.ps1 +98 -0
  40. package/services/batch-operation-orchestrator.js +262 -259
  41. package/services/comment-replies.js +96 -95
  42. package/services/comment-thread-parts.js +280 -0
  43. package/services/document-inspection.js +366 -365
  44. package/services/document-operation-applier.js +230 -202
  45. package/services/document-operation-contract.js +17 -2
  46. package/services/error-recovery.js +6 -0
  47. package/services/headers-footers.js +206 -0
  48. package/services/operation-batch-compiler.js +1 -0
  49. package/services/operation-preflight.js +231 -218
  50. package/services/package-parts.js +80 -0
  51. package/services/revision-token.js +11 -7
  52. package/services/standalone-docx-plumbing.js +631 -569
  53. package/services/standalone-operation-runner.d.ts +19 -3
package/AGENTS.md CHANGED
@@ -11,8 +11,8 @@ or an installed plugin bundle to infer public behavior.
11
11
  | Edit or review a complete `.docx` | [Agent Fast Start](docs/AGENT_FAST_START.md) and the `docx-redline` CLI |
12
12
  | Build or update an agent skill/tool wrapper | [Skill Authoring Contract](docs/SKILL_AUTHORING.md), then [README wrapper example](README.md#example-agent-session-wrapper-development-only) |
13
13
  | Change paragraph/range reconciliation | `index.js` → `engine/oxml-engine.js` → selected `engine/*-mode.js` |
14
- | Change complete-document operations | `services/standalone-operation-runner.js` → `services/document-operation-*.js` |
15
- | Change DOCX ZIP or CLI behavior | `node/index.js`, `node/docx-document.js`, `node/cli.js` |
14
+ | Change complete-document operations | `document/docx-document.js` → `services/standalone-operation-runner.js` → `services/document-operation-*.js` |
15
+ | Change DOCX ZIP or CLI behavior | `document/zip-archive.js`, `node/index.js`, `node/docx-document.js`, `node/cli.js` |
16
16
  | Choose or add tests | Closest `tests/*.mjs`, then [Testing Guide](docs/TESTING.md) |
17
17
  | Understand ownership/dependencies | [Architecture](ARCHITECTURE.md) |
18
18
 
@@ -59,11 +59,13 @@ examples live in the
59
59
 
60
60
  ## Thin wrappers
61
61
 
62
- Wrap the CLI for shell hosts or `openDocx` from
63
- `@ansonlai/docx-redline-js/node` for byte-oriented Node hosts. A wrapper should
64
- inspect, translate narrow ergonomic inputs into canonical operations, call the
65
- facade once, and return its structured result. Do not reproduce ZIP handling,
66
- targeting, revision allocation, comments, numbering, validation, or rollback.
62
+ Wrap the CLI for shell hosts or `openDocx` from `@ansonlai/docx-redline-js`
63
+ (or `@ansonlai/docx-redline-js/bundle` for zero-dependency sandboxes, or
64
+ `@ansonlai/docx-redline-js/node` for backward-compatible Node hosts) for
65
+ byte-oriented hosts. A wrapper should inspect, translate narrow ergonomic inputs
66
+ into canonical operations, call the facade once, and return its structured result.
67
+ Do not reproduce ZIP handling, targeting, revision allocation, comments, numbering,
68
+ validation, or rollback.
67
69
 
68
70
  The stateful wrapper in `examples/agent-session-wrapper.mjs` is a testable
69
71
  development demonstration only. It is excluded from package files and exports.
@@ -74,13 +76,16 @@ not belong in an ordinary editing prompt merely because the CLI supports them.
74
76
  ## Code map
75
77
 
76
78
  ```text
77
- index.js host-independent public API
78
- core/ OOXML primitives, text views, targeting, validation
79
+ index.js host-independent public API & universal document facade
80
+ adapters/ DOM/XML parser provider with automatic pure-JS fallback
81
+ core/ OOXML primitives, text views, targeting, SHA-256, validation
82
+ document/ universal Uint8Array DOCX facade & fflate ZIP container
79
83
  pipeline/ ingestion, diffing, Markdown, lists, serialization
80
84
  engine/ reconciliation modes and run-level mutation
81
85
  orchestration/ route planning and structural conversion
82
86
  services/ document operations, comments, receipts, artifacts
83
- node/ Node-only ZIP and whole-DOCX facade/CLI
87
+ node/ Node CLI and backward-compatibility re-exports
88
+ dist/ universal ESM and zero-dependency sandbox bundles
84
89
  tests/*.mjs directly runnable suites
85
90
  ```
86
91
 
package/ARCHITECTURE.md CHANGED
@@ -8,11 +8,12 @@ This repository contains only the publishable package surface:
8
8
 
9
9
  - `adapters/`
10
10
  - `core/`
11
+ - `document/` (universal complete-DOCX facade & ZIP archive layer)
11
12
  - `engine/`
12
13
  - `pipeline/`
13
14
  - `services/`
14
15
  - `orchestration/`
15
- - `node/` (separate Node-only package facade)
16
+ - `node/` (Node CLI & backward-compatibility facade)
16
17
  - `index.js`
17
18
  - `index.d.ts`
18
19
  - `dist/`
@@ -22,8 +23,9 @@ No Word add-in entrypoints or host-specific integration layers are part of this
22
23
  ## Goals
23
24
 
24
25
  - Preserve Word-compatible redlines by editing OOXML directly.
25
- - Keep core logic host-independent (no Office.js globals, no Word API calls).
26
- - Reuse the same engine in browser, Node.js, and other JavaScript runtimes.
26
+ - Keep core logic and document-level operations host-independent (no Office.js globals, no Word API calls, no runtime Node built-ins like `node:zlib` or `node:crypto`).
27
+ - Standardize complete-document packages on `Uint8Array` binary payloads, pure-JS SHA-256 revision tokens, and `fflate` ZIP container manipulation.
28
+ - Reuse the same engine across Node.js, browsers, Cloudflare Workers, Deno, Bun, and sandboxed runtimes (e.g. n8n Code nodes).
27
29
  - Keep generated OOXML schema-safe through shared Word element creation and
28
30
  centralized revision metadata helpers.
29
31
 
@@ -37,7 +39,12 @@ No Word add-in entrypoints or host-specific integration layers are part of this
37
39
  │ └── xml-adapter.js
38
40
  ├── core/
39
41
  │ ├── paragraph-text.js
42
+ │ ├── sha256.js
40
43
  │ └── word-xml.js
44
+ ├── document/
45
+ │ ├── docx-document.js
46
+ │ ├── docx-document.d.ts
47
+ │ └── zip-archive.js
41
48
  ├── engine/
42
49
  │ ├── oxml-engine.js
43
50
  │ ├── surgical-mode.js
@@ -63,16 +70,22 @@ No Word add-in entrypoints or host-specific integration layers are part of this
63
70
  │ ├── cli.js
64
71
  │ ├── zip-archive.js
65
72
  │ └── index.js
73
+ ├── dist/
74
+ │ ├── docx-redline-js.esm.js
75
+ │ ├── docx-redline.bundle.js
76
+ │ └── docx-redline.bundle.cjs
66
77
  ├── index.js
67
78
  └── index.d.ts
68
79
  ```
69
80
 
70
81
  ## Entry Points
71
82
 
72
- - `index.js`: primary host-independent exports for OOXML reconciliation.
83
+ - `index.js`: primary host-independent exports for OOXML reconciliation and universal complete-document operations (`openDocx`, `DocxDocument`, `computePackageRevisionToken`).
84
+ - `document/docx-document.js`: universal `Uint8Array`-based document facade and package-level operation runner.
85
+ - `dist/docx-redline.bundle.js` / `dist/docx-redline.bundle.cjs`: zero-dependency standalone sandbox bundles, exported via `@ansonlai/docx-redline-js/bundle`.
73
86
  - `services/standalone-operation-runner.js`: stable complete-document XML
74
87
  operations, exported as `@ansonlai/docx-redline-js/standalone-runner`.
75
- - `node/index.js`: Node-only complete-DOCX buffer facade, exported as
88
+ - `node/index.js`: Node-compatible complete-DOCX facade re-exports, exported as
76
89
  `@ansonlai/docx-redline-js/node`.
77
90
  - `bin/docx-redline.js`: CLI launcher; command implementation lives in
78
91
  `node/cli.js` and shared operation behavior lives in `services/`.
@@ -181,11 +194,18 @@ No Word add-in entrypoints or host-specific integration layers are part of this
181
194
  - `services/document-inspection.js`
182
195
  - Read-only paragraphs/comments inventory with target identity, headings,
183
196
  revision authors, table context, and advisory visible numbering.
184
- - `node/docx-document.js`
185
- - Transactional whole-DOCX editing, artifact wiring, validation, and rollback.
186
- OOXML and package issues are classified as baseline/generated multisets, so
187
- unchanged source defects remain diagnostics while new defects block writes.
188
- This surface is excluded from the browser/root dependency graph.
197
+ - `document/docx-document.js`
198
+ - Universal transactional whole-DOCX editing, artifact wiring, validation, and rollback.
199
+ Standardized on `Uint8Array` binary payloads and pure-JS SHA-256 revision tokens.
200
+ Exposes `openDocx`, `DocxDocument`, and `computePackageRevisionToken` directly across all runtimes.
201
+ - `document/zip-archive.js`
202
+ - Universal, pure-JS ZIP archive reader and writer based on `fflate`. Operates on
203
+ `Uint8Array` byte arrays with zero Node built-ins (`node:zlib`, `Buffer`).
204
+ - `core/sha256.js`
205
+ - Pure-JS synchronous implementation of FIPS 180-4 SHA-256 with zero dependencies,
206
+ enabling deterministic revision tokens in sandboxed runtimes without `node:crypto`.
207
+ - `node/docx-document.js` and `node/zip-archive.js`
208
+ - Node-compatible re-exports maintaining `Buffer` compatibility for `@ansonlai/docx-redline-js/node`.
189
209
  - `node/cli.js` and `bin/docx-redline.js`
190
210
  - Cross-platform, JSON-only agent command boundary. Read commands never
191
211
  mutate; write commands require attribution, use package transactions, and