mdedit-cli 0.1.3 → 0.2.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.
package/skill.md ADDED
@@ -0,0 +1,304 @@
1
+ # mdedit CLI — Agent Skill
2
+
3
+ > Use this skill to manage articles, folders, workspaces, and API keys on [mdedit.ai](https://mdedit.ai) directly from your terminal or from an AI agent.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g mdedit-cli
9
+ ```
10
+
11
+ ## Quick-start authentication
12
+
13
+ ```bash
14
+ # Set your API key (get one at https://docs.mdedit.ai/api-keys)
15
+ mdedit config login --api-key <YOUR_KEY>
16
+
17
+ # Or via environment variable (recommended for CI/agents)
18
+ export MDEDIT_API_KEY=<YOUR_KEY>
19
+ export MDEDIT_WORKSPACE_ID=<YOUR_WORKSPACE_ID> # optional default workspace
20
+ ```
21
+
22
+ ## Agent tips
23
+
24
+ - **Always use `--format json`** when parsing output programmatically: `mdedit article list --format json`
25
+ - **Suppress interactive prompts** by supplying all required flags (title, name, …) on the command line.
26
+ - **Use `-y` / `--yes`** on destructive commands to skip confirmation prompts.
27
+ - **Pipe article content** via stdin using `--file -` or read it back with `--content-only` (stdout).
28
+ - In `json` mode, **human-facing messages go to stderr** (stdout stays machine-parseable).
29
+ - **Exit codes**: `0` = success, `1` = general error, `2` = edit anchor missing,
30
+ `3` = edit anchor ambiguous, `4` = edit conflict. Typed edit errors are JSON on stdout
31
+ in `json` mode; other errors are written to stderr.
32
+
33
+ ## Global flags
34
+
35
+ | Flag | Description |
36
+ |------|-------------|
37
+ | `-F, --format <plain\|table\|json>` | Output format. Use `json` for agents. |
38
+ | `--api-key <key>` | Override API key for this call |
39
+ | `--workspace <workspaceId>` | Override default workspace for this call |
40
+ | `--api-url <url>` | Override API base URL |
41
+ | `--local` | Target local API at `http://localhost:8080` |
42
+ | `--debug` | Print stack traces and request info on errors |
43
+
44
+ ## Commands reference
45
+
46
+ ### config
47
+
48
+ ```bash
49
+ mdedit config show # show current config (api key redacted)
50
+ mdedit config login --api-key <key> # authenticate
51
+ mdedit config logout # remove stored api key
52
+ mdedit config use-workspace <workspaceId> # set default workspace
53
+ mdedit config set <key> <value> # set any config key
54
+ mdedit config clear --yes # wipe all config
55
+ ```
56
+
57
+ ### workspace
58
+
59
+ ```bash
60
+ mdedit workspace list
61
+ mdedit workspace get <workspaceId>
62
+ mdedit workspace create --name "My Workspace" --type user
63
+ mdedit workspace update <workspaceId> --name "New Name"
64
+ mdedit workspace delete <workspaceId> --yes
65
+ ```
66
+
67
+ ### folder
68
+
69
+ ```bash
70
+ mdedit folder list [-w <workspaceId>]
71
+ mdedit folder list --include-deleted
72
+ mdedit folder get <folderId>
73
+ mdedit folder create --name "Drafts" [--parent <parentFolderId>]
74
+ mdedit folder update <folderId> --name "Archive"
75
+ mdedit folder delete <folderId> --yes
76
+ ```
77
+
78
+ ### article
79
+
80
+ ```bash
81
+ # List & filter
82
+ mdedit article list
83
+ mdedit article list --folder <folderId>
84
+ mdedit article list --limit 10 --offset 0
85
+
86
+ # Read
87
+ mdedit article get <articleId>
88
+ mdedit article get <articleId> --content-only # raw markdown to stdout
89
+ mdedit article get <articleId> --include-content # include markdown in output object
90
+ mdedit article get <articleId> --output article.md # save markdown to file
91
+
92
+ # Create
93
+ mdedit article create --title "My Article"
94
+ mdedit article create --title "My Article" --folder <folderId> --file article.md
95
+ mdedit article create --title "My Article" --content "# Hello world"
96
+ echo "# Hello" | mdedit article create --title "My Article" --file -
97
+
98
+ # Update
99
+ mdedit article update <articleId> --title "New Title"
100
+ mdedit article update <articleId> --file updated.md
101
+ mdedit article update <articleId> --content "# Updated"
102
+ cat updated.md | mdedit article update <articleId> --file -
103
+ mdedit article update <articleId> --archive
104
+ mdedit article update <articleId> --pin
105
+
106
+ # One-shot live edit
107
+ mdedit article edit <articleId> --replace "old text" --with "new text"
108
+ mdedit article edit <articleId> --ops-file ops.json --format json
109
+
110
+ # Stream newline-delimited document and review events until interrupted
111
+ mdedit article watch <articleId>
112
+ mdedit article watch <articleId> --agent claude-code --poll-interval 5000
113
+
114
+ # Delete
115
+ mdedit article delete <articleId> --yes
116
+
117
+ # Export
118
+ mdedit article export <articleId> --output article.zip
119
+ ```
120
+
121
+ ## Reviewing and editing documents
122
+
123
+ Reviewer keys should use least-privilege scopes:
124
+
125
+ ```bash
126
+ mdedit apikey create --name "Review agent" --scopes articles:read,reviews:write
127
+ ```
128
+
129
+ All review mutations are server-authored and retry-safe. Suggestions do not change article
130
+ text until accepted; `review accept` therefore requires `articles:write` in addition to the
131
+ reviewer scopes.
132
+
133
+ ```bash
134
+ mdedit review list <articleId> --status open --format json
135
+ mdedit review add <articleId> --quote "some text" --body "This needs a citation."
136
+ mdedit review reply <articleId> --thread <reviewId> --body "Fixed."
137
+ mdedit review resolve <articleId> --thread <reviewId>
138
+ mdedit review reopen <articleId> --thread <reviewId>
139
+ mdedit review accept <articleId> --thread <suggestionId>
140
+ mdedit review reject <articleId> --thread <suggestionId>
141
+ mdedit review delete <articleId> --thread <reviewId>
142
+ mdedit review delete <articleId> --thread <reviewId> --reply <replyId>
143
+ mdedit suggest <articleId> --quote "teh" --replace "the" --note "Typo"
144
+ ```
145
+
146
+ When quoted text repeats, add `--occurrence <n>`, `--before <text>`, or `--after <text>`.
147
+ Use `--target <file.md>` for package targets other than `content.md`.
148
+
149
+ ### api-key
150
+
151
+ ```bash
152
+ mdedit apikey list
153
+ mdedit apikey create --name "CI/CD Key" --description "Used in pipeline" --scopes articles:read,articles:write
154
+ mdedit apikey create --name "30-day key" --expires 30
155
+ mdedit apikey revoke <keyId> --yes
156
+ ```
157
+
158
+ ### utility
159
+
160
+ ```bash
161
+ mdedit health # check API health
162
+ mdedit info # CLI version, API URL, workspace, auth status
163
+ ```
164
+
165
+ ### skill
166
+
167
+ ```bash
168
+ mdedit skill show # print this skill to stdout
169
+ mdedit skill install # install skill into all detected agent tools
170
+ mdedit skill install --target claude # Claude Code: ~/.claude/CLAUDE.md
171
+ mdedit skill install --target cursor # Cursor: .cursor/rules/mdedit.mdc
172
+ mdedit skill install --target codex # GitHub Copilot: .github/copilot-instructions.md
173
+ mdedit skill install --target all # all of the above
174
+ mdedit skill install --global # install globally (home directory targets)
175
+ ```
176
+
177
+ ## Common agent workflows
178
+
179
+ ### Workflow: edit article text directly
180
+
181
+ Use `article edit` for anchored changes so collaborative documents join the live room and
182
+ non-collaborative documents use a conditional REST commit. A simple replacement must match
183
+ exactly once:
184
+
185
+ ```bash
186
+ mdedit article edit <articleId> \
187
+ --replace "The old sentence." \
188
+ --with "The revised sentence." \
189
+ --format json
190
+ ```
191
+
192
+ For context, occurrences, headings, ranges, or multiple sequential edits, pass a non-empty
193
+ JSON array to `--ops-file`:
194
+
195
+ ```json
196
+ [
197
+ {
198
+ "type": "replace",
199
+ "anchor": { "quote": "teh", "occurrence": 2 },
200
+ "text": "the"
201
+ },
202
+ {
203
+ "type": "insert",
204
+ "anchor": { "afterHeading": "## Setup" },
205
+ "text": "\nNew setup note.\n"
206
+ }
207
+ ]
208
+ ```
209
+
210
+ Quote anchors also accept `context: { before, after }`. Other anchors are
211
+ `beforeHeading`, `inSection`, and `range: { from, to }`. On exit `2` or `3`, revise the
212
+ anchor and retry. On exit `4`, the edit may have landed; re-read the article before making
213
+ another change.
214
+
215
+ ### Workflow: react to document and review changes
216
+
217
+ `article watch` writes exactly one JSON object per stdout line. It begins with
218
+ `session.ready`, then emits `article.updated`, `review.event`, and `review.updated`.
219
+ Use the stream as the input to a long-running agent loop and stop it with `SIGINT` or
220
+ `SIGTERM`; the CLI closes the article session before exiting.
221
+
222
+ ```bash
223
+ mdedit article watch <articleId> | while IFS= read -r event; do
224
+ printf '%s\n' "$event" | jq -c '{type, articleId, event}'
225
+ done
226
+ ```
227
+
228
+ ### Workflow: read an article and update its content
229
+
230
+ ```bash
231
+ # Fetch current content
232
+ CONTENT=$(mdedit article get <articleId> --content-only)
233
+
234
+ # Modify $CONTENT with your agent logic, then push it back
235
+ echo "$MODIFIED_CONTENT" | mdedit article update <articleId> --file -
236
+ ```
237
+
238
+ ### Workflow: create a new article in a folder
239
+
240
+ ```bash
241
+ # Find the target folder
242
+ mdedit folder list --format json | jq '.[] | select(.name=="Docs") | .id'
243
+
244
+ # Create article in that folder
245
+ mdedit article create --title "API Reference" --folder <folderId> --file api-ref.md
246
+ ```
247
+
248
+ ### Workflow: bulk export all articles as JSON
249
+
250
+ ```bash
251
+ mdedit article list --format json > articles.json
252
+ ```
253
+
254
+ ### Workflow: set up a fresh environment
255
+
256
+ ```bash
257
+ export MDEDIT_API_KEY=<key>
258
+ mdedit config login --api-key "$MDEDIT_API_KEY"
259
+ # list workspaces and set the default
260
+ mdedit workspace list --format json
261
+ mdedit config use-workspace <workspaceId>
262
+ ```
263
+
264
+ ## Environment variables
265
+
266
+ | Variable | Description |
267
+ |----------|-------------|
268
+ | `MDEDIT_API_KEY` | API key (overrides stored config) |
269
+ | `MDEDIT_API_URL` | API base URL (default: `https://apiv2.mdedit.ai`) |
270
+ | `MDEDIT_WORKSPACE_ID` | Default workspace ID |
271
+ | `MDEDIT_CONFIG_DIR` | Override config directory (default: `~/.mdedit-cli`) |
272
+ | `MDEDIT_DEBUG` | Set to `1` to enable debug output |
273
+
274
+ ## Output format guide
275
+
276
+ | Format | Best for |
277
+ |--------|----------|
278
+ | `table` | Humans scanning many rows (default) |
279
+ | `plain` | Human reading (object details) |
280
+ | `json` | Agents, scripts, piping to `jq` |
281
+
282
+ Use `--format json` globally: `mdedit <command> --format json`.
283
+ In `json` mode all human-readable messages go to **stderr** so stdout stays machine-parseable.
284
+
285
+ ## Error handling
286
+
287
+ General errors write a descriptive message to **stderr** and exit with code `1`.
288
+ Typed `article edit` failures use these stable codes:
289
+
290
+ | Exit | Error code | Meaning |
291
+ |------|------------|---------|
292
+ | 2 | `ANCHOR_NOT_FOUND` | No anchor match; nothing was applied |
293
+ | 3 | `AMBIGUOUS_ANCHOR` | Multiple matches; add occurrence or context |
294
+ | 4 | `EDIT_CONFLICT` | Concurrent edits overlapped or a conditional commit raced |
295
+
296
+ Common errors and fixes:
297
+
298
+ | HTTP | Meaning | Fix |
299
+ |------|---------|-----|
300
+ | 401 | Unauthenticated | Run `mdedit config login --api-key <key>` |
301
+ | 403 | Forbidden | Check API key workspace permissions |
302
+ | 404 | Not found | Verify IDs and `--api-url` |
303
+
304
+ Add `--debug` to print full stack traces.