@superdoc-dev/cli 0.1.1-next.1 → 1.0.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.
Files changed (5) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +228 -37
  3. package/dist/index.js +233590 -174815
  4. package/package.json +39 -17
  5. package/skill/SKILL.md +45 -0
package/README.md CHANGED
@@ -1,71 +1,262 @@
1
1
  # @superdoc-dev/cli
2
2
 
3
- The command-line interface for [SuperDoc](https://superdoc.dev) DOCX editing in your terminal.
3
+ LLM-first CLI for deterministic DOCX operations through SuperDoc's Document API.
4
+
5
+ ## Install
4
6
 
5
7
  ```bash
6
- npx @superdoc-dev/cli search "CONFIDENTIAL" ./legal/*.docx
8
+ npm install -g @superdoc-dev/cli
7
9
  ```
8
10
 
9
- ## Commands
11
+ The package automatically installs a native binary for your platform via optionalDependencies. Supported platforms:
10
12
 
11
- | Command | Status | Description |
12
- |---------|--------|-------------|
13
- | `search` | Available | Find text across documents |
14
- | `replace` | Available | Find and replace text |
15
- | `replace --track` | Coming soon | Replace with track changes |
16
- | `read` | Available | Extract plain text |
17
- | `diff` | Coming soon | Compare two documents |
18
- | `convert` | Coming soon | DOCX ↔ HTML ↔ Markdown |
19
- | `comments` | Coming soon | List, add, resolve comments |
20
- | `accept` | Coming soon | Accept/reject track changes |
13
+ | Platform | Package |
14
+ |----------|---------|
15
+ | macOS (Apple Silicon) | `@superdoc-dev/cli-darwin-arm64` |
16
+ | macOS (Intel) | `@superdoc-dev/cli-darwin-x64` |
17
+ | Linux (x64) | `@superdoc-dev/cli-linux-x64` |
18
+ | Linux (ARM64) | `@superdoc-dev/cli-linux-arm64` |
19
+ | Windows (x64) | `@superdoc-dev/cli-windows-x64` |
21
20
 
22
- Powered by the SuperDoc document engine. Bulk operations, glob patterns, JSON output.
23
-
24
- ## Install
21
+ ## Usage
25
22
 
26
23
  ```bash
27
- npm install -g @superdoc-dev/cli
24
+ superdoc <command> [options]
28
25
  ```
29
26
 
30
- Or run directly:
27
+ ## Getting Started
28
+
29
+ Stateful editing flow (recommended for multi-step edits):
31
30
 
32
31
  ```bash
33
- npx @superdoc-dev/cli <command>
32
+ superdoc open ./contract.docx
33
+ superdoc find --type text --pattern "termination"
34
+ superdoc replace --target-json '{"blockId":"p1","range":{"start":0,"end":11}}' --text "expiration"
35
+ superdoc save --in-place
36
+ superdoc close
34
37
  ```
35
38
 
36
- ## Usage
39
+ Legacy compatibility commands (v0.x behavior):
37
40
 
38
41
  ```bash
39
- # Search across documents
40
42
  superdoc search "indemnification" ./contracts/*.docx
43
+ superdoc replace-legacy "ACME Corp" "Globex Inc" ./merger/*.docx
44
+ superdoc read ./proposal.docx
45
+ ```
41
46
 
42
- # Find and replace
43
- superdoc replace "ACME Corp" "Globex Inc" ./merger/*.docx
47
+ ## Command Index
44
48
 
45
- # Extract text
46
- superdoc read ./proposal.docx
49
+ | Category | Commands |
50
+ |----------|----------|
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-type`, `lists indent`, `lists outdent`, `lists restart`, `lists exit` |
56
+ | comments | `comments add`, `comments edit`, `comments reply`, `comments move`, `comments resolve`, `comments remove`, `comments set-internal`, `comments set-active`, `comments go-to`, `comments get`, `comments list` |
57
+ | trackChanges | `track-changes list`, `track-changes get`, `track-changes accept`, `track-changes reject`, `track-changes accept-all`, `track-changes reject-all` |
58
+ | lifecycle | `open`, `save`, `close` |
59
+ | session | `session list`, `session save`, `session close`, `session set-default`, `session use` |
60
+ | introspection | `status`, `describe`, `describe command` |
61
+ | low-level | `call <operationId>` |
62
+ | legacy compat | `search`, `replace-legacy <find> <to> <files...>`, `read` |
63
+
64
+ For full command help and examples, run:
65
+
66
+ ```bash
67
+ superdoc --help
68
+ ```
69
+
70
+ ## v1 Breaking Changes
71
+
72
+ This CLI replaces the previous `@superdoc-dev/cli` package surface with the v1 contract-driven command set.
73
+
74
+ | Legacy command | v1 status | Migration |
75
+ |---------------|-----------|-----------|
76
+ | `superdoc replace <find> <to> <files...>` | Renamed to `replace-legacy` | Use `replace-legacy`, or use `find` + `replace --target-json` for the v1 workflow. |
77
+
78
+ Legacy compatibility is retained for `search`, `read`, and `replace-legacy`.
79
+
80
+ ## Normative Policy
81
+
82
+ - Canonical contract/version metadata comes from `@superdoc/document-api` (`CONTRACT_VERSION`, operation metadata, and schemas).
83
+ - This README is usage guidance for CLI consumers.
84
+ - If guidance here conflicts with `superdoc describe`/`describe command` output or document-api contract exports, those are authoritative.
85
+
86
+ ## Host mode (stdio JSON-RPC)
87
+
88
+ ```bash
89
+ superdoc host --stdio
90
+ ```
91
+
92
+ - Starts a persistent JSON-RPC 2.0 host over newline-delimited stdio frames.
93
+ - Intended for SDK/runtime integrations that need long-lived command execution in a single process.
94
+ - Supported methods:
95
+ - `host.ping`
96
+ - `host.capabilities`
97
+ - `host.describe`
98
+ - `host.describe.command` (requires `params.operationId`)
99
+ - `host.shutdown`
100
+ - `cli.invoke` (executes canonical CLI command semantics)
101
+
102
+ ## API introspection commands
103
+
104
+ ```bash
105
+ superdoc describe
106
+ superdoc describe command doc.find
107
+ superdoc status
108
+ ```
109
+
110
+ - `describe` returns contract + protocol metadata and the operation catalog.
111
+ - `describe command <operationId>` returns one operation definition (inputs, response schema, errors, examples).
112
+ - `status` shows current session status and document metadata.
113
+
114
+ ## Stateful session commands
115
+
116
+ ```bash
117
+ superdoc open ./contract.docx
118
+ superdoc status
119
+ superdoc find --type text --pattern "termination"
120
+ superdoc replace --target-json '{...}' --text "Updated clause"
121
+ superdoc save --in-place
122
+ superdoc close
123
+ ```
124
+
125
+ - `open` creates a new session id automatically unless `--session <id>` is provided.
126
+ - If `<doc>` is omitted, commands run against the active default session.
127
+ - Explicit `<doc>` (or `--doc`) always runs in stateless mode and does not use session state.
128
+
129
+ ## Session management
130
+
131
+ ```bash
132
+ superdoc session list
133
+ superdoc session save <sessionId> [--in-place] [--out <path>] [--force]
134
+ superdoc session set-default <sessionId>
135
+ superdoc session use <sessionId>
136
+ superdoc session close <sessionId> [--discard]
137
+ ```
138
+
139
+ ## Read / locate commands
140
+
141
+ ```bash
142
+ superdoc info [<doc>]
143
+ superdoc find [<doc>] --type text --pattern "termination"
144
+ superdoc find [<doc>] --type run
145
+ superdoc get-node [<doc>] --address-json '{"kind":"block","nodeType":"paragraph","nodeId":"p1"}'
146
+ superdoc get-node-by-id [<doc>] --id p1 --node-type paragraph
147
+ ```
148
+
149
+ - Flat `find` flags are convenience syntax and are normalized into the canonical query object used by `editor.doc.find`.
150
+ - Use `--query-json` / `--query-file` for complex or programmatic queries.
151
+ - For text queries, use `result.context[*].textRanges[*]` as targets for `replace`, `comments add`, and formatting commands.
152
+
153
+ ## Mutating commands
154
+
155
+ ```bash
156
+ superdoc comments add [<doc>] --target-json '{...}' --text "Please revise" [--out ./with-comment.docx]
157
+ superdoc replace [<doc>] --target-json '{...}' --text "Updated text" [--out ./updated.docx]
158
+ superdoc format bold [<doc>] --target-json '{...}' [--out ./bolded.docx]
159
+ ```
160
+
161
+ - In stateless mode (`<doc>` provided), mutating commands require `--out`.
162
+ - In stateful mode (after `open`), mutating commands update the active working document and `--out` is optional.
163
+ - Use `--expected-revision <n>` with stateful mutating commands for optimistic concurrency checks.
164
+
165
+ ## Low-level invocation
47
166
 
48
- # JSON output for scripting
49
- superdoc search "Article 7" ./**/*.docx --json
167
+ ```bash
168
+ superdoc call <operationId> --input-json '{...}'
50
169
  ```
51
170
 
52
- ## Options
171
+ - Invokes any document-api operation directly with a JSON payload.
172
+
173
+ ## Save command modes
53
174
 
54
- | Flag | Description |
55
- |------|-------------|
56
- | `--json` | Machine-readable output |
57
- | `--help` | Show help |
175
+ ```bash
176
+ superdoc save --in-place
177
+ superdoc save --out ./final.docx
178
+ ```
58
179
 
59
- ## AI Integration
180
+ - `save` persists the active session but keeps it open for more edits.
181
+ - If no source path exists (for example stdin-opened docs), `save` requires `--out <path>`.
182
+ - `save --in-place` checks for source-file drift and refuses overwrite unless `--force` is passed.
60
183
 
61
- Works with AI coding assistants. Copy the skill file so Claude Code, Cursor, etc. know to use `superdoc` for DOCX operations instead of python-docx.
184
+ ## Close command modes
62
185
 
63
186
  ```bash
64
- # Copy skill to Claude Code
65
- cp -r skills/superdoc ~/.claude/skills/
187
+ superdoc close
188
+ superdoc close --discard
66
189
  ```
67
190
 
68
- See [`skills/superdoc/SKILL.md`](../../skills/superdoc/SKILL.md) for the skill definition.
191
+ - Dirty contexts require explicit `--discard` (or run `save` first, then `close`).
192
+
193
+ ## Output modes
194
+
195
+ - Default: `--output json` (machine-oriented envelope)
196
+ - Human mode: `--output pretty` (or `--pretty`)
197
+
198
+ ```bash
199
+ superdoc info ./contract.docx --output json
200
+ superdoc info ./contract.docx --pretty
201
+ ```
202
+
203
+ ## Global flags
204
+
205
+ - `--output <json|pretty>`
206
+ - `--json`
207
+ - `--pretty`
208
+ - `--session <id>`
209
+ - `--timeout-ms <n>`
210
+ - `--help`
211
+
212
+ ## Input payload flags
213
+
214
+ - `--query-json`, `--query-file`
215
+ - `--address-json`, `--address-file`
216
+ - `--target-json`, `--target-file`
217
+
218
+ ## Stdin support
219
+
220
+ Use `-` as `<doc>` to read DOCX bytes from stdin:
221
+
222
+ ```bash
223
+ cat ./contract.docx | superdoc open -
224
+ cat ./contract.docx | superdoc info -
225
+ ```
226
+
227
+ ## JSON envelope contract
228
+
229
+ Normative operation/version metadata comes from `@superdoc/document-api`; use `superdoc describe` for the runtime contract surface.
230
+
231
+ Success:
232
+
233
+ ```json
234
+ {
235
+ "ok": true,
236
+ "command": "find",
237
+ "data": {},
238
+ "meta": {
239
+ "version": "1.0.0",
240
+ "elapsedMs": 42
241
+ }
242
+ }
243
+ ```
244
+
245
+ Error:
246
+
247
+ ```json
248
+ {
249
+ "ok": false,
250
+ "error": {
251
+ "code": "VALIDATION_ERROR",
252
+ "message": "..."
253
+ },
254
+ "meta": {
255
+ "version": "1.0.0",
256
+ "elapsedMs": 8
257
+ }
258
+ }
259
+ ```
69
260
 
70
261
  ## Part of SuperDoc
71
262