@superdoc-dev/cli 0.2.0 → 0.3.0-next.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.
- package/README.md +129 -22
- package/dist/index.js +168657 -139061
- package/package.json +8 -8
- package/skill/SKILL.md +78 -27
package/README.md
CHANGED
|
@@ -30,31 +30,112 @@ Stateful editing flow (recommended for multi-step edits):
|
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
superdoc open ./contract.docx
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
# Use query match to find a mutation-grade target
|
|
35
|
+
superdoc query match --select-json '{"type":"text","pattern":"termination"}' --require exactlyOne
|
|
36
|
+
|
|
37
|
+
# Mutate using the returned target
|
|
38
|
+
superdoc replace --target-json '{"kind":"text","blockId":"p1","range":{"start":0,"end":11}}' --text "expiration"
|
|
39
|
+
|
|
35
40
|
superdoc save --in-place
|
|
36
41
|
superdoc close
|
|
37
42
|
```
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
## Choosing the Right Command
|
|
45
|
+
|
|
46
|
+
### Which command should I use?
|
|
47
|
+
|
|
48
|
+
| I want to... | Use this command |
|
|
49
|
+
|--------------|------------------|
|
|
50
|
+
| Find a mutation target (block ID, text range) | `query match` |
|
|
51
|
+
| Search/browse document content | `find` |
|
|
52
|
+
| Insert inline text within a block | `insert` |
|
|
53
|
+
| Create a new standalone paragraph | `create paragraph` |
|
|
54
|
+
| Create a new heading | `create heading` |
|
|
55
|
+
| Insert a list item before/after another list item | `lists insert` |
|
|
56
|
+
| Apply formatting to a text range | `format apply` or format helpers (`format bold`, etc.) |
|
|
57
|
+
| Apply multiple changes in one operation | `mutations apply` |
|
|
58
|
+
|
|
59
|
+
### Mutation targeting workflow
|
|
60
|
+
|
|
61
|
+
Always use `query match` to discover targets before mutating:
|
|
40
62
|
|
|
41
63
|
```bash
|
|
42
|
-
|
|
43
|
-
superdoc
|
|
44
|
-
|
|
64
|
+
# Step 1: Find the target
|
|
65
|
+
superdoc query match --select-json '{"type":"text","pattern":"Introduction"}' --require exactlyOne
|
|
66
|
+
|
|
67
|
+
# Step 2: Use the returned address in a mutation
|
|
68
|
+
superdoc replace --block-id <returned-blockId> --start <start> --end <end> --text "Overview"
|
|
45
69
|
```
|
|
46
70
|
|
|
71
|
+
`find` is for content discovery and inspection. `query match` is for mutation targeting — it returns exact addresses with cardinality guarantees.
|
|
72
|
+
|
|
73
|
+
### Block-oriented editing workflow
|
|
74
|
+
|
|
75
|
+
Use `blocks list` for ordered inspection, then `blocks delete-range` for contiguous removal:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
superdoc open ./contract.docx
|
|
79
|
+
|
|
80
|
+
# 1. Inspect block order, IDs, and text previews
|
|
81
|
+
superdoc blocks list --limit 30
|
|
82
|
+
|
|
83
|
+
# 2. Preview the deletion (no mutation, shows what would be removed)
|
|
84
|
+
superdoc blocks delete-range \
|
|
85
|
+
--start-json '{"kind":"block","nodeType":"paragraph","nodeId":"abc123"}' \
|
|
86
|
+
--end-json '{"kind":"block","nodeType":"paragraph","nodeId":"def456"}' \
|
|
87
|
+
--dry-run
|
|
88
|
+
|
|
89
|
+
# 3. Apply the deletion
|
|
90
|
+
superdoc blocks delete-range \
|
|
91
|
+
--start-json '{"kind":"block","nodeType":"paragraph","nodeId":"abc123"}' \
|
|
92
|
+
--end-json '{"kind":"block","nodeType":"paragraph","nodeId":"def456"}'
|
|
93
|
+
|
|
94
|
+
superdoc save --in-place
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This replaces the pattern of calling `blocks delete` once per block. A 17-block removal becomes one command.
|
|
98
|
+
|
|
99
|
+
### Preview-before-apply workflow
|
|
100
|
+
|
|
101
|
+
Use `--dry-run` and `--expected-revision` for safe, auditable mutations:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
superdoc open ./contract.docx
|
|
105
|
+
|
|
106
|
+
# 1. Check session state
|
|
107
|
+
superdoc status
|
|
108
|
+
|
|
109
|
+
# 2. Find the mutation target
|
|
110
|
+
superdoc query match --select-json '{"type":"text","pattern":"termination"}' --require exactlyOne
|
|
111
|
+
|
|
112
|
+
# 3. Preview the change (validates input, shows what would change, no mutation)
|
|
113
|
+
superdoc replace --block-id p1 --start 0 --end 11 --text "expiration" --dry-run
|
|
114
|
+
|
|
115
|
+
# 4. Apply with revision guard (fails if document changed since preview)
|
|
116
|
+
superdoc replace --block-id p1 --start 0 --end 11 --text "expiration" --expected-revision 1
|
|
117
|
+
|
|
118
|
+
superdoc save --in-place
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Common mistakes
|
|
122
|
+
|
|
123
|
+
1. **Do not use `find` output to construct mutation targets.** `find` returns discovery-grade data, not mutation-grade addresses. Use `query match` instead.
|
|
124
|
+
2. **Do not use `insert --block-id` for sibling block insertion.** `insert` inserts inline text *within* a block. To create a new block adjacent to another, use `create paragraph`, `create heading`, or `lists insert`.
|
|
125
|
+
3. **Do not use `create paragraph` to continue a list.** If you want to add a list item adjacent to existing list items, use `lists insert`. `create paragraph` creates a standalone (non-list) paragraph.
|
|
126
|
+
|
|
47
127
|
## Command Index
|
|
48
128
|
|
|
49
129
|
| Category | Commands |
|
|
50
130
|
|----------|----------|
|
|
51
|
-
| query | `find`, `get-node`, `get-node-by-id`, `info` |
|
|
52
|
-
| mutation | `insert`, `replace`, `delete` |
|
|
53
|
-
| format | `format bold` |
|
|
54
|
-
| create | `create paragraph` |
|
|
55
|
-
| lists | `lists list`, `lists get`, `lists insert`, `lists set-
|
|
56
|
-
| comments | `comments add`, `comments
|
|
131
|
+
| query | `find`, `query match`, `get-node`, `get-node-by-id`, `get-text`, `info` |
|
|
132
|
+
| mutation | `insert`, `replace`, `delete`, `blocks delete`, `blocks delete-range`, `blocks list`, `mutations apply`, `mutations preview` |
|
|
133
|
+
| format | `format apply`, `format bold`, `format italic`, `format underline`, `format strikethrough` |
|
|
134
|
+
| create | `create paragraph`, `create heading`, `create table-of-contents` |
|
|
135
|
+
| lists | `lists list`, `lists get`, `lists insert`, `lists create`, `lists attach`, `lists detach`, `lists join`, `lists separate`, `lists set-level`, `lists indent`, `lists outdent`, `lists set-value`, `lists set-type`, `lists convert-to-text` |
|
|
136
|
+
| comments | `comments add`, `comments reply`, `comments delete`, `comments get`, `comments list` |
|
|
57
137
|
| trackChanges | `track-changes list`, `track-changes get`, `track-changes accept`, `track-changes reject`, `track-changes accept-all`, `track-changes reject-all` |
|
|
138
|
+
| history | `history get`, `history undo`, `history redo` |
|
|
58
139
|
| lifecycle | `open`, `save`, `close` |
|
|
59
140
|
| session | `session list`, `session save`, `session close`, `session set-default`, `session use` |
|
|
60
141
|
| introspection | `status`, `describe`, `describe command` |
|
|
@@ -65,6 +146,7 @@ For full command help and examples, run:
|
|
|
65
146
|
|
|
66
147
|
```bash
|
|
67
148
|
superdoc --help
|
|
149
|
+
superdoc describe command <command-name>
|
|
68
150
|
```
|
|
69
151
|
|
|
70
152
|
## v1 Breaking Changes
|
|
@@ -73,7 +155,7 @@ This CLI replaces the previous `@superdoc-dev/cli` package surface with the v1 c
|
|
|
73
155
|
|
|
74
156
|
| Legacy command | v1 status | Migration |
|
|
75
157
|
|---------------|-----------|-----------|
|
|
76
|
-
| `superdoc replace <find> <to> <files...>` | Renamed to `replace-legacy` | Use `replace-legacy`, or use `
|
|
158
|
+
| `superdoc replace <find> <to> <files...>` | Renamed to `replace-legacy` | Use `replace-legacy`, or use `query match` + `replace --target-json` for the v1 workflow. |
|
|
77
159
|
|
|
78
160
|
Legacy compatibility is retained for `search`, `read`, and `replace-legacy`.
|
|
79
161
|
|
|
@@ -116,7 +198,7 @@ superdoc status
|
|
|
116
198
|
```bash
|
|
117
199
|
superdoc open ./contract.docx
|
|
118
200
|
superdoc status
|
|
119
|
-
superdoc
|
|
201
|
+
superdoc query match --select-json '{"type":"text","pattern":"termination"}' --require exactlyOne
|
|
120
202
|
superdoc replace --target-json '{...}' --text "Updated clause"
|
|
121
203
|
superdoc save --in-place
|
|
122
204
|
superdoc close
|
|
@@ -140,28 +222,45 @@ superdoc session close <sessionId> [--discard]
|
|
|
140
222
|
|
|
141
223
|
```bash
|
|
142
224
|
superdoc info [<doc>]
|
|
143
|
-
superdoc find [<doc>] --type text --pattern "termination"
|
|
144
|
-
superdoc
|
|
225
|
+
superdoc find [<doc>] --type text --pattern "termination" --limit 5
|
|
226
|
+
superdoc query match [<doc>] --select-json '{"type":"text","pattern":"termination"}' --require exactlyOne
|
|
145
227
|
superdoc get-node [<doc>] --address-json '{"kind":"block","nodeType":"paragraph","nodeId":"p1"}'
|
|
146
228
|
superdoc get-node-by-id [<doc>] --id p1 --node-type paragraph
|
|
147
229
|
```
|
|
148
230
|
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
- For text queries, use `
|
|
231
|
+
- `find` returns discovery-grade results for content search and browsing.
|
|
232
|
+
- `query match` returns mutation-grade addresses and text ranges — use this before any mutation.
|
|
233
|
+
- For text queries, use the returned `blocks[].range` as targets for `replace`, `comments add`, and formatting commands.
|
|
152
234
|
|
|
153
235
|
## Mutating commands
|
|
154
236
|
|
|
155
237
|
```bash
|
|
156
|
-
superdoc comments add [<doc>] --target-json '{...}' --text "Please revise" [--out ./with-comment.docx]
|
|
157
238
|
superdoc replace [<doc>] --target-json '{...}' --text "Updated text" [--out ./updated.docx]
|
|
239
|
+
superdoc insert [<doc>] --value "New text" [--out ./inserted.docx]
|
|
240
|
+
superdoc blocks delete [<doc>] --node-type paragraph --node-id abc123
|
|
241
|
+
superdoc blocks delete-range --start-json '{"kind":"block",...}' --end-json '{"kind":"block",...}'
|
|
242
|
+
superdoc create paragraph [<doc>] --text "New paragraph" [--at-json '{"kind":"after","target":{"kind":"block","nodeType":"paragraph","nodeId":"p1"}}']
|
|
243
|
+
superdoc lists insert [<doc>] --node-id li1 --position after --text "New item"
|
|
158
244
|
superdoc format bold [<doc>] --target-json '{...}' [--out ./bolded.docx]
|
|
245
|
+
superdoc comments add [<doc>] --block-id p1 --start 0 --end 10 --text "Please revise" [--out ./with-comment.docx]
|
|
159
246
|
```
|
|
160
247
|
|
|
161
248
|
- In stateless mode (`<doc>` provided), mutating commands require `--out`.
|
|
162
249
|
- In stateful mode (after `open`), mutating commands update the active working document and `--out` is optional.
|
|
250
|
+
- Use `--dry-run` to preview any mutation without applying it.
|
|
163
251
|
- Use `--expected-revision <n>` with stateful mutating commands for optimistic concurrency checks.
|
|
164
252
|
|
|
253
|
+
## Block inspection
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
superdoc blocks list
|
|
257
|
+
superdoc blocks list --limit 20 --offset 10
|
|
258
|
+
superdoc blocks list --node-types-json '["paragraph","heading"]'
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
- Returns ordered block metadata: ordinal, nodeId, nodeType, textPreview, isEmpty.
|
|
262
|
+
- Use the returned nodeIds as targets for `blocks delete`, `blocks delete-range`, or other block-oriented commands.
|
|
263
|
+
|
|
165
264
|
## Low-level invocation
|
|
166
265
|
|
|
167
266
|
```bash
|
|
@@ -208,12 +307,14 @@ superdoc info ./contract.docx --pretty
|
|
|
208
307
|
- `--session <id>`
|
|
209
308
|
- `--timeout-ms <n>`
|
|
210
309
|
- `--help`
|
|
310
|
+
- `--version`, `-v`
|
|
211
311
|
|
|
212
312
|
## Input payload flags
|
|
213
313
|
|
|
214
314
|
- `--query-json`, `--query-file`
|
|
215
315
|
- `--address-json`, `--address-file`
|
|
216
316
|
- `--target-json`, `--target-file`
|
|
317
|
+
- `--at-json`, `--at-file` (for `create paragraph`)
|
|
217
318
|
|
|
218
319
|
## Stdin support
|
|
219
320
|
|
|
@@ -248,8 +349,14 @@ Error:
|
|
|
248
349
|
{
|
|
249
350
|
"ok": false,
|
|
250
351
|
"error": {
|
|
251
|
-
"code": "
|
|
252
|
-
"message": "
|
|
352
|
+
"code": "INVALID_TARGET",
|
|
353
|
+
"message": "Expected paragraph:abc123 but found listItem:abc123.",
|
|
354
|
+
"details": {
|
|
355
|
+
"requestedNodeType": "paragraph",
|
|
356
|
+
"actualNodeType": "listItem",
|
|
357
|
+
"nodeId": "abc123",
|
|
358
|
+
"remediation": "Use lists.insert to add an item to a list sequence."
|
|
359
|
+
}
|
|
253
360
|
},
|
|
254
361
|
"meta": {
|
|
255
362
|
"version": "1.0.0",
|