doc-control 0.0.1__tar.gz

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 (149) hide show
  1. doc_control-0.0.1/.gitignore +41 -0
  2. doc_control-0.0.1/LICENSE +202 -0
  3. doc_control-0.0.1/PKG-INFO +76 -0
  4. doc_control-0.0.1/README.md +67 -0
  5. doc_control-0.0.1/pyproject.toml +70 -0
  6. doc_control-0.0.1/src/doc_control/__init__.py +4 -0
  7. doc_control-0.0.1/src/doc_control/__main__.py +3 -0
  8. doc_control-0.0.1/src/doc_control/cli.py +93 -0
  9. doc_control-0.0.1/src/doc_control/envelope.py +40 -0
  10. doc_control-0.0.1/src/doc_control/errors.py +72 -0
  11. doc_control-0.0.1/src/doc_control/mcp.py +94 -0
  12. doc_control-0.0.1/src/doc_control/model/__init__.py +1 -0
  13. doc_control-0.0.1/src/doc_control/model/address.py +113 -0
  14. doc_control-0.0.1/src/doc_control/model/align.py +529 -0
  15. doc_control-0.0.1/src/doc_control/model/anchor.py +609 -0
  16. doc_control-0.0.1/src/doc_control/model/annotations.py +280 -0
  17. doc_control-0.0.1/src/doc_control/model/document.py +109 -0
  18. doc_control-0.0.1/src/doc_control/model/format.py +109 -0
  19. doc_control-0.0.1/src/doc_control/model/index.py +353 -0
  20. doc_control-0.0.1/src/doc_control/model/layout.py +143 -0
  21. doc_control-0.0.1/src/doc_control/model/normalized.py +160 -0
  22. doc_control-0.0.1/src/doc_control/model/pages.py +403 -0
  23. doc_control-0.0.1/src/doc_control/model/parts.py +50 -0
  24. doc_control-0.0.1/src/doc_control/model/search.py +403 -0
  25. doc_control-0.0.1/src/doc_control/model/segment.py +445 -0
  26. doc_control-0.0.1/src/doc_control/model/structure.py +418 -0
  27. doc_control-0.0.1/src/doc_control/model/styles.py +134 -0
  28. doc_control-0.0.1/src/doc_control/ooxml/__init__.py +1 -0
  29. doc_control-0.0.1/src/doc_control/ooxml/commentparts.py +679 -0
  30. doc_control-0.0.1/src/doc_control/ooxml/formatting.py +181 -0
  31. doc_control-0.0.1/src/doc_control/ooxml/resolve.py +269 -0
  32. doc_control-0.0.1/src/doc_control/ooxml/revisions.py +1024 -0
  33. doc_control-0.0.1/src/doc_control/ooxml/splice.py +957 -0
  34. doc_control-0.0.1/src/doc_control/ooxml/styledef.py +504 -0
  35. doc_control-0.0.1/src/doc_control/ooxml/zipio.py +454 -0
  36. doc_control-0.0.1/src/doc_control/ops/__init__.py +1 -0
  37. doc_control-0.0.1/src/doc_control/ops/anchor.py +135 -0
  38. doc_control-0.0.1/src/doc_control/ops/batch.py +177 -0
  39. doc_control-0.0.1/src/doc_control/ops/comments.py +433 -0
  40. doc_control-0.0.1/src/doc_control/ops/compare.py +620 -0
  41. doc_control-0.0.1/src/doc_control/ops/diff.py +177 -0
  42. doc_control-0.0.1/src/doc_control/ops/dotx.py +206 -0
  43. doc_control-0.0.1/src/doc_control/ops/find.py +190 -0
  44. doc_control-0.0.1/src/doc_control/ops/history.py +479 -0
  45. doc_control-0.0.1/src/doc_control/ops/layout.py +40 -0
  46. doc_control-0.0.1/src/doc_control/ops/locate.py +364 -0
  47. doc_control-0.0.1/src/doc_control/ops/meta.py +49 -0
  48. doc_control-0.0.1/src/doc_control/ops/page.py +104 -0
  49. doc_control-0.0.1/src/doc_control/ops/paging.py +124 -0
  50. doc_control-0.0.1/src/doc_control/ops/read.py +517 -0
  51. doc_control-0.0.1/src/doc_control/ops/recipe.py +161 -0
  52. doc_control-0.0.1/src/doc_control/ops/rename.py +370 -0
  53. doc_control-0.0.1/src/doc_control/ops/revision.py +616 -0
  54. doc_control-0.0.1/src/doc_control/ops/segment.py +289 -0
  55. doc_control-0.0.1/src/doc_control/ops/styleset.py +262 -0
  56. doc_control-0.0.1/src/doc_control/ops/stylewrite.py +573 -0
  57. doc_control-0.0.1/src/doc_control/ops/text.py +207 -0
  58. doc_control-0.0.1/src/doc_control/ops/tracked.py +1441 -0
  59. doc_control-0.0.1/src/doc_control/py.typed +0 -0
  60. doc_control-0.0.1/src/doc_control/recipes/bundled/blank-paragraphs.json +16 -0
  61. doc_control-0.0.1/src/doc_control/recipes/bundled/chapter-heading-period.json +17 -0
  62. doc_control-0.0.1/src/doc_control/recipes/bundled/chapter-heading-style.json +17 -0
  63. doc_control-0.0.1/src/doc_control/recipes/bundled/dashes-em.json +17 -0
  64. doc_control-0.0.1/src/doc_control/recipes/bundled/dashes-spaced-en.json +19 -0
  65. doc_control-0.0.1/src/doc_control/recipes/bundled/fake-centring.json +22 -0
  66. doc_control-0.0.1/src/doc_control/recipes/bundled/fake-tabs.json +17 -0
  67. doc_control-0.0.1/src/doc_control/recipes/bundled/leading-spaces.json +17 -0
  68. doc_control-0.0.1/src/doc_control/recipes/bundled/leftover-markers.json +17 -0
  69. doc_control-0.0.1/src/doc_control/recipes/bundled/quotes-de.json +17 -0
  70. doc_control-0.0.1/src/doc_control/recipes/bundled/quotes-en-single.json +17 -0
  71. doc_control-0.0.1/src/doc_control/recipes/bundled/quotes-en.json +17 -0
  72. doc_control-0.0.1/src/doc_control/recipes/bundled/quotes-fr.json +17 -0
  73. doc_control-0.0.1/src/doc_control/recipes/bundled/scene-break.json +22 -0
  74. doc_control-0.0.1/src/doc_control/recipes/bundled/tab-indent.json +22 -0
  75. doc_control-0.0.1/src/doc_control/recipes/engine.py +209 -0
  76. doc_control-0.0.1/src/doc_control/recipes/schema.py +140 -0
  77. doc_control-0.0.1/src/doc_control/recipes/store.py +96 -0
  78. doc_control-0.0.1/src/doc_control/registry.py +76 -0
  79. doc_control-0.0.1/src/doc_control/safety/__init__.py +38 -0
  80. doc_control-0.0.1/src/doc_control/safety/history.py +508 -0
  81. doc_control-0.0.1/src/doc_control/safety/lock.py +69 -0
  82. doc_control-0.0.1/src/doc_control/safety/store.py +415 -0
  83. doc_control-0.0.1/src/doc_control/safety/verify.py +357 -0
  84. doc_control-0.0.1/src/doc_control/schema.py +143 -0
  85. doc_control-0.0.1/tests/__init__.py +0 -0
  86. doc_control-0.0.1/tests/ci/__init__.py +0 -0
  87. doc_control-0.0.1/tests/ci/test_hygiene.py +90 -0
  88. doc_control-0.0.1/tests/conftest.py +66 -0
  89. doc_control-0.0.1/tests/corpus/__init__.py +0 -0
  90. doc_control-0.0.1/tests/corpus/generator.py +740 -0
  91. doc_control-0.0.1/tests/corpus/private.py +55 -0
  92. doc_control-0.0.1/tests/corpus/structural.py +289 -0
  93. doc_control-0.0.1/tests/corpus/test_generator.py +252 -0
  94. doc_control-0.0.1/tests/corpus/test_validator.py +244 -0
  95. doc_control-0.0.1/tests/corpus/validator.py +409 -0
  96. doc_control-0.0.1/tests/helpers.py +40 -0
  97. doc_control-0.0.1/tests/model/__init__.py +0 -0
  98. doc_control-0.0.1/tests/model/data/segment_gold.txt +326 -0
  99. doc_control-0.0.1/tests/model/test_address.py +156 -0
  100. doc_control-0.0.1/tests/model/test_anchor.py +721 -0
  101. doc_control-0.0.1/tests/model/test_anchor_exact.py +161 -0
  102. doc_control-0.0.1/tests/model/test_index.py +367 -0
  103. doc_control-0.0.1/tests/model/test_normalized.py +244 -0
  104. doc_control-0.0.1/tests/model/test_segment.py +302 -0
  105. doc_control-0.0.1/tests/model/test_structure.py +575 -0
  106. doc_control-0.0.1/tests/ooxml/__init__.py +0 -0
  107. doc_control-0.0.1/tests/ooxml/docgen.py +269 -0
  108. doc_control-0.0.1/tests/ooxml/test_splice.py +774 -0
  109. doc_control-0.0.1/tests/ooxml/test_zipio.py +345 -0
  110. doc_control-0.0.1/tests/ops/__init__.py +0 -0
  111. doc_control-0.0.1/tests/ops/bigdoc.py +32 -0
  112. doc_control-0.0.1/tests/ops/revsim.py +190 -0
  113. doc_control-0.0.1/tests/ops/test_batch.py +395 -0
  114. doc_control-0.0.1/tests/ops/test_comments.py +420 -0
  115. doc_control-0.0.1/tests/ops/test_compare.py +473 -0
  116. doc_control-0.0.1/tests/ops/test_diff.py +621 -0
  117. doc_control-0.0.1/tests/ops/test_dotx.py +202 -0
  118. doc_control-0.0.1/tests/ops/test_find.py +322 -0
  119. doc_control-0.0.1/tests/ops/test_find_hardening.py +122 -0
  120. doc_control-0.0.1/tests/ops/test_format.py +255 -0
  121. doc_control-0.0.1/tests/ops/test_layout.py +200 -0
  122. doc_control-0.0.1/tests/ops/test_locate.py +344 -0
  123. doc_control-0.0.1/tests/ops/test_page.py +381 -0
  124. doc_control-0.0.1/tests/ops/test_read.py +716 -0
  125. doc_control-0.0.1/tests/ops/test_rename.py +273 -0
  126. doc_control-0.0.1/tests/ops/test_revisions.py +385 -0
  127. doc_control-0.0.1/tests/ops/test_stylesets.py +457 -0
  128. doc_control-0.0.1/tests/ops/test_tracked_markup.py +1266 -0
  129. doc_control-0.0.1/tests/ops/test_tracked_text.py +448 -0
  130. doc_control-0.0.1/tests/recipes/__init__.py +0 -0
  131. doc_control-0.0.1/tests/recipes/house/recipes/house-author-notes.json +14 -0
  132. doc_control-0.0.1/tests/recipes/house/recipes/house-note-lines.json +7 -0
  133. doc_control-0.0.1/tests/recipes/house/recipes/house-scene-separator.json +7 -0
  134. doc_control-0.0.1/tests/recipes/house/stylesets/house-novel.json +36 -0
  135. doc_control-0.0.1/tests/recipes/test_common_recipes.py +207 -0
  136. doc_control-0.0.1/tests/recipes/test_engine.py +425 -0
  137. doc_control-0.0.1/tests/recipes/test_inventory.py +112 -0
  138. doc_control-0.0.1/tests/recipes/test_user_expressibility.py +318 -0
  139. doc_control-0.0.1/tests/safety/__init__.py +0 -0
  140. doc_control-0.0.1/tests/safety/test_history.py +543 -0
  141. doc_control-0.0.1/tests/safety/test_lock.py +85 -0
  142. doc_control-0.0.1/tests/safety/test_store.py +602 -0
  143. doc_control-0.0.1/tests/safety/test_verify.py +666 -0
  144. doc_control-0.0.1/tests/scenarios/__init__.py +0 -0
  145. doc_control-0.0.1/tests/scenarios/test_writer_notes.py +188 -0
  146. doc_control-0.0.1/tests/test_mcp.py +103 -0
  147. doc_control-0.0.1/tests/test_package.py +37 -0
  148. doc_control-0.0.1/tests/test_registry.py +250 -0
  149. doc_control-0.0.1/tests/test_text_op.py +203 -0
