jira-ai 0.6.6 → 0.6.8

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/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ import { createTaskCommand } from './commands/create-task.js';
18
18
  import { transitionCommand } from './commands/transition.js';
19
19
  import { getIssueStatisticsCommand } from './commands/get-issue-statistics.js';
20
20
  import { getPersonWorklogCommand } from './commands/get-person-worklog.js';
21
- import { confluenceGetPageCommand, confluenceListSpacesCommand, confluenceGetSpacePagesHierarchyCommand, confluenceAddCommentCommand } from './commands/confluence.js';
21
+ import { confluenceGetPageCommand, confluenceListSpacesCommand, confluenceGetSpacePagesHierarchyCommand, confluenceAddCommentCommand, confluenceCreatePageCommand, confluenceUpdateDescriptionCommand } from './commands/confluence.js';
22
22
  import { aboutCommand } from './commands/about.js';
23
23
  import { authCommand } from './commands/auth.js';
24
24
  import { settingsCommand } from './commands/settings.js';
@@ -264,10 +264,21 @@ confl
264
264
  .description('Display a hierarchical tree view of pages within a specific space.')
265
265
  .action(withPermission('confl', confluenceGetSpacePagesHierarchyCommand, { skipValidation: false }));
266
266
  confl
267
- .command('add-comment <url>')
267
+ .command('create-page <space> <title> [parent-page]')
268
+ .description('Create a new Confluence page')
269
+ .action(withPermission('confl', confluenceCreatePageCommand, { skipValidation: false }));
270
+ confl
271
+ .command('add-comment')
272
+ .argument('<url>', 'The full URL of the Confluence page.')
268
273
  .description('Add a new comment to a Confluence page using content from a local Markdown file.')
269
- .requiredOption('--from-file <path>', 'Path to Markdown file')
274
+ .option('-f, --from-file <path>', 'Path to the markdown file containing the comment content.')
270
275
  .action(withPermission('confl', confluenceAddCommentCommand, { schema: ConfluenceAddCommentSchema }));
276
+ confl
277
+ .command('update-description')
278
+ .argument('<url>', 'The full URL of the Confluence page.')
279
+ .description('Update the content of an existing Confluence page using a Markdown file.')
280
+ .option('-f, --from-file <path>', 'Path to the markdown file containing the new content.')
281
+ .action(withPermission('confl', confluenceUpdateDescriptionCommand, { schema: UpdateDescriptionSchema }));
271
282
  // About command (always allowed)
272
283
  program
273
284
  .command('about')
@@ -2,11 +2,37 @@ import chalk from 'chalk';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import { markdownToAdf } from 'marklassian';
5
- import { getPage, getPageComments, parseConfluenceUrl, listSpaces, getSpacePagesHierarchy, addPageComment } from '../lib/confluence-client.js';
5
+ import { getPage, getPageComments, parseConfluenceUrl, listSpaces, getSpacePagesHierarchy, addPageComment, createPage, updatePageContent } from '../lib/confluence-client.js';
6
6
  import { formatConfluencePage, formatConfluenceSpaces, formatConfluencePageHierarchy } from '../lib/formatters.js';
7
7
  import { ui } from '../lib/ui.js';
8
8
  import { CommandError } from '../lib/errors.js';
9
9
  import { isConfluenceSpaceAllowed } from '../lib/settings.js';
10
+ export async function confluenceCreatePageCommand(space, title, parentPage) {
11
+ // Validate space key
12
+ if (!isConfluenceSpaceAllowed(space)) {
13
+ throw new CommandError(`Access to Confluence space '${space}' is restricted by your settings.`);
14
+ }
15
+ ui.startSpinner(`Creating Confluence page '${title}' in space '${space}'...`);
16
+ try {
17
+ const url = await createPage(space, title, parentPage);
18
+ ui.succeedSpinner(chalk.green('Confluence page created successfully'));
19
+ console.log(chalk.cyan(`\nURL: ${url}`));
20
+ }
21
+ catch (error) {
22
+ ui.failSpinner();
23
+ if (error instanceof CommandError)
24
+ throw error;
25
+ const errorMsg = error.message?.toLowerCase() || '';
26
+ const hints = [];
27
+ if (errorMsg.includes('401') || errorMsg.includes('403') || errorMsg.includes('unauthorized')) {
28
+ hints.push('Authentication failed or you do not have permission to create pages in this space.');
29
+ }
30
+ else if (errorMsg.includes('404')) {
31
+ hints.push('Space or parent page not found.');
32
+ }
33
+ throw new CommandError(`Failed to create Confluence page: ${error.message}`, { hints });
34
+ }
35
+ }
10
36
  export async function confluenceAddCommentCommand(url, options) {
11
37
  const { fromFile } = options;
12
38
  // Validate space key before proceeding
@@ -151,3 +177,62 @@ export async function confluenceGetSpacePagesHierarchyCommand(spaceKey) {
151
177
  throw new CommandError(`Failed to fetch page hierarchy: ${error.message}`);
152
178
  }
153
179
  }
