@closedloop-ai/cli 0.2.0 → 0.2.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 (79) hide show
  1. package/CONTRIBUTING.md +437 -0
  2. package/LICENSE +21 -0
  3. package/README.md +265 -0
  4. package/docs/CLI_COMMANDS.md +508 -0
  5. package/package.json +49 -26
  6. package/packages/cli/dist/api/team.js +45 -0
  7. package/packages/cli/dist/api/team.js.map +1 -0
  8. package/{dist → packages/cli/dist}/cli.js +7 -0
  9. package/packages/cli/dist/cli.js.map +1 -0
  10. package/packages/cli/dist/commands/team.js +44 -0
  11. package/packages/cli/dist/commands/team.js.map +1 -0
  12. package/dist/cli.js.map +0 -1
  13. package/jest.config.js +0 -14
  14. package/src/__tests__/cli.test.ts +0 -44
  15. package/src/__tests__/config.test.ts +0 -38
  16. package/src/__tests__/errors.test.ts +0 -132
  17. package/src/__tests__/setup.ts +0 -21
  18. package/src/__tests__/validation.test.ts +0 -156
  19. package/src/api/auth.ts +0 -21
  20. package/src/api/feedback.ts +0 -64
  21. package/src/api/input.ts +0 -55
  22. package/src/api/usage.ts +0 -45
  23. package/src/cli.ts +0 -158
  24. package/src/commands/config.ts +0 -192
  25. package/src/commands/feedback.ts +0 -250
  26. package/src/commands/input.ts +0 -389
  27. package/src/commands/list.ts +0 -84
  28. package/src/commands/status.ts +0 -96
  29. package/src/commands/submit.ts +0 -214
  30. package/src/config/constants.ts +0 -36
  31. package/src/config/index.ts +0 -59
  32. package/src/types/index.ts +0 -119
  33. package/src/utils/errors.ts +0 -98
  34. package/src/utils/validation.ts +0 -166
  35. package/tsconfig.json +0 -25
  36. /package/{dist → packages/cli/dist}/__tests__/cli.test.js +0 -0
  37. /package/{dist → packages/cli/dist}/__tests__/cli.test.js.map +0 -0
  38. /package/{dist → packages/cli/dist}/__tests__/config.test.js +0 -0
  39. /package/{dist → packages/cli/dist}/__tests__/config.test.js.map +0 -0
  40. /package/{dist → packages/cli/dist}/__tests__/errors.test.js +0 -0
  41. /package/{dist → packages/cli/dist}/__tests__/errors.test.js.map +0 -0
  42. /package/{dist → packages/cli/dist}/__tests__/setup.js +0 -0
  43. /package/{dist → packages/cli/dist}/__tests__/setup.js.map +0 -0
  44. /package/{dist → packages/cli/dist}/__tests__/validation.test.js +0 -0
  45. /package/{dist → packages/cli/dist}/__tests__/validation.test.js.map +0 -0
  46. /package/{dist → packages/cli/dist}/api/auth.js +0 -0
  47. /package/{dist → packages/cli/dist}/api/auth.js.map +0 -0
  48. /package/{dist → packages/cli/dist}/api/feedback.js +0 -0
  49. /package/{dist → packages/cli/dist}/api/feedback.js.map +0 -0
  50. /package/{dist → packages/cli/dist}/api/input.js +0 -0
  51. /package/{dist → packages/cli/dist}/api/input.js.map +0 -0
  52. /package/{dist → packages/cli/dist}/api/usage.js +0 -0
  53. /package/{dist → packages/cli/dist}/api/usage.js.map +0 -0
  54. /package/{dist → packages/cli/dist}/commands/config.js +0 -0
  55. /package/{dist → packages/cli/dist}/commands/config.js.map +0 -0
  56. /package/{dist → packages/cli/dist}/commands/feedback.js +0 -0
  57. /package/{dist → packages/cli/dist}/commands/feedback.js.map +0 -0
  58. /package/{dist → packages/cli/dist}/commands/input.js +0 -0
  59. /package/{dist → packages/cli/dist}/commands/input.js.map +0 -0
  60. /package/{dist → packages/cli/dist}/commands/list.js +0 -0
  61. /package/{dist → packages/cli/dist}/commands/list.js.map +0 -0
  62. /package/{dist → packages/cli/dist}/commands/status.js +0 -0
  63. /package/{dist → packages/cli/dist}/commands/status.js.map +0 -0
  64. /package/{dist → packages/cli/dist}/commands/submit.js +0 -0
  65. /package/{dist → packages/cli/dist}/commands/submit.js.map +0 -0
  66. /package/{dist → packages/cli/dist}/commands/usage.js +0 -0
  67. /package/{dist → packages/cli/dist}/commands/usage.js.map +0 -0
  68. /package/{dist → packages/cli/dist}/config/constants.js +0 -0
  69. /package/{dist → packages/cli/dist}/config/constants.js.map +0 -0
  70. /package/{dist → packages/cli/dist}/config/index.js +0 -0
  71. /package/{dist → packages/cli/dist}/config/index.js.map +0 -0
  72. /package/{dist → packages/cli/dist}/types/index.js +0 -0
  73. /package/{dist → packages/cli/dist}/types/index.js.map +0 -0
  74. /package/{dist → packages/cli/dist}/utils/config.js +0 -0
  75. /package/{dist → packages/cli/dist}/utils/config.js.map +0 -0
  76. /package/{dist → packages/cli/dist}/utils/errors.js +0 -0
  77. /package/{dist → packages/cli/dist}/utils/errors.js.map +0 -0
  78. /package/{dist → packages/cli/dist}/utils/validation.js +0 -0
  79. /package/{dist → packages/cli/dist}/utils/validation.js.map +0 -0