@@ -0,0 +1,41 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv/
6
+ venv/
7
+ build/
8
+ dist/
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ .coverage
13
+ coverage.xml
14
+ htmlcov/
15
+
16
+ # Word / Office temp and lock files
17
+ ~$*
18
+ *.tmp
19
+ .~lock.*#
20
+
21
+ # Editors / OS
22
+ .vscode/
23
+ .idea/
24
+ .DS_Store
25
+ Thumbs.db
26
+
27
+ # Local test documents (never commit real manuscripts)
28
+ /private/
29
+
30
+ # claude-arsenal runtime state
31
+ arsenal/session/surface_profile.json
32
+ arsenal/session/rate_limits.json
33
+ arsenal/session/budget_iterations.json
34
+ arsenal/session/worktree_isolation
35
+ arsenal/session/worktree_isolation.why
36
+ arsenal/session/host_branch
37
+ arsenal/session/rescue_refs
38
+ /.claude/worktrees/
39
+ .claude/skills/*/findings.md
40
+ tmp/*-notes.md
41
+ tmp/.arsenal-sessions/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.5
2
+ Name: doc-control
3
+ Version: 0.0.1
4
+ Summary: Deterministic, LLM-first control of Word documents: addresses, anchors, tracked-change batches and a safety layer.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+
10
+ # doc-control
11
+
12
+ <p align="center">
13
+ <img src="docs/social-preview.png" width="100%" alt="doc-control: let AI agents edit Word documents safely. Deterministic .docx edits, every change a tracked change the writer can reject.">
14
+ </p>
15
+
16
+ > Status: **spec and plan approved** — implementation starting. See `status/specification.md` and `status/plan.md`.
17
+
18
+ A deterministic tool that lets AI agents work on Word documents quickly,
19
+ precisely and safely, ideally live in the Word window the writer has open.
20
+ Every content change is a tracked change the writer can accept or reject.
21
+
22
+ For anyone — writers and editors first — who wants an AI agent's help inside a
23
+ Word document without a single silent change. Nothing to install yet; watch the
24
+ repo for the first release.
25
+
26
+ ## Planned shape
27
+
28
+ - **One core, two engines, one API**
29
+ - *File engine*: edits a closed `.docx` with the Python standard library only,
30
+ rewriting only the parts it touches.
31
+ - *Live engine*: controls the open Word (Windows/COM first, Mac later).
32
+ - **Two front doors**: a CLI with JSON in/out, and an MCP server
33
+ (`doc-control mcp`, stdio) for Claude Desktop / Cowork and other MCP clients.
34
+ - **Safety first**: lock-file and on-disk change detection, backup before every
35
+ write, verification, automatic restore, operation log with undo, and
36
+ `unintended_changes == 0` as a gate.
37
+ - **No AI inside.** Judgment belongs to the agent; approval belongs to the writer.
38
+
39
+ It will replace `docx-fixer`, whose rules become packs built on this tool, and
40
+ serve `literary-critic` as its first downstream consumer.
41
+
42
+ ## MCP server
43
+
44
+ `doc-control mcp` serves every operation as an MCP tool over stdio, one tool per
45
+ operation (`para.move` becomes `para_move`), with the same JSON Schemas and the
46
+ same response envelope as the CLI. It needs nothing beyond the package itself:
47
+
48
+ ```json
49
+ {
50
+ "mcpServers": {
51
+ "doc-control": { "command": "uvx", "args": ["doc-control", "mcp"] }
52
+ }
53
+ }
54
+ ```
55
+
56
+ ## Documents
57
+
58
+ - [Initial research: tooling and risks](docs/research/01-tooling-and-risks.md)
59
+
60
+ ## Development
61
+
62
+ This repo uses [claude-arsenal](https://github.com/nuncaeslupus/claude-arsenal)
63
+ (spec-driven workflow, gated tasks in `arsenal/tasks/`). See `CLAUDE.md`.
64
+
65
+ ## Related projects
66
+
67
+ Same author:
68
+
69
+ - [claude-arsenal](https://github.com/nuncaeslupus/claude-arsenal) — a Claude Code skill and plugin marketplace: specs before code, failing tests first, gates with numbers.
70
+ - [literary-critic](https://github.com/nuncaeslupus/literary-critic) — lets an LLM index, analyse and advise on a full novel manuscript the way a professional editor would; doc-control's first planned consumer.
71
+ - [drawspec](https://github.com/nuncaeslupus/drawspec) — declarative diagram spec → clean, themeable SVG; JSON with no coordinates, so an LLM can write it.
72
+ - [integral-job-search](https://github.com/nuncaeslupus/integral-job-search) — a candidate-centred job search run as a conversation in Claude Code.
73
+
74
+ ## License
75
+
76
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,67 @@
1
+ # doc-control
2
+
3
+ <p align="center">
4
+ <img src="docs/social-preview.png" width="100%" alt="doc-control: let AI agents edit Word documents safely. Deterministic .docx edits, every change a tracked change the writer can reject.">
5
+ </p>
6
+
7
+ > Status: **spec and plan approved** — implementation starting. See `status/specification.md` and `status/plan.md`.
8
+
9
+ A deterministic tool that lets AI agents work on Word documents quickly,
10
+ precisely and safely, ideally live in the Word window the writer has open.
11
+ Every content change is a tracked change the writer can accept or reject.
12
+
13
+ For anyone — writers and editors first — who wants an AI agent's help inside a
14
+ Word document without a single silent change. Nothing to install yet; watch the
15
+ repo for the first release.
16
+
17
+ ## Planned shape
18
+
19
+ - **One core, two engines, one API**
20
+ - *File engine*: edits a closed `.docx` with the Python standard library only,
21
+ rewriting only the parts it touches.
22
+ - *Live engine*: controls the open Word (Windows/COM first, Mac later).
23
+ - **Two front doors**: a CLI with JSON in/out, and an MCP server
24
+ (`doc-control mcp`, stdio) for Claude Desktop / Cowork and other MCP clients.
25
+ - **Safety first**: lock-file and on-disk change detection, backup before every
26
+ write, verification, automatic restore, operation log with undo, and
27
+ `unintended_changes == 0` as a gate.
28
+ - **No AI inside.** Judgment belongs to the agent; approval belongs to the writer.
29
+
30
+ It will replace `docx-fixer`, whose rules become packs built on this tool, and
31
+ serve `literary-critic` as its first downstream consumer.
32
+
33
+ ## MCP server
34
+
35
+ `doc-control mcp` serves every operation as an MCP tool over stdio, one tool per
36
+ operation (`para.move` becomes `para_move`), with the same JSON Schemas and the
37
+ same response envelope as the CLI. It needs nothing beyond the package itself:
38
+
39
+ ```json
40
+ {
41
+ "mcpServers": {
42
+ "doc-control": { "command": "uvx", "args": ["doc-control", "mcp"] }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Documents
48
+
49
+ - [Initial research: tooling and risks](docs/research/01-tooling-and-risks.md)
50
+
51
+ ## Development
52
+
53
+ This repo uses [claude-arsenal](https://github.com/nuncaeslupus/claude-arsenal)
54
+ (spec-driven workflow, gated tasks in `arsenal/tasks/`). See `CLAUDE.md`.
55
+
56
+ ## Related projects
57
+
58
+ Same author:
59
+
60
+ - [claude-arsenal](https://github.com/nuncaeslupus/claude-arsenal) — a Claude Code skill and plugin marketplace: specs before code, failing tests first, gates with numbers.
61
+ - [literary-critic](https://github.com/nuncaeslupus/literary-critic) — lets an LLM index, analyse and advise on a full novel manuscript the way a professional editor would; doc-control's first planned consumer.
62
+ - [drawspec](https://github.com/nuncaeslupus/drawspec) — declarative diagram spec → clean, themeable SVG; JSON with no coordinates, so an LLM can write it.
63
+ - [integral-job-search](https://github.com/nuncaeslupus/integral-job-search) — a candidate-centred job search run as a conversation in Claude Code.
64
+
65
+ ## License
66
+
67
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,70 @@
1
+ [project]
2
+ name = "doc-control"
3
+ version = "0.0.1"
4
+ description = "Deterministic, LLM-first control of Word documents: addresses, anchors, tracked-change batches and a safety layer."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.11"
8
+ dependencies = []
9
+
10
+ [project.scripts]
11
+ doc-control = "doc_control.cli:main"
12
+
13
+ [dependency-groups]
14
+ dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.6", "mypy>=1.11"]
15
+
16
+ [build-system]
17
+ requires = ["hatchling"]
18
+ build-backend = "hatchling.build"
19
+
20
+ [tool.hatch.build.targets.wheel]
21
+ packages = ["src/doc_control"]
22
+
23
+ [tool.hatch.build.targets.sdist]
24
+ # Without this the sdist ships the agent tooling and planning files (.claude, arsenal, status).
25
+ include = ["/src", "/tests"]
26
+
27
+ [tool.ruff]
28
+ line-length = 100
29
+ target-version = "py311"
30
+ extend-exclude = ["claude-arsenal", ".claude", "arsenal"]
31
+
32
+ [tool.ruff.lint]
33
+ select = [
34
+ "E", # pycodestyle errors
35
+ "W", # pycodestyle warnings
36
+ "F", # pyflakes
37
+ "I", # isort
38
+ "UP", # pyupgrade
39
+ "RUF", # ruff-specific
40
+ "B", # flake8-bugbear (real bug patterns)
41
+ "SIM", # flake8-simplify (cleaner equivalents)
42
+ "PTH", # flake8-use-pathlib (prefer Path.open over open)
43
+ ]
44
+
45
+ [tool.ruff.lint.per-file-ignores]
46
+ # The test helpers hold OOXML namespace URIs and content types as long literals.
47
+ "tests/helpers.py" = ["E501"]
48
+ "tests/ops/test_stylesets.py" = ["E501"] # the style-sheet fixture is one long XML literal
49
+
50
+ [tool.mypy]
51
+ python_version = "3.11"
52
+ files = ["src", "tests"]
53
+ warn_return_any = true
54
+ warn_unused_configs = true
55
+ disallow_untyped_defs = true
56
+ disallow_incomplete_defs = true
57
+ check_untyped_defs = true
58
+ warn_redundant_casts = true
59
+ warn_unused_ignores = true
60
+ warn_no_return = true
61
+ show_error_codes = true
62
+
63
+ [tool.pytest.ini_options]
64
+ testpaths = ["tests"]
65
+ # Wall-clock budgets are opt-in (`make bench`); a later `-m bench` overrides this default.
66
+ addopts = "--strict-markers -m 'not bench'"
67
+ markers = [
68
+ "bench: wall-clock performance budgets; run with `make bench` (pytest -m bench)",
69
+ "writes_invalid_docs: the test writes deliberately invalid packages; CI skips them in the OOXML lint",
70
+ ]
@@ -0,0 +1,4 @@
1
+ """doc-control: deterministic, LLM-first control of Word documents."""
2
+
3
+ __version__ = "0.0.1"
4
+ API_VERSION = "1.0"
@@ -0,0 +1,3 @@
1
+ from doc_control.cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,93 @@
1
+ """Command-line front door: `doc-control <op> [--json '<request>' | --json - < request.json]`.
2
+
3
+ `doc-control help <op>` is shorthand for `doc-control help --json '{"op": "<op>"}'`, and
4
+ `--help` / `-h` are aliases of `help`. `doc-control mcp` serves the same operations as an
5
+ MCP server on stdio (see `doc_control.mcp`).
6
+
7
+ Never prompts and never reads stdin unless asked with `--json -`, so an agent whose
8
+ stdin is an open pipe cannot hang it. Prints exactly one JSON envelope on stdout. Exit codes:
9
+ 0 success, 1 operation error, 2 usage error (unknown op or invalid request).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import sys
16
+ from typing import Any
17
+
18
+ from doc_control.envelope import Reply, failure, success
19
+ from doc_control.errors import DocControlError, ErrorCode
20
+ from doc_control.registry import Operation, load_operations
21
+
22
+ _USAGE_CODES = {ErrorCode.SCHEMA_INVALID}
23
+
24
+
25
+ def main(argv: list[str] | None = None) -> int:
26
+ args = sys.argv[1:] if argv is None else argv
27
+ registry = load_operations()
28
+ op = args[0] if args else "help"
29
+ if op == "mcp":
30
+ from doc_control.mcp import serve
31
+
32
+ return serve()
33
+ if op in ("--version", "version"):
34
+ op = "capabilities"
35
+ elif op in ("--help", "-h"):
36
+ op = "help"
37
+ rest = args[1:]
38
+ try:
39
+ if op == "help" and len(rest) == 1 and not rest[0].startswith("-"):
40
+ request: dict[str, Any] = {"op": rest[0]}
41
+ else:
42
+ request = _read_request(rest)
43
+ except DocControlError as err:
44
+ envelope, code = failure(op, err), 2
45
+ else:
46
+ envelope, code = execute(registry, op, request)
47
+ print(json.dumps(envelope, ensure_ascii=False))
48
+ return code
49
+
50
+
51
+ def execute(
52
+ registry: dict[str, Operation], op: str, request: dict[str, Any]
53
+ ) -> tuple[dict[str, Any], int]:
54
+ """Run one operation; return its envelope and the CLI exit code. Never raises."""
55
+ try:
56
+ if op not in registry:
57
+ raise DocControlError(ErrorCode.SCHEMA_INVALID, f"unknown operation: {op}", op=op)
58
+ out = registry[op].run(request)
59
+ if isinstance(out, Reply):
60
+ return success(
61
+ op, out.result, doc=out.doc, warnings=out.warnings, next_cursor=out.next_cursor
62
+ ), 0
63
+ return success(op, out), 0
64
+ except DocControlError as err:
65
+ return failure(op, err), 2 if err.code in _USAGE_CODES else 1
66
+ except Exception as err: # never leak a traceback instead of an envelope
67
+ internal = DocControlError(ErrorCode.INTERNAL, f"{type(err).__name__}: {err}")
68
+ return failure(op, internal), 1
69
+
70
+
71
+ def _read_request(rest: list[str]) -> dict[str, Any]:
72
+ raw: str | None = None
73
+ if rest[:1] == ["--json"]:
74
+ if len(rest) < 2:
75
+ raise DocControlError(ErrorCode.SCHEMA_INVALID, "--json needs a value")
76
+ raw = sys.stdin.read() if rest[1] == "-" else rest[1]
77
+ if len(rest) > 2:
78
+ raise DocControlError(ErrorCode.SCHEMA_INVALID, f"unexpected arguments: {rest[2:]}")
79
+ elif rest:
80
+ raise DocControlError(ErrorCode.SCHEMA_INVALID, f"unexpected arguments: {rest}")
81
+ if not raw or not raw.strip():
82
+ return {}
83
+ try:
84
+ value = json.loads(raw)
85
+ except json.JSONDecodeError as err:
86
+ raise DocControlError(ErrorCode.SCHEMA_INVALID, f"request is not JSON: {err}") from err
87
+ if not isinstance(value, dict):
88
+ raise DocControlError(ErrorCode.SCHEMA_INVALID, "request must be a JSON object")
89
+ return value
90
+
91
+
92
+ if __name__ == "__main__":
93
+ raise SystemExit(main())
@@ -0,0 +1,40 @@
1
+ """The response envelope every operation returns."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any
7
+
8
+ from doc_control import API_VERSION
9
+ from doc_control.errors import DocControlError
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class Reply:
14
+ """What a handler returns when it fills more of the envelope than ``result``."""
15
+
16
+ result: dict[str, Any]
17
+ doc: dict[str, Any] | None = None
18
+ warnings: list[str] = field(default_factory=list)
19
+ next_cursor: str | None = None
20
+
21
+
22
+ def success(
23
+ op: str,
24
+ result: dict[str, Any],
25
+ *,
26
+ doc: dict[str, Any] | None = None,
27
+ warnings: list[str] | None = None,
28
+ next_cursor: str | None = None,
29
+ ) -> dict[str, Any]:
30
+ out: dict[str, Any] = {"api": API_VERSION, "ok": True, "op": op}
31
+ if doc is not None:
32
+ out["doc"] = doc
33
+ out["result"] = result
34
+ out["warnings"] = warnings or []
35
+ out["next"] = next_cursor
36
+ return out
37
+
38
+
39
+ def failure(op: str, error: DocControlError) -> dict[str, Any]:
40
+ return {"api": API_VERSION, "ok": False, "op": op, "error": error.to_dict()}
@@ -0,0 +1,72 @@
1
+ """Stable error codes, each with a one-line hint on what to do next."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from enum import StrEnum
6
+ from typing import Any
7
+
8
+
9
+ class ErrorCode(StrEnum):
10
+ DOC_NOT_FOUND = "DOC_NOT_FOUND"
11
+ NOT_A_DOCX = "NOT_A_DOCX"
12
+ DOC_LOCKED = "DOC_LOCKED"
13
+ DOC_CHANGED_ON_DISK = "DOC_CHANGED_ON_DISK"
14
+ SCHEMA_INVALID = "SCHEMA_INVALID"
15
+ ADDRESS_INVALID = "ADDRESS_INVALID"
16
+ STALE_ADDRESS = "STALE_ADDRESS"
17
+ ANCHOR_NOT_FOUND = "ANCHOR_NOT_FOUND"
18
+ ANCHOR_AMBIGUOUS = "ANCHOR_AMBIGUOUS"
19
+ UNSUPPORTED_CONTENT = "UNSUPPORTED_CONTENT"
20
+ BATCH_CONFLICT = "BATCH_CONFLICT"
21
+ VERIFY_FAILED_RESTORED = "VERIFY_FAILED_RESTORED"
22
+ COMMENT_NOT_FOUND = "COMMENT_NOT_FOUND"
23
+ STYLE_NOT_FOUND = "STYLE_NOT_FOUND"
24
+ STYLE_CONFLICT = "STYLE_CONFLICT"
25
+ RECIPE_INVALID = "RECIPE_INVALID"
26
+ HISTORY_NOT_FOUND = "HISTORY_NOT_FOUND"
27
+ INTERNAL = "INTERNAL"
28
+
29
+
30
+ HINTS: dict[ErrorCode, str] = {
31
+ ErrorCode.DOC_NOT_FOUND: "Check the path; it is resolved relative to the current directory.",
32
+ ErrorCode.NOT_A_DOCX: "Pass a Word .docx file; .doc and other formats are not supported.",
33
+ ErrorCode.DOC_LOCKED: "Word has the file open: save and close it in Word, then retry.",
34
+ ErrorCode.DOC_CHANGED_ON_DISK: "The file changed since you read it: re-read, then retry.",
35
+ ErrorCode.SCHEMA_INVALID: "Run `doc-control help <op>` to see the request schema.",
36
+ ErrorCode.ADDRESS_INVALID: "Use an address from a read result, e.g. p142#a7b2c3d4.",
37
+ ErrorCode.STALE_ADDRESS: "Re-read the paragraph (para.get) or resolve its anchor, then retry.",
38
+ ErrorCode.ANCHOR_NOT_FOUND: "Widen the quote or its context, or search with find.",
39
+ ErrorCode.ANCHOR_AMBIGUOUS: "Pick one of the candidates, or add prefix/suffix context.",
40
+ ErrorCode.UNSUPPORTED_CONTENT: (
41
+ "Edit around fields, hyperlinks or controls; encrypted or ZIP64 packages are not"
42
+ " supported: save a normal copy in Word."
43
+ ),
44
+ ErrorCode.BATCH_CONFLICT: "Split overlapping operations into separate batches.",
45
+ ErrorCode.VERIFY_FAILED_RESTORED: "Nothing was changed; report the request that caused it.",
46
+ ErrorCode.COMMENT_NOT_FOUND: "List comments with comments.list and use an existing id.",
47
+ ErrorCode.STYLE_NOT_FOUND: "List styles with styles.list and use an existing id.",
48
+ ErrorCode.STYLE_CONFLICT: "Rename the style or merge it with style.merge.",
49
+ ErrorCode.RECIPE_INVALID: "Fix the recipe so it only uses the documented keys.",
50
+ ErrorCode.HISTORY_NOT_FOUND: "List history with history.list and use an existing op id.",
51
+ ErrorCode.INTERNAL: "Unexpected error; nothing was written. Report it with the request.",
52
+ }
53
+
54
+
55
+ class DocControlError(Exception):
56
+ """An error with a stable code; the CLI turns it into an error envelope."""
57
+
58
+ def __init__(self, code: ErrorCode, message: str, **details: Any) -> None:
59
+ super().__init__(message)
60
+ self.code = code
61
+ self.message = message
62
+ self.details = details
63
+
64
+ def to_dict(self) -> dict[str, Any]:
65
+ out: dict[str, Any] = {
66
+ "code": self.code.value,
67
+ "message": self.message,
68
+ "hint": HINTS[self.code],
69
+ }
70
+ if self.details:
71
+ out["details"] = self.details
72
+ return out