@@ -5,7 +5,7 @@ description: Edit, query, and transform Word documents with the SuperDoc CLI v1
55
66# SuperDoc CLI (v1)
77
8- Use SuperDoc CLI for DOCX work. Prefer canonical v1 commands.
8+ Use SuperDoc CLI for DOCX work. Use v1 commands (canonical operations and their helper wrappers) .
99Do not default to legacy commands unless explicitly needed for v0-style bulk workflows.
1010
1111Use ` superdoc ` if installed, or ` npx @superdoc-dev/cli@latest ` as a fallback.
@@ -28,12 +28,13 @@ Use `describe command` for per-command args and constraints.
2828
2929``` bash
3030superdoc open ./contract.docx
31- superdoc find --type text -- pattern " termination"
31+ superdoc query match --select-json ' {"type":" text"," pattern":" termination"} ' --require exactlyOne
3232superdoc replace --target-json ' {"kind":"text","blockId":"p1","range":{"start":0,"end":11}}' --text " expiration"
3333superdoc save --in-place
3434superdoc close
3535```
3636
37+ - Always use ` query match ` (not ` find ` ) to discover mutation targets — it returns exact addresses with cardinality guarantees.
3738- After ` open ` , commands run against the active/default session when ` <doc> ` is omitted.
3839- Use ` superdoc session list|set-default|save|close ` for explicit session control.
3940- ` close ` on dirty state requires ` --discard ` or a prior ` save ` .
@@ -57,28 +58,80 @@ superdoc replace ./proposal.docx \
5758
5859- In stateless mode (` <doc> ` provided), mutating commands require ` --out ` unless using ` --dry-run ` .
5960
61+ ### Safety: preview before apply
62+
63+ - Use ` --dry-run ` to preview any mutation without applying it.
64+ - Use ` --expected-revision <n> ` with stateful mutations for optimistic concurrency checks.
65+
6066## Common v1 Commands
6167
62- - Search text/nodes: ` find --type text --pattern "..." ` or ` find --query-json '{...}' `
63- - Replace text: ` replace --target-json '{...}' --text "..." `
64- - Add/edit comments: ` comments add|reply|edit|resolve|remove `
65- - Review tracked changes: ` track-changes list|accept|reject|accept-all|reject-all `
68+ ### Query & inspect
69+
70+ - Search/browse content: ` find --type text --pattern "..." ` or ` find --query-json '{...}' `
71+ - Find mutation target: ` query match --select-json '{...}' --require exactlyOne `
72+ - Inspect blocks: ` blocks list ` , ` get-node ` , ` get-node-by-id `
6673- Extract content: ` get-text ` , ` get-markdown ` , ` get-html `
67- - Low-level direct invoke: ` call <operationId> --input-json '{...}' `
74+
75+ ### Mutate
76+
77+ - Replace text: ` replace --target-json '{...}' --text "..." `
78+ - Insert inline text: ` insert --block-id <id> --offset <n> --value "..." `
79+ - Delete text/node: ` delete --target-json '{...}' `
80+ - Delete blocks: ` blocks delete ` , ` blocks delete-range `
81+ - Batch mutations: ` mutations apply --steps-json '[...]' --atomic true --change-mode direct `
82+ - Create paragraph: ` create paragraph --text "..." ` (with optional ` --at-json ` )
83+ - Create heading: ` create heading --input-json '{"level":<n>,"text":"..."}' `
84+
85+ ### Format
86+
87+ - Apply formatting: ` format apply --block-id <id> --start <n> --end <n> --inline-json '{"bold":true}' `
88+ - Shortcuts: ` format bold ` , ` format italic ` , ` format underline ` , ` format strikethrough `
89+
90+ ### Lists
91+
92+ - List items: ` lists list ` , ` lists get `
93+ - Insert list item: ` lists insert --node-id <id> --position after --text "..." `
94+ - Modify: ` lists indent ` , ` lists outdent ` , ` lists set-level ` , ` lists set-type ` , ` lists convert-to-text `
95+
96+ ### Comments
97+
98+ - Add/reply: ` comments add ` , ` comments reply `
99+ - Read: ` comments get ` , ` comments list `
100+ - Edit/resolve/move: ` comments edit ` , ` comments resolve ` , ` comments move ` , ` comments set-internal `
101+ - Delete: ` comments delete ` (canonical) or ` comments remove ` (alias)
102+
103+ ### Track changes
104+
105+ - List: ` track-changes list ` , ` track-changes get `
106+ - Decide: ` track-changes accept ` , ` track-changes reject ` , ` track-changes accept-all ` , ` track-changes reject-all `
107+
108+ ### History
109+
110+ - ` history get ` , ` history undo ` , ` history redo `
111+
112+ ### Low-level
113+
114+ - Direct invoke: ` call <operationId> --input-json '{...}' ` (JSON output only — ` --pretty ` is not supported)
68115
69116## JSON/File Payload Flags
70117
71- Use one of each pair (not both):
118+ Not all ` --*-file ` variants are available on every command. Use ` describe command <name> ` to check.
119+
120+ Always supported alongside their ` -json ` counterpart (use one, not both):
121+
122+ | Flag pair | Available on |
123+ | -----------| -------------|
124+ | ` --query-json ` / ` --query-file ` | ` find ` , ` lists list ` |
125+ | ` --address-json ` / ` --address-file ` | ` get-node ` , ` lists get ` |
126+ | ` --input-json ` / ` --input-file ` | ` call ` , ` create paragraph ` |
127+ | ` --at-json ` / ` --at-file ` | ` create paragraph ` |
72128
73- - ` --query-json ` or ` --query-file `
74- - ` --target-json ` or ` --target-file `
75- - ` --address-json ` or ` --address-file `
76- - ` --input-json ` or ` --input-file ` (for ` call ` )
129+ ` --target-json ` is widely available on mutation commands but has ** no** ` --target-file ` counterpart. Use flat flags (` --block-id ` , ` --start ` , ` --end ` ) as an alternative to ` --target-json ` .
77130
78131## Output and Global Flags
79132
80133- Default output is JSON envelope.
81- - Use ` --pretty ` for human-readable output.
134+ - Use ` --pretty ` for human-readable output (not supported by ` call ` ) .
82135- Global flags: ` --output <json|pretty> ` , ` --session <id> ` , ` --timeout-ms <n> ` .
83136- ` <doc> ` can be ` - ` to read DOCX bytes from stdin.
84137
0 commit comments