180
+ export async function confluenceUpdateDescriptionCommand(url, options) {
181
+ const { fromFile } = options;
182
+ // Validate space key before proceeding
183
+ try {
184
+ const { spaceKey } = parseConfluenceUrl(url);
185
+ if (spaceKey && !isConfluenceSpaceAllowed(spaceKey)) {
186
+ throw new CommandError(`Access to Confluence space '${spaceKey}' is restricted by your settings.`);
187
+ }
188
+ }
189
+ catch (e) {
190
+ if (e instanceof CommandError)
191
+ throw e;
192
+ }
193
+ // Resolve and read file
194
+ const absolutePath = path.resolve(fromFile);
195
+ let markdownContent;
196
+ try {
197
+ markdownContent = fs.readFileSync(absolutePath, 'utf-8');
198
+ }
199
+ catch (error) {
200
+ throw new CommandError(`Error reading file: ${error.message}`, {
201
+ hints: ['Make sure the file exists and you have permission to read it.']
202
+ });
203
+ }
204
+ if (markdownContent.trim() === '') {
205
+ throw new CommandError('Markdown file is empty');
206
+ }
207
+ // Convert Markdown to ADF
208
+ let adfContent;
209
+ try {
210
+ adfContent = markdownToAdf(markdownContent);
211
+ }
212
+ catch (error) {
213
+ throw new CommandError(`Error converting Markdown to ADF: ${error.message}`, {
214
+ hints: ['Ensure the Markdown content is valid.']
215
+ });
216
+ }
217
+ ui.startSpinner('Updating Confluence page content...');
218
+ try {
219
+ await updatePageContent(url, adfContent);
220
+ ui.succeedSpinner(chalk.green('Confluence page content updated successfully'));
221
+ console.log(chalk.gray(`\nPage: ${url}`));
222
+ console.log(chalk.gray(`File: ${absolutePath}`));
223
+ }
224
+ catch (error) {
225
+ ui.failSpinner();
226
+ if (error instanceof CommandError)
227
+ throw error;
228
+ const errorMsg = error.message?.toLowerCase() || '';
229
+ const hints = [];
230
+ if (errorMsg.includes('404') || errorMsg.includes('not found')) {
231
+ hints.push('The Confluence page was not found. Check if the URL is correct.');
232
+ }
233
+ else if (errorMsg.includes('401') || errorMsg.includes('403') || errorMsg.includes('unauthorized')) {
234
+ hints.push('Authentication failed or you do not have permission to update this page.');
235
+ }
236
+ throw new CommandError(`Failed to update Confluence page: ${error.message}`, { hints });
237
+ }
238
+ }
@@ -1,6 +1,7 @@
1
1
  import { ConfluenceClient } from 'confluence.js';
2
2
  import { loadCredentials, getCurrentOrganizationAlias, setOrganizationOverride as setAuthOrgOverride } from './auth-storage.js';
3
3
  import { convertADFToMarkdown } from './utils.js';
4
+ import { CommandError } from './errors.js';
4
5
  let confluenceClient = null;
5
6
  /**
6
7
  * Set a global organization override for the current execution
@@ -200,3 +201,71 @@ export async function addPageComment(url, adfContent) {
200
201
  }
201
202
  });
202
203
  }
204
+ /**
205
+ * Create a new Confluence page
206
+ */
207
+ export async function createPage(spaceKey, title, parentId) {
208
+ const client = getConfluenceClient();
209
+ const response = await client.content.createContent({
210
+ type: 'page',
211
+ title,
212
+ space: { key: spaceKey },
213
+ ancestors: parentId ? [{ id: parentId }] : undefined,
214
+ body: {
215
+ atlas_doc_format: {
216
+ value: JSON.stringify({
217
+ type: 'doc',
218
+ version: 1,
219
+ content: []
220
+ }),
221
+ representation: 'atlas_doc_format'
222
+ }
223
+ }
224
+ });
225
+ // @ts-ignore - accessing host to construct URL
226
+ const host = client.config.host || '';
227
+ return `${host.replace(/\/$/, '')}/pages/${response.id}`;
228
+ }
229
+ /**
230
+ * Update the content of an existing Confluence page
231
+ */
232
+ export async function updatePageContent(url, adfContent) {
233
+ const client = getConfluenceClient();
234
+ const { pageId } = parseConfluenceUrl(url);
235
+ // 1. Fetch current page details to get version and title
236
+ let page;
237
+ try {
238
+ page = await client.content.getContentById({
239
+ id: pageId,
240
+ expand: ['version', 'space'],
241
+ });
242
+ }
243
+ catch (error) {
244
+ throw new Error(`Failed to fetch page details: ${error.message}`);
245
+ }
246
+ const currentVersion = page.version?.number || 0;
247
+ const title = page.title;
248
+ // 2. Update the page content
249
+ try {
250
+ await client.content.updateContent({
251
+ id: pageId,
252
+ version: { number: currentVersion + 1 },
253
+ title,
254
+ type: 'page',
255
+ body: {
256
+ atlas_doc_format: {
257
+ value: JSON.stringify(adfContent),
258
+ representation: 'atlas_doc_format',
259
+ },
260
+ },
261
+ });
262
+ }
263
+ catch (error) {
264
+ if (error.status === 409 || error.message?.includes('409') || error.message?.toLowerCase().includes('conflict')) {
265
+ throw new CommandError('Version mismatch when updating Confluence page. Someone else might have updated it. Please try again.', {
266
+ hints: ['Reload the page content and try your update again.']
267
+ });
268
+ }
269
+ throw new Error(`Failed to update page content: ${error.message}`);
270
+ }
271
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jira-ai",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "description": "AI friendly Jira CLI to save context",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",