@bestend/confluence-cli 1.16.0 → 2.0.0

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # Confluence CLI
2
2
 
3
+ > **Fork**: [`@bestend/confluence-cli`](https://github.com/bestend/confluence-cli) — forked from [`pchuri/confluence-cli`](https://github.com/pchuri/confluence-cli) (based on upstream v1.27.1)
4
+
3
5
  A powerful command-line interface for Atlassian Confluence that allows you to read, search, and manage your Confluence content from the terminal.
4
6
 
5
7
  ## Features
@@ -11,23 +13,69 @@ A powerful command-line interface for Atlassian Confluence that allows you to re
11
13
  - ✏️ **Create pages** - Create new pages with support for Markdown, HTML, or Storage format
12
14
  - 📝 **Update pages** - Update existing page content and titles
13
15
  - 🗑️ **Delete pages** - Delete (or move to trash) pages by ID or URL
14
- - 📎 **Attachments** - List or download page attachments
16
+ - 📎 **Attachments** - List, download, upload, or delete page attachments
17
+ - 🏷️ **Properties** - List, get, set, and delete content properties (key-value metadata)
15
18
  - 💬 **Comments** - List, create, and delete page comments (footer or inline)
16
19
  - 📦 **Export** - Save a page and its attachments to a local folder
17
20
  - 🛠️ **Edit workflow** - Export page content for editing and re-import
21
+ - 🔀 **Profiles** - Manage multiple Confluence instances with named configuration profiles
22
+ - 🔒 **Read-only mode** - Profile-level write protection for safe AI agent usage
18
23
  - 🔧 **Easy setup** - Simple configuration with environment variables or interactive setup
19
24
 
25
+ ## Fork-specific Features
26
+
27
+ This fork adds the following features on top of upstream:
28
+
29
+ ### Context Path Auto-detection
30
+
31
+ Upstream hardcodes `/wiki` as the context path, which breaks on Confluence Server/Data Center instances with custom context paths (or no context path). This fork auto-detects the context path from the `_links.context` field in API responses.
32
+
33
+ ### Storage Format Sanitization & XML Validation
34
+
35
+ - **`--sanitize-storage`** (default: on) — Auto-escapes raw `&` characters to `&` before sending, preventing XML parse errors
36
+ - **`--validate-storage`** — Optionally validates storage content as well-formed XML before sending, with line/column error reporting via `fast-xml-parser`
37
+
38
+ ### `create --parent` Option
39
+
40
+ Create a child page directly with `--parent <pageId>` on the `create` command, without needing the separate `create-child` command.
41
+
42
+ ```bash
43
+ confluence create "Child Page" SPACEKEY --parent 12345 -c "Content here"
44
+ ```
45
+
46
+ ### Spaces URL Parsing
47
+
48
+ Supports `/spaces/SPACEKEY/pages/ID/Title` URL format in addition to upstream's `/pages/ID` pattern.
49
+
50
+ ### `<hr/>` Tag Removal
51
+
52
+ Removes `<hr/>` tags from Confluence storage format output during markdown conversion, since Confluence does not use horizontal rules.
53
+
20
54
  ## Installation
21
55
 
56
+ ### npm
57
+
22
58
  ```bash
23
- npm install -g @bestend/confluence-cli@1.15.2
59
+ npm install -g @bestend/confluence-cli
24
60
  ```
25
61
 
26
62
  Or run directly with npx:
27
63
  ```bash
28
- npx @bestend/confluence-cli@1.15.2
64
+ npx @bestend/confluence-cli
65
+ ```
66
+
67
+ ## Claude Code AI Skills
68
+
69
+ If you use [Claude Code](https://claude.ai/code) or any AI agent that reads `.claude/skills/`, install the skill documentation so the agent understands all confluence-cli commands automatically.
70
+
71
+ Run this from your project root after installing confluence-cli:
72
+
73
+ ```bash
74
+ confluence install-skill
29
75
  ```
30
76
 
77
+ This creates `.claude/skills/confluence/SKILL.md` in your current directory. Claude Code picks it up automatically and can help you with any confluence-cli command.
78
+
31
79
  ## Quick Start
32
80
 
33
81
  1. **Initialize configuration:**
@@ -67,7 +115,7 @@ npx @bestend/confluence-cli@1.15.2
67
115
  confluence init
68
116
  ```
69
117
 
70
- The wizard helps you choose the right API endpoint and authentication method. It recommends `/wiki/rest/api` for Atlassian Cloud domains (e.g., `*.atlassian.net`) and `/rest/api` for self-hosted/Data Center instances, then prompts for Basic (email + token) or Bearer authentication.
118
+ The wizard helps you choose the right API endpoint and authentication method. It recommends `/wiki/rest/api` for Atlassian Cloud domains (e.g., `*.atlassian.net`) and `/rest/api` for self-hosted/Data Center instances, then prompts for Basic (email/username + token/password) or Bearer authentication.
71
119
 
72
120
  ### Option 2: Non-interactive Setup (CLI Flags)
73
121
 
@@ -83,6 +131,26 @@ confluence init \
83
131
  --token "your-api-token"
84
132
  ```
85
133
 
134
+ **Scoped API token** (recommended for agents — least privilege):
135
+ ```bash
136
+ # Replace <your-cloud-id> with your actual Cloud ID
137
+ confluence init \
138
+ --domain "api.atlassian.com" \
139
+ --api-path "/ex/confluence/<your-cloud-id>/wiki/rest/api" \
140
+ --auth-type "basic" \
141
+ --email "user@example.com" \
142
+ --token "your-scoped-token"
143
+ ```
144
+
145
+ **Named profile** (save to a specific profile):
146
+ ```bash
147
+ confluence --profile staging init \
148
+ --domain "staging.example.com" \
149
+ --api-path "/rest/api" \
150
+ --auth-type "bearer" \
151
+ --token "your-personal-access-token"
152
+ ```
153
+
86
154
  **Hybrid mode** (some fields provided, rest via prompts):
87
155
  ```bash
88
156
  # Domain and token provided, will prompt for auth method and email
@@ -96,30 +164,62 @@ confluence init --email "user@example.com" --token "your-api-token"
96
164
  - `-d, --domain <domain>` - Confluence domain (e.g., `company.atlassian.net`)
97
165
  - `-p, --api-path <path>` - REST API path (e.g., `/wiki/rest/api`)
98
166
  - `-a, --auth-type <type>` - Authentication type: `basic` or `bearer`
99
- - `-e, --email <email>` - Email for basic authentication
100
- - `-t, --token <token>` - API token
167
+ - `-e, --email <email>` - Email or username for basic authentication
168
+ - `-t, --token <token>` - API token or password
169
+ - `--read-only` - Enable read-only mode (blocks all write operations)
101
170
 
102
171
  ⚠️ **Security note:** While flags work, storing tokens in shell history is risky. Prefer environment variables (Option 3) for production environments.
103
172
 
104
173
  ### Option 3: Environment Variables
105
174
  ```bash
106
175
  export CONFLUENCE_DOMAIN="your-domain.atlassian.net"
107
- export CONFLUENCE_API_TOKEN="your-api-token"
108
- export CONFLUENCE_EMAIL="your.email@example.com" # required when using basic auth
176
+ export CONFLUENCE_API_TOKEN="your-api-token" # or password for on-premise (alias: CONFLUENCE_PASSWORD)
177
+ export CONFLUENCE_EMAIL="your.email@example.com" # required for basic auth (alias: CONFLUENCE_USERNAME for on-premise)
109
178
  export CONFLUENCE_API_PATH="/wiki/rest/api" # Cloud default; use /rest/api for Server/DC
110
179
  # Optional: set to 'bearer' for self-hosted/Data Center instances
111
180
  export CONFLUENCE_AUTH_TYPE="basic"
181
+ # Optional: select a named profile (overridden by --profile flag)
182
+ export CONFLUENCE_PROFILE="default"
183
+ ```
184
+
185
+ **Scoped API token** (recommended for agents):
186
+ ```bash
187
+ export CONFLUENCE_DOMAIN="api.atlassian.com"
188
+ export CONFLUENCE_API_PATH="/ex/confluence/<your-cloud-id>/wiki/rest/api"
189
+ export CONFLUENCE_AUTH_TYPE="basic"
190
+ export CONFLUENCE_EMAIL="user@example.com"
191
+ export CONFLUENCE_API_TOKEN="your-scoped-token"
112
192
  ```
113
193
 
114
194
  `CONFLUENCE_API_PATH` defaults to `/wiki/rest/api` for Atlassian Cloud domains and `/rest/api` otherwise. Override it when your site lives under a custom reverse proxy or on-premises path. `CONFLUENCE_AUTH_TYPE` defaults to `basic` when an email is present and falls back to `bearer` otherwise.
115
195
 
196
+ **Read-only mode** (recommended for AI agents):
197
+ ```bash
198
+ export CONFLUENCE_READ_ONLY=true
199
+ ```
200
+ When set, all write operations (`create`, `update`, `delete`, etc.) are blocked at the CLI level. The environment variable overrides the profile's `readOnly` setting.
201
+
116
202
  ### Getting Your API Token
117
203
 
204
+ **Atlassian Cloud:**
118
205
  1. Go to [Atlassian Account Settings](https://id.atlassian.com/manage-profile/security/api-tokens)
119
206
  2. Click "Create API token"
120
207
  3. Give it a label (e.g., "confluence-cli")
121
208
  4. Copy the generated token
122
209
 
210
+ **Atlassian Cloud — Scoped API Token** (recommended for agents and automation):
211
+
212
+ Scoped tokens restrict access to specific Atlassian products and permissions, following the principle of least privilege. They use a different API gateway (`api.atlassian.com`) instead of your site domain.
213
+
214
+ 1. Create a scoped token in your [Atlassian Admin settings](https://admin.atlassian.com)
215
+ 2. Find your Cloud ID by visiting `https://<your-site>.atlassian.net/_edge/tenant_info`
216
+ 3. Configure with:
217
+ - **Domain:** `api.atlassian.com`
218
+ - **API path:** `/ex/confluence/<your-cloud-id>/wiki/rest/api`
219
+ - **Auth type:** `basic` (email + scoped token)
220
+
221
+ **On-premise / Data Center:** Use your Confluence username and password for basic authentication.
222
+
123
223
  ## Usage
124
224
 
125
225
  ### Read a Page
@@ -160,6 +260,48 @@ confluence attachments 123456789 --pattern "*.png" --limit 5
160
260
  confluence attachments 123456789 --pattern "*.png" --download --dest ./downloads
161
261
  ```
162
262
 
263
+ ### Upload Attachments
264
+ ```bash
265
+ # Upload a single attachment
266
+ confluence attachment-upload 123456789 --file ./report.pdf
267
+
268
+ # Upload multiple files with a comment
269
+ confluence attachment-upload 123456789 --file ./a.pdf --file ./b.png --comment "v2"
270
+
271
+ # Replace an existing attachment by filename
272
+ confluence attachment-upload 123456789 --file ./diagram.png --replace
273
+ ```
274
+
275
+ ### Delete Attachments
276
+ ```bash
277
+ # Delete an attachment by ID
278
+ confluence attachment-delete 123456789 998877
279
+
280
+ # Skip confirmation
281
+ confluence attachment-delete 123456789 998877 --yes
282
+ ```
283
+
284
+ ### Content Properties
285
+ ```bash
286
+ # List all properties on a page
287
+ confluence property-list 123456789
288
+
289
+ # Get a specific property
290
+ confluence property-get 123456789 my-key
291
+
292
+ # Set a property (creates or updates with auto-versioning)
293
+ confluence property-set 123456789 my-key --value '{"color":"#ff0000"}'
294
+
295
+ # Set a property from a JSON file
296
+ confluence property-set 123456789 my-key --file ./property.json
297
+
298
+ # Delete a property
299
+ confluence property-delete 123456789 my-key
300
+
301
+ # Skip confirmation on delete
302
+ confluence property-delete 123456789 my-key --yes
303
+ ```
304
+
163
305
  ### Comments
164
306
  ```bash
165
307
  # List all comments (footer + inline)
@@ -296,6 +438,22 @@ confluence update 123456789 --file ./updated-content.md --format markdown
296
438
  confluence update 123456789 --title "New Title" --content "And new content"
297
439
  ```
298
440
 
441
+ ### Move a Page to New Parent
442
+
443
+ ```bash
444
+ # Move page by ID
445
+ confluence move 123456789 987654321
446
+
447
+ # Move page and rename it
448
+ confluence move 123456789 987654321 --title "Relocated Page"
449
+
450
+ # Move using URLs (for convenience)
451
+ confluence move "https://domain.atlassian.net/wiki/viewpage.action?pageId=123456789" \
452
+ "https://domain.atlassian.net/wiki/viewpage.action?pageId=987654321"
453
+ ```
454
+
455
+ **Note:** Pages can only be moved within the same Confluence space. Cross-space moves are not supported.
456
+
299
457
  ### Delete a Page
300
458
  ```bash
301
459
  # Delete by page ID (prompts for confirmation)
@@ -321,6 +479,52 @@ vim ./page-to-edit.xml
321
479
  confluence update 123456789 --file ./page-to-edit.xml --format storage
322
480
  ```
323
481
 
482
+ ### Profile Management
483
+ ```bash
484
+ # List all profiles and see which is active
485
+ confluence profile list
486
+
487
+ # Switch the active profile
488
+ confluence profile use staging
489
+
490
+ # Add a new profile interactively
491
+ confluence profile add staging
492
+
493
+ # Add a new profile non-interactively
494
+ confluence profile add staging --domain "staging.example.com" --auth-type bearer --token "xyz"
495
+
496
+ # Add a read-only profile (blocks all write operations)
497
+ confluence profile add agent --domain "company.atlassian.net" --auth-type basic --email "bot@example.com" --token "xyz" --read-only
498
+
499
+ # Remove a profile
500
+ confluence profile remove staging
501
+
502
+ # Use a specific profile for a single command
503
+ confluence --profile staging spaces
504
+ ```
505
+
506
+ ### Read-Only Mode
507
+
508
+ Read-only mode blocks all write operations at the CLI level, making it safe to hand the tool to AI agents (Claude Code, Copilot, etc.) without risking accidental edits.
509
+
510
+ **Enable via profile:**
511
+ ```bash
512
+ # During init
513
+ confluence init --read-only
514
+
515
+ # When adding a profile
516
+ confluence profile add agent --domain "company.atlassian.net" --token "xyz" --read-only
517
+ ```
518
+
519
+ **Enable via environment variable:**
520
+ ```bash
521
+ export CONFLUENCE_READ_ONLY=true # overrides profile setting
522
+ ```
523
+
524
+ When read-only mode is active, any write command (`create`, `create-child`, `update`, `delete`, `move`, `edit`, `comment`, `attachment-upload`, `attachment-delete`, `property-set`, `property-delete`, `comment-delete`, `copy-tree`) exits with code 1 and prints an error message.
525
+
526
+ `confluence profile list` shows a `[read-only]` badge next to protected profiles.
527
+
324
528
  ### View Usage Statistics
325
529
  ```bash
326
530
  confluence stats
@@ -330,7 +534,7 @@ confluence stats
330
534
 
331
535
  | Command | Description | Options |
332
536
  |---|---|---|
333
- | `init` | Initialize CLI configuration | |
537
+ | `init` | Initialize CLI configuration | `--read-only` |
334
538
  | `read <pageId_or_url>` | Read page content | `--format <html\|text\|markdown>` |
335
539
  | `info <pageId_or_url>` | Get page information | |
336
540
  | `search <query>` | Search for pages | `--limit <number>` |
@@ -341,15 +545,28 @@ confluence stats
341
545
  | `create-child <title> <parentId>` | Create a child page | `--content <string>`, `--file <path>`, `--format <storage\|html\|markdown>` |
342
546
  | `copy-tree <sourcePageId> <targetParentId> [newTitle]` | Copy page tree with all children | `--max-depth <number>`, `--exclude <patterns>`, `--delay-ms <ms>`, `--copy-suffix <text>`, `--dry-run`, `--fail-on-error`, `--quiet` |
343
547
  | `update <pageId>` | Update a page's title or content | `--title <string>`, `--content <string>`, `--file <path>`, `--format <storage\|html\|markdown>` |
548
+ | `move <pageId_or_url> <newParentId_or_url>` | Move a page to a new parent location | `--title <string>` |
344
549
  | `delete <pageId_or_url>` | Delete a page by ID or URL | `--yes` |
345
550
  | `edit <pageId>` | Export page content for editing | `--output <file>` |
346
551
  | `attachments <pageId_or_url>` | List or download attachments for a page | `--limit <number>`, `--pattern <glob>`, `--download`, `--dest <directory>` |
552
+ | `attachment-upload <pageId_or_url>` | Upload attachments to a page | `--file <path>`, `--comment <text>`, `--replace`, `--minor-edit` |
553
+ | `attachment-delete <pageId_or_url> <attachmentId>` | Delete an attachment from a page | `--yes` |
347
554
  | `comments <pageId_or_url>` | List comments for a page | `--format <text\|markdown\|json>`, `--limit <number>`, `--start <number>`, `--location <inline\|footer\|resolved>`, `--depth <root\|all>`, `--all` |
348
555
  | `comment <pageId_or_url>` | Create a comment on a page | `--content <string>`, `--file <path>`, `--format <storage\|html\|markdown>`, `--parent <commentId>`, `--location <inline\|footer>`, `--inline-selection <text>`, `--inline-original-selection <text>`, `--inline-marker-ref <ref>`, `--inline-properties <json>` |
349
556
  | `comment-delete <commentId>` | Delete a comment by ID | `--yes` |
557
+ | `property-list <pageId_or_url>` | List all content properties for a page | `--format <text\|json>`, `--limit <number>`, `--start <number>`, `--all` |
558
+ | `property-get <pageId_or_url> <key>` | Get a content property by key | `--format <text\|json>` |
559
+ | `property-set <pageId_or_url> <key>` | Set a content property (create or update) | `--value <json>`, `--file <path>`, `--format <text\|json>` |
560
+ | `property-delete <pageId_or_url> <key>` | Delete a content property by key | `--yes` |
350
561
  | `export <pageId_or_url>` | Export a page to a directory with its attachments | `--format <html\|text\|markdown>`, `--dest <directory>`, `--file <filename>`, `--attachments-dir <name>`, `--pattern <glob>`, `--referenced-only`, `--skip-attachments` |
562
+ | `profile list` | List all configuration profiles | |
563
+ | `profile use <name>` | Set the active configuration profile | |
564
+ | `profile add <name>` | Add a new configuration profile | `-d, --domain`, `-p, --api-path`, `-a, --auth-type`, `-e, --email`, `-t, --token`, `--protocol`, `--read-only` |
565
+ | `profile remove <name>` | Remove a configuration profile | |
351
566
  | `stats` | View your usage statistics | |
352
567
 
568
+ **Global option:** `--profile <name>` — Use a specific profile for any command (overrides `CONFLUENCE_PROFILE` env var and active profile).
569
+
353
570
  ## Examples
354
571
 
355
572
  ```bash
@@ -371,15 +588,30 @@ confluence search "API documentation" --limit 3
371
588
  # List all spaces
372
589
  confluence spaces
373
590
 
591
+ # Move a page to a new parent
592
+ confluence move 123456789 987654321
593
+
594
+ # Move and rename
595
+ confluence move 123456789 987654321 --title "New Title"
596
+
597
+ # Upload and delete an attachment
598
+ confluence attachment-upload 123456789 --file ./report.pdf
599
+ confluence attachment-delete 123456789 998877 --yes
600
+
374
601
  # View usage statistics
375
602
  confluence stats
603
+
604
+ # Profile management
605
+ confluence profile list
606
+ confluence profile use staging
607
+ confluence --profile staging spaces
376
608
  ```
377
609
 
378
610
  ## Development
379
611
 
380
612
  ```bash
381
613
  # Clone the repository
382
- git clone https://github.com/pchuri/confluence-cli.git
614
+ git clone https://github.com/bestend/confluence-cli.git
383
615
  cd confluence-cli
384
616
 
385
617
  # Install dependencies
@@ -414,7 +646,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
414
646
  - [ ] Bulk operations
415
647
  - [ ] Export pages to different formats
416
648
  - [ ] Integration with other Atlassian tools (Jira)
417
- - [ ] Page attachments management
649
+ - [x] Page attachments management (list, download, upload, delete)
418
650
  - [x] Comments
419
651
  - [ ] Reviews
420
652
 
@@ -425,15 +657,15 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
425
657
  Your feedback helps make confluence-cli better for everyone. Here's how you can share your thoughts:
426
658
 
427
659
  #### 🐛 Found a bug?
428
- 1. Check the [Issues](https://github.com/pchuri/confluence-cli/issues) page
429
- 2. Create a new [bug report](https://github.com/pchuri/confluence-cli/issues/new?template=bug_report.md)
660
+ 1. Check the [Issues](https://github.com/bestend/confluence-cli/issues) page
661
+ 2. Create a new [bug report](https://github.com/bestend/confluence-cli/issues/new?template=bug_report.md)
430
662
 
431
663
  #### 💡 Have a feature idea?
432
- 1. Create a [feature request](https://github.com/pchuri/confluence-cli/issues/new?template=feature_request.md)
433
- 2. Join our [Discussions](https://github.com/pchuri/confluence-cli/discussions) to chat with the community
664
+ 1. Create a [feature request](https://github.com/bestend/confluence-cli/issues/new?template=feature_request.md)
665
+ 2. Join our [Discussions](https://github.com/bestend/confluence-cli/discussions) to chat with the community
434
666
 
435
667
  #### 📝 General feedback?
436
- - Share your experience with a [feedback issue](https://github.com/pchuri/confluence-cli/issues/new?template=feedback.md)
668
+ - Share your experience with a [feedback issue](https://github.com/bestend/confluence-cli/issues/new?template=feedback.md)
437
669
  - Rate us on [NPM](https://www.npmjs.com/package/confluence-cli)
438
670
  - Star the repo if you find it useful! ⭐
439
671
 
@@ -442,12 +674,10 @@ Check out our [Contributing Guide](CONTRIBUTING.md) - all contributions are welc
442
674
 
443
675
  ### 📈 Usage Analytics
444
676
 
445
- To help us understand how confluence-cli is being used and improve it, we collect anonymous usage statistics. This includes:
446
- - Command usage frequency (no personal data)
447
- - Error patterns (to fix bugs faster)
448
- - Feature adoption metrics
677
+ confluence-cli tracks command usage statistics **locally** on your machine (`~/.confluence-cli/stats.json`). No data is sent to any external server. This includes:
678
+ - Command usage counts (success/error)
449
679
 
450
- You can opt-out anytime by setting: `export CONFLUENCE_CLI_ANALYTICS=false`
680
+ You can view your stats with `confluence stats`, or disable tracking by setting: `export CONFLUENCE_CLI_ANALYTICS=false`
451
681
 
452
682
  ---
453
683