package/src/cli.ts DELETED
@@ -1,158 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import chalk from 'chalk';
5
- import { handleInputCommand } from './commands/input';
6
- import { handleFeedbackCommand } from './commands/feedback';
7
- import { configCommand } from './commands/config';
8
- import { CliError, handleApiError } from './utils/errors';
9
- import { CommandOptions } from './types';
10
-
11
- // Create the main program
12
- const program = new Command();
13
-
14
- program
15
- .name('cl')
16
- .description('ClosedLoop AI CLI - AI-powered customer feedback analysis for product management')
17
- .version('0.2.0')
18
- .addHelpText('before', chalk.blue(`
19
- ╔══════════════════════════════════════════════════════════════════════════════╗
20
- ║ ClosedLoop AI CLI v0.2.0 ║
21
- ║ AI-Powered Customer Feedback Analysis ║
22
- ╚══════════════════════════════════════════════════════════════════════════════╝
23
- `))
24
- .addHelpText('after', chalk.black(`
25
- Commands:
26
- input [content] Submit customer input for AI analysis
27
- input List all customer inputs
28
- input <id> Show specific input details
29
-
30
- feedback List AI-generated feedback
31
- feedback <id> Show specific feedback details
32
-
33
- config Show current configuration
34
- config set --api-key <key> Set API key
35
-
36
- version Show version information
37
- help [command] Show help for a command
38
-
39
- Examples:
40
- $ cl input "Dashboard is confusing"
41
- $ cl input
42
- $ cl input 74e3dd87-878f-41cf-8e5a-87527bbf7770
43
- $ cl feedback
44
- $ cl feedback 2ea8f556-052b-4f5c-bf86-833780b3d00d
45
- $ cl config set --api-key your-api-key-here
46
-
47
- Pagination:
48
- $ cl input --page 2 --limit 10
49
- $ cl feedback --page 2
50
-
51
- Get API keys for free at https://closedloop.sh
52
- `));
53
-
54
- // Add input command
55
- program
56
- .command('input [content]')
57
- .description('Submit customer input for AI analysis or list inputs')
58
- .option('-t, --title <title>', 'Title for this input')
59
- .option('-u, --url <url>', 'Source URL (support ticket, survey, etc.)')
60
- .option('-c, --customer <id>', 'Customer identifier')
61
- .option('-n, --name <name>', 'Name of person who provided the input')
62
- .option('-e, --email <email>', 'Email of person who provided the input')
63
- .option('--interactive', 'Fill in details step by step')
64
- .option('-w, --wait', 'Wait until processing is completed')
65
- .option('--json', 'Output in JSON format')
66
- .option('--page <number>', 'Page number for list', '1')
67
- .option('--limit <number>', 'Items per page for list', '20')
68
- .option('--status <status>', 'Filter by status (processing, completed, failed)')
69
- .option('--search <query>', 'Search in input content')
70
- .action(async (content, options: CommandOptions) => {
71
- try {
72
- await handleInputCommand(content, options);
73
- } catch (error: any) {
74
- handleError(error, options);
75
- }
76
- });
77
-
78
- // Add feedback command
79
- program
80
- .command('feedback [id]')
81
- .description('List AI-generated feedback or show specific feedback details')
82
- .option('--json', 'Output in JSON format')
83
- .option('--page <number>', 'Page number for list', '1')
84
- .option('--limit <number>', 'Items per page for list', '20')
85
- .option('--search <query>', 'Search feedback by content')
86
- .action(async (id, options: CommandOptions) => {
87
- try {
88
- await handleFeedbackCommand(id, options);
89
- } catch (error: any) {
90
- handleError(error, options);
91
- }
92
- });
93
-
94
- // Add config command
95
- program.addCommand(configCommand);
96
-
97
- // Add version command
98
- program
99
- .command('version')
100
- .description('Show version information')
101
- .action(() => {
102
- console.log(chalk.blue('ClosedLoop AI CLI v0.2.0'));
103
- console.log(chalk.gray('AI-Powered Customer Feedback Analysis'));
104
- console.log(chalk.gray('Get started: https://closedloop.sh'));
105
- });
106
-
107
- // Add help command
108
- program
109
- .command('help [command]')
110
- .description('Show help for a command')
111
- .action((command) => {
112
- if (command) {
113
- program.outputHelp();
114
- } else {
115
- program.outputHelp();
116
- }
117
- });
118
-
119
- // Error handling function
120
- function handleError(error: any, options: CommandOptions) {
121
- if (options.json) {
122
- console.log(JSON.stringify({
123
- success: false,
124
- error: error.message,
125
- code: error.code || 'UNKNOWN_ERROR',
126
- details: error.response?.data || 'Unknown error occurred'
127
- }, null, 2));
128
- } else {
129
- if (error instanceof CliError) {
130
- console.error(chalk.red('❌ Error:'), error.message);
131
- if (error.code === 'NO_API_KEY') {
132
- console.log(chalk.black('\n💡 To fix:'));
133
- console.log(chalk.black(' 1. Get your free API key at: https://closedloop.sh'));
134
- console.log(chalk.black(' 2. Run: cl config set --api-key <your-key>'));
135
- }
136
- } else {
137
- const cliError = handleApiError(error);
138
- console.error(chalk.red('❌ Error:'), cliError.message);
139
- console.log(chalk.black('\n💡 Get help: cl --help'));
140
- }
141
- }
142
- process.exit(error.exitCode || 1);
143
- }
144
-
145
- // Handle unknown commands
146
- program.on('command:*', (operands) => {
147
- console.error(chalk.red(`Unknown command: ${operands[0]}`));
148
- console.log(chalk.gray('Run "cl --help" to see available commands'));
149
- process.exit(1);
150
- });
151
-
152
- // Parse command line arguments
153
- program.parse();
154
-
155
- // If no command provided, show help
156
- if (!process.argv.slice(2).length) {
157
- program.outputHelp();
158
- }
@@ -1,192 +0,0 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import ora from 'ora';
4
- import { config } from '../config';
5
- import { validateApiKey } from '../api/auth';
6
- import { CommandOptions } from '../types';
7
- import { CONFIG, MESSAGES, URLS } from '../config/constants';
8
- import { validateApiKey as validateApiKeyFormat } from '../utils/validation';
9
-
10
- // Create config command
11
- export const configCommand = new Command('config')
12
- .description('Configure your API key and settings')
13
- .option('--set-api-key <key>', 'Set your API key')
14
- .option('--set-team <team>', 'Set your team (future feature)')
15
- .option('--json', 'Output in JSON format')
16
- .action(async (options: CommandOptions) => {
17
- try {
18
- await handleConfig(options);
19
- } catch (error: any) {
20
- handleError(error, options);
21
- }
22
- });
23
-
24
- // Create config subcommands
25
- const configSetCommand = new Command('set')
26
- .description('Set configuration values')
27
- .option('--api-key <key>', 'Set API key')
28
- .option('--team <team>', 'Set team (future feature)')
29
- .action(async (options: CommandOptions) => {
30
- try {
31
- await handleConfigSet(options);
32
- } catch (error: any) {
33
- handleError(error, options);
34
- }
35
- });
36
-
37
- const configShowCommand = new Command('show')
38
- .description('Show current configuration')
39
- .option('--json', 'Output in JSON format')
40
- .action(async (options: CommandOptions) => {
41
- try {
42
- await handleConfigShow(options);
43
- } catch (error: any) {
44
- handleError(error, options);
45
- }
46
- });
47
-
48
- // Add subcommands to main config command
49
- configCommand.addCommand(configSetCommand);
50
- configCommand.addCommand(configShowCommand);
51
-
52
- // Helper functions
53
- async function handleConfig(options: CommandOptions) {
54
- const currentConfig = config.get();
55
-
56
- if (options.setApiKey) {
57
- await setApiKey(options.setApiKey, options);
58
- return;
59
- }
60
-
61
- if (options.setTeam) {
62
- console.log(chalk.yellow('⚠️ Team configuration is not yet implemented'));
63
- console.log(chalk.black('This feature will be available in a future update.'));
64
- return;
65
- }
66
-
67
- // Show current config
68
- await showConfig(currentConfig, options);
69
- }
70
-
71
- async function handleConfigSet(options: CommandOptions) {
72
- if (options.apiKey) {
73
- await setApiKey(options.apiKey, options);
74
- } else if (options.team) {
75
- console.log(chalk.yellow('⚠️ Team configuration is not yet implemented'));
76
- console.log(chalk.black('This feature will be available in a future update.'));
77
- } else {
78
- console.log(chalk.red('❌ No configuration option specified'));
79
- console.log(chalk.black('Use --api-key or --team to set values'));
80
- process.exit(1);
81
- }
82
- }
83
-
84
- async function handleConfigShow(options: CommandOptions) {
85
- const currentConfig = config.get();
86
- await showConfig(currentConfig, options);
87
- }
88
-
89
- async function setApiKey(apiKey: string, options: CommandOptions) {
90
- try {
91
- // Validate API key format
92
- const validatedApiKey = validateApiKeyFormat(apiKey);
93
-
94
- // Validate API key by making a test request
95
- const spinner = ora('Validating API key...').start();
96
-
97
- try {
98
- await validateApiKey(validatedApiKey);
99
- spinner.succeed('API key validated successfully!');
100
-
101
- // Save the API key
102
- config.set('apiKey', validatedApiKey);
103
-
104
- if (options.json) {
105
- console.log(JSON.stringify({
106
- success: true,
107
- message: 'API key set successfully',
108
- data: {
109
- apiKey: validatedApiKey.substring(0, 8) + '...',
110
- configFile: config.getConfigPath(),
111
- configured: true
112
- }
113
- }, null, 2));
114
- } else {
115
- console.log(chalk.green('✅ API key set successfully!'));
116
- console.log(chalk.black(`Config file: ${config.getConfigPath()}`));
117
- }
118
- } catch (error: any) {
119
- spinner.fail('API key validation failed');
120
-
121
- if (error.response?.status === 401) {
122
- console.error(chalk.red('❌ Invalid API key'));
123
- console.log(chalk.black('\n💡 To get a valid API key:'));
124
- console.log(chalk.black(' 1. Visit: https://closedloop.sh'));
125
- console.log(chalk.black(' 2. Sign up or log in'));
126
- console.log(chalk.black(' 3. Generate an API key'));
127
- console.log(chalk.black(' 4. Run: cl config set-api-key <your-key>'));
128
- } else {
129
- console.error(chalk.red('❌ Validation Error:'), error.message);
130
- console.log(chalk.black('\n💡 Check your internet connection and try again'));
131
- }
132
- process.exit(1);
133
- }
134
- } catch (error: any) {
135
- console.error(chalk.red('❌ Invalid API key. Get your free API key at https://closedloop.sh'));
136
- process.exit(1);
137
- }
138
- }
139
-
140
- async function showConfig(currentConfig: any, options: CommandOptions) {
141
- if (options.json) {
142
- console.log(JSON.stringify({
143
- success: true,
144
- data: {
145
- apiKey: currentConfig.apiKey ? currentConfig.apiKey.substring(0, 8) + '...' : null,
146
- configFile: config.getConfigPath(),
147
- configured: !!currentConfig.apiKey
148
- }
149
- }, null, 2));
150
- return;
151
- }
152
-
153
- console.log(chalk.blue('\n⚙️ Configuration:'));
154
- console.log(chalk.black('─'.repeat(40)));
155
-
156
- if (currentConfig.apiKey) {
157
- console.log(chalk.blue('API Key:'), chalk.green('✓ Configured'));
158
- } else {
159
- console.log(chalk.blue('API Key:'), chalk.red('✗ Not configured'));
160
- console.log(chalk.black('Run: cl config set-api-key <your-key>'));
161
- }
162
-
163
- console.log(chalk.blue('Config File:'), config.getConfigPath());
164
-
165
- if (!currentConfig.apiKey) {
166
- console.log(chalk.yellow('\n💡 Get started:'));
167
- console.log(chalk.black(' 1. Get your free API key at: https://closedloop.sh'));
168
- console.log(chalk.black(' 2. Run: cl config set-api-key <your-key>'));
169
- console.log(chalk.black(' 3. Submit your first input: cl input "Your feedback here"'));
170
- }
171
- }
172
-
173
- function handleError(error: any, options: CommandOptions) {
174
- if (options.json) {
175
- console.log(JSON.stringify({
176
- success: false,
177
- error: error.message,
178
- details: error.response?.data || 'Unknown error occurred'
179
- }, null, 2));
180
- } else {
181
- if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
182
- console.error(chalk.red('❌ Connection Error:'), 'Cannot connect to ClosedLoop AI servers');
183
- console.log(chalk.black('\n💡 Check your internet connection and try again'));
184
- } else {
185
- console.error(chalk.red('❌ Error:'), error.message);
186
- console.log(chalk.black('\n💡 Get help: cl --help'));
187
- }
188
- }
189
- process.exit(1);
190
- }
191
-
192
- export { configCommand as default };
@@ -1,250 +0,0 @@
1
- import chalk from 'chalk';
2
- import { table } from 'table';
3
- import { listFeedbacks, getFeedbackDetail } from '../api/feedback';
4
- import { CommandOptions, FeedbackData, ListResponse } from '../types';
5
- import { CONFIG, MESSAGES } from '../config/constants';
6
- import { validateUuid, validatePagination } from '../utils/validation';
7
-
8
- // UUID regex pattern for detecting IDs
9
- const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
-
11
- // Main feedback command handler
12
- export async function handleFeedbackCommand(id: string | undefined, options: CommandOptions) {
13
- // If ID provided, show specific feedback details
14
- if (id) {
15
- if (!validateUuid(id)) {
16
- console.log(chalk.yellow('💡 Invalid feedback ID format'));
17
- console.log(chalk.black('Feedback ID should be a UUID like: 2ea8f556-052b-4f5c-bf86-833780b3d00d'));
18
- return;
19
- }
20
- return await showFeedback(id, options);
21
- }
22
-
23
- // If search query provided, search feedback
24
- if (options.search) {
25
- return await searchFeedback(options.search, options);
26
- }
27
-
28
- // Otherwise, list all feedback
29
- return await listFeedback(options);
30
- }
31
-
32
- // Helper functions
33
- async function listFeedback(options: CommandOptions) {
34
- const { page, limit } = validatePagination(options.page, options.limit);
35
- const status = options.status;
36
- const search = options.search;
37
-
38
- const result = await listFeedbacks({
39
- page,
40
- limit,
41
- status,
42
- search
43
- });
44
-
45
- if (options.json) {
46
- console.log(JSON.stringify({ success: true, data: result }, null, 2));
47
- return;
48
- }
49
-
50
- const feedbacks = result.feedbacks || [];
51
-
52
- if (feedbacks.length === 0) {
53
- console.log(chalk.yellow('📝 No feedback found'));
54
- if (search) {
55
- console.log(chalk.gray(`Try a different search term or remove --search to see all feedback`));
56
- }
57
- return;
58
- }
59
-
60
- console.log(chalk.blue('\n🎯 AI-Generated Feedback:'));
61
-
62
- const tableData = [
63
- [
64
- chalk.bold('ID'),
65
- chalk.bold('Title'),
66
- chalk.bold('Severity'),
67
- chalk.bold('Input ID'),
68
- chalk.bold('Created')
69
- ]
70
- ];
71
-
72
- feedbacks.forEach((feedback: any) => {
73
- tableData.push([
74
- feedback.id,
75
- feedback.title || chalk.gray('null'),
76
- feedback.severity || 'medium',
77
- feedback.input_id || chalk.gray('null'),
78
- feedback.timestamp ? new Date(feedback.timestamp).toLocaleString() : 'Unknown'
79
- ]);
80
- });
81
-
82
- console.log(table(tableData, {
83
- border: {
84
- topBody: '─',
85
- topJoin: '┬',
86
- topLeft: '┌',
87
- topRight: '┐',
88
- bottomBody: '─',
89
- bottomJoin: '┴',
90
- bottomLeft: '└',
91
- bottomRight: '┘',
92
- bodyLeft: '│',
93
- bodyRight: '│',
94
- bodyJoin: '│',
95
- joinBody: '─',
96
- joinLeft: '├',
97
- joinRight: '┤',
98
- joinJoin: '┼'
99
- }
100
- }));
101
-
102
- if (result.pagination) {
103
- console.log(chalk.black(`\nPage ${result.pagination.page} of ${result.pagination.pages} (${result.pagination.total} total feedback)`));
104
- if (result.pagination.page < result.pagination.pages) {
105
- console.log(chalk.gray(`💡 Use --page ${result.pagination.page + 1} to see next page`));
106
- }
107
- }
108
- }
109
-
110
- async function showFeedback(id: string, options: CommandOptions) {
111
- try {
112
- const result = await getFeedbackDetail(id);
113
-
114
- if (options.json) {
115
- console.log(JSON.stringify({ success: true, data: result }, null, 2));
116
- return;
117
- }
118
-
119
- console.log(chalk.blue('\n🎯 Feedback Details:'));
120
- console.log(chalk.black('─'.repeat(50)));
121
- console.log(chalk.blue('ID:'), result.id);
122
- console.log(chalk.blue('Title:'), result.title || chalk.gray('null'));
123
- console.log(chalk.blue('Clarity:'), result.clarity || chalk.gray('null'));
124
- console.log(chalk.blue('Deal Blocker:'), result.deal_blocker ? chalk.red('Yes') : chalk.green('No'));
125
- console.log(chalk.blue('Pain Point:'), result.pain_point || chalk.gray('null'));
126
- console.log(chalk.blue('Workaround:'), result.workaround || chalk.gray('null'));
127
- console.log(chalk.blue('Competitor Gap:'), result.competitor_gap || chalk.gray('null'));
128
- console.log(chalk.blue('Willingness to Pay:'), result.willingness_to_pay || chalk.gray('null'));
129
- console.log(chalk.blue('Use Case:'), result.use_case || chalk.gray('null'));
130
- console.log(chalk.blue('Feature Area:'), result.feature_area || chalk.gray('null'));
131
- console.log(chalk.blue('Source URL:'), result.source_url || chalk.gray('null'));
132
- console.log(chalk.blue('Created:'), result.timestamp ? new Date(result.timestamp).toLocaleString() : 'Unknown');
133
- } catch (error: any) {
134
- if (options.json) {
135
- console.log(JSON.stringify({
136
- success: false,
137
- error: error.message,
138
- details: error.response?.data || 'Unknown error occurred'
139
- }, null, 2));
140
- } else {
141
- if (error.response?.status === 404) {
142
- console.error(chalk.red('❌ Feedback not found'));
143
- console.log(chalk.black('The feedback ID you provided does not exist or is not accessible.'));
144
- } else if (error.response?.status === 401) {
145
- console.error(chalk.red('❌ Authentication Error:'), 'Invalid API key');
146
- console.log(chalk.black('\n💡 To fix:'));
147
- console.log(chalk.black(' 1. Get your free API key at: https://closedloop.sh'));
148
- console.log(chalk.black(' 2. Run: cl config set --api-key <your-key>'));
149
- } else {
150
- console.error(chalk.red('❌ Error:'), error.message);
151
- console.log(chalk.black('\n💡 Get help: cl --help'));
152
- }
153
- }
154
- process.exit(1);
155
- }
156
- }
157
-
158
- async function searchFeedback(query: string, options: any) {
159
- const page = parseInt(options.page) || 1;
160
- const limit = parseInt(options.limit) || 20;
161
-
162
- const result = await listFeedbacks({
163
- page,
164
- limit,
165
- search: query
166
- });
167
-
168
- if (options.json) {
169
- console.log(JSON.stringify({ success: true, data: result }, null, 2));
170
- return;
171
- }
172
-
173
- const feedbacks = result.feedbacks || [];
174
-
175
- if (feedbacks.length === 0) {
176
- console.log(chalk.yellow(`📝 No feedback found for "${query}"`));
177
- console.log(chalk.gray('Try a different search term or remove --search to see all feedback'));
178
- return;
179
- }
180
-
181
- console.log(chalk.blue(`\n🔍 Search Results for "${query}":`));
182
-
183
- const tableData = [
184
- [
185
- chalk.bold('ID'),
186
- chalk.bold('Title'),
187
- chalk.bold('Severity'),
188
- chalk.bold('Input ID'),
189
- chalk.bold('Created')
190
- ]
191
- ];
192
-
193
- feedbacks.forEach((feedback: any) => {
194
- tableData.push([
195
- feedback.id,
196
- feedback.title || chalk.gray('null'),
197
- feedback.severity || 'medium',
198
- feedback.input_id || chalk.gray('null'),
199
- feedback.timestamp ? new Date(feedback.timestamp).toLocaleString() : 'Unknown'
200
- ]);
201
- });
202
-
203
- console.log(table(tableData, {
204
- border: {
205
- topBody: '─',
206
- topJoin: '┬',
207
- topLeft: '┌',
208
- topRight: '┐',
209
- bottomBody: '─',
210
- bottomJoin: '┴',
211
- bottomLeft: '└',
212
- bottomRight: '┘',
213
- bodyLeft: '│',
214
- bodyRight: '│',
215
- bodyJoin: '│',
216
- joinBody: '─',
217
- joinLeft: '├',
218
- joinRight: '┤',
219
- joinJoin: '┼'
220
- }
221
- }));
222
-
223
- if (result.pagination) {
224
- console.log(chalk.black(`Page ${result.pagination.page} of ${result.pagination.pages} (${result.pagination.total} total results)`));
225
- }
226
- }
227
-
228
- function handleError(error: any, options: any) {
229
- if (options.json) {
230
- console.log(JSON.stringify({
231
- success: false,
232
- error: error.message,
233
- details: error.response?.data || 'Unknown error occurred'
234
- }, null, 2));
235
- } else {
236
- if (error.response?.status === 404) {
237
- console.error(chalk.red('❌ Not found'));
238
- console.log(chalk.black('The requested resource does not exist or is not accessible.'));
239
- } else if (error.response?.status === 401) {
240
- console.error(chalk.red('❌ Authentication Error:'), 'Invalid API key');
241
- console.log(chalk.black('\n💡 To fix:'));
242
- console.log(chalk.black(' 1. Get your free API key at: https://closedloop.sh'));
243
- console.log(chalk.black(' 2. Run: cl config set --api-key <your-key>'));
244
- } else {
245
- console.error(chalk.red('❌ Error:'), error.message);
246
- console.log(chalk.black('\n💡 Get help: cl --help'));
247
- }
248
- }
249
- process.exit(1);
250
- }