@braingrid/cli 0.0.9 → 0.1.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +7 -3
  3. package/dist/build-config.d.ts +4 -8
  4. package/dist/build-config.d.ts.map +1 -1
  5. package/dist/build-config.js +21 -8
  6. package/dist/build-config.js.map +1 -1
  7. package/dist/cli.js +297 -276
  8. package/dist/cli.js.map +1 -1
  9. package/dist/handlers/auth.handlers.d.ts +7 -1
  10. package/dist/handlers/auth.handlers.d.ts.map +1 -1
  11. package/dist/handlers/auth.handlers.js +80 -21
  12. package/dist/handlers/auth.handlers.js.map +1 -1
  13. package/dist/handlers/project.handlers.d.ts.map +1 -1
  14. package/dist/handlers/project.handlers.js +1 -0
  15. package/dist/handlers/project.handlers.js.map +1 -1
  16. package/dist/rpc/registry.d.ts +97 -0
  17. package/dist/rpc/registry.d.ts.map +1 -0
  18. package/dist/rpc/registry.js +119 -0
  19. package/dist/rpc/registry.js.map +1 -0
  20. package/dist/rpc/server.d.ts +76 -0
  21. package/dist/rpc/server.d.ts.map +1 -0
  22. package/dist/rpc/server.js +420 -0
  23. package/dist/rpc/server.js.map +1 -0
  24. package/dist/rpc/transport.d.ts +84 -0
  25. package/dist/rpc/transport.d.ts.map +1 -0
  26. package/dist/rpc/transport.js +296 -0
  27. package/dist/rpc/transport.js.map +1 -0
  28. package/dist/services/__mocks__/utils.d.ts +16 -0
  29. package/dist/services/__mocks__/utils.d.ts.map +1 -0
  30. package/dist/services/__mocks__/utils.js +21 -0
  31. package/dist/services/__mocks__/utils.js.map +1 -0
  32. package/dist/services/auth.d.ts +18 -0
  33. package/dist/services/auth.d.ts.map +1 -1
  34. package/dist/services/auth.js +92 -42
  35. package/dist/services/auth.js.map +1 -1
  36. package/dist/services/oauth2-auth.d.ts +16 -0
  37. package/dist/services/oauth2-auth.d.ts.map +1 -1
  38. package/dist/services/oauth2-auth.js +74 -0
  39. package/dist/services/oauth2-auth.js.map +1 -1
  40. package/package.json +11 -29
  41. package/dist/.build-info.json +0 -9
  42. package/dist/test/setup.d.ts +0 -2
  43. package/dist/test/setup.d.ts.map +0 -1
  44. package/dist/test/setup.js +0 -40
  45. package/dist/test/setup.js.map +0 -1
package/dist/cli.js CHANGED
@@ -2,283 +2,304 @@
2
2
  import { Command } from 'commander';
3
3
  import { createRequire } from 'module';
4
4
  import * as handlers from './handlers/index.js';
5
+ import { JsonRpcServer } from './rpc/server.js';
5
6
  const require = createRequire(import.meta.url);
6
7
  const packageJson = require('../package.json');
7
8
  const program = new Command();
8
- program
9
- .name('braingrid')
10
- .description('BrainGrid CLI - Manage projects, requirements, and tasks')
11
- .version(packageJson.version, '-v, --version', 'output the current version')
12
- .showHelpAfterError('(use --help for usage)');
13
- // ============================================
14
- // AUTH COMMANDS
15
- // ============================================
16
- program
17
- .command('login')
18
- .description('Authenticate with BrainGrid')
19
- .action(async () => {
20
- const result = await handlers.handleLogin();
21
- console.log(result.message);
22
- if (!result.success) {
23
- process.exit(1);
24
- }
25
- });
26
- program
27
- .command('logout')
28
- .description('Sign out from BrainGrid')
29
- .action(async () => {
30
- const result = await handlers.handleLogout();
31
- console.log(result.message);
32
- if (!result.success) {
33
- process.exit(1);
34
- }
35
- });
36
- program
37
- .command('whoami')
38
- .description('Show current user information')
39
- .action(async () => {
40
- const result = await handlers.handleWhoami();
41
- console.log(result.message);
42
- if (!result.success) {
43
- process.exit(1);
44
- }
45
- });
46
- program
47
- .command('status')
48
- .description('Show CLI status (authentication, git, config)')
49
- .action(async () => {
50
- const result = await handlers.handleStatus();
51
- console.log(result.message);
52
- if (!result.success) {
53
- process.exit(1);
54
- }
55
- });
56
- program
57
- .command('init')
58
- .description('Initialize BrainGrid project in current repository')
59
- .option('--project <id>', 'project ID to initialize with (auto-detects if not provided)')
60
- .option('--wizard', 'run interactive wizard')
61
- .option('--force', 'force reinitialization if already initialized')
62
- .action(async (opts) => {
63
- const result = await handlers.handleInit(opts);
64
- console.log(result.message);
65
- if (!result.success) {
66
- process.exit(1);
67
- }
68
- });
69
- program
70
- .command('update')
71
- .description('Update BrainGrid CLI to the latest version')
72
- .option('--check', 'check for updates without installing')
73
- .action(async (opts) => {
74
- const result = await handlers.handleUpdate(opts);
75
- console.log(result.message);
76
- if (!result.success) {
77
- process.exit(1);
78
- }
79
- });
80
- // ============================================
81
- // PROJECT RESOURCE COMMANDS
82
- // ============================================
83
- const project = program.command('project').description('Manage projects');
84
- project
85
- .command('list')
86
- .description('List all projects')
87
- .option('--format <format>', 'output format (table or json)', 'table')
88
- .option('--page <page>', 'page number for pagination', '1')
89
- .option('--limit <limit>', 'number of projects per page', '20')
90
- .action(async (opts) => {
91
- const result = await handlers.handleProjectList(opts);
92
- console.log(result.message);
93
- if (!result.success) {
94
- process.exit(1);
95
- }
96
- });
97
- project
98
- .command('show')
99
- .description('Show projects for a repository (defaults to current git repo)')
100
- .option('--repository, --repo <owner/name>', 'specify repository (e.g., microsoft/vscode)')
101
- .option('--format <format>', 'output format (table or json)', 'table')
102
- .option('--page <page>', 'page number for pagination', '1')
103
- .option('--limit <limit>', 'number of projects per page', '20')
104
- .action(async (opts) => {
105
- const result = await handlers.handleProjectShow(opts);
106
- console.log(result.message);
107
- if (!result.success) {
108
- process.exit(1);
109
- }
110
- });
111
- project
112
- .command('get <id>')
113
- .description('Get a specific project by ID')
114
- .action(async (id) => {
115
- const result = await handlers.handleProjectGet(id);
116
- console.log(result.message);
117
- if (!result.success) {
118
- process.exit(1);
119
- }
120
- });
121
- project
122
- .command('create')
123
- .description('Create a new project')
124
- .requiredOption('--name <name>', 'project name')
125
- .option('--description <description>', 'project description')
126
- .action(async (opts) => {
127
- const result = await handlers.handleProjectCreate(opts);
128
- console.log(result.message);
129
- if (!result.success) {
130
- process.exit(1);
131
- }
132
- });
133
- project
134
- .command('update <id>')
135
- .description('Update project information')
136
- .option('--name <name>', 'new project name')
137
- .option('--description <description>', 'new project description')
138
- .action(async (id, opts) => {
139
- const result = await handlers.handleProjectUpdate(id, opts);
140
- console.log(result.message);
141
- if (!result.success) {
142
- process.exit(1);
143
- }
144
- });
145
- project
146
- .command('delete <id>')
147
- .description('Delete a project')
148
- .option('--force', 'force deletion without confirmation')
149
- .action(async (id, opts) => {
150
- const result = await handlers.handleProjectDelete(id, opts);
151
- console.log(result.message);
152
- if (!result.success) {
153
- process.exit(1);
154
- }
155
- });
156
- // ============================================
157
- // REQUIREMENT RESOURCE COMMANDS
158
- // ============================================
159
- const requirement = program.command('requirement').description('Manage requirements');
160
- requirement
161
- .command('list')
162
- .description('List requirements for a project')
163
- .option('-p, --project <id>', 'project ID (auto-detects from .braingrid/project.json if not provided)')
164
- .option('--status <status>', 'filter by status (IDEA, PLANNED, IN_PROGRESS, REVIEW, COMPLETED, CANCELLED)')
165
- .option('--format <format>', 'output format (table or json)', 'table')
166
- .option('--page <page>', 'page number for pagination', '1')
167
- .option('--limit <limit>', 'number of requirements per page', '20')
168
- .action(async (opts) => {
169
- const result = await handlers.handleRequirementList(opts);
170
- console.log(result.message);
171
- if (!result.success) {
172
- process.exit(1);
173
- }
174
- });
175
- requirement
176
- .command('show <id>')
177
- .description('Show requirement details')
178
- .action(async (id) => {
179
- const result = await handlers.handleRequirementShow(id);
180
- console.log(result.message);
181
- if (!result.success) {
182
- process.exit(1);
183
- }
184
- });
185
- requirement
186
- .command('create')
187
- .description('Create a new requirement')
188
- .option('-p, --project <id>', 'project ID (auto-detects from .braingrid/project.json if not provided)')
189
- .requiredOption('--prompt <prompt>', 'requirement prompt/description')
190
- .option('--repositories <repos>', 'comma-separated list of repositories (owner/repo)')
191
- .action(async (opts) => {
192
- const result = await handlers.handleRequirementCreate(opts);
193
- console.log(result.message);
194
- if (!result.success) {
195
- process.exit(1);
196
- }
197
- });
198
- requirement
199
- .command('update <id>')
200
- .description('Update requirement information')
201
- .option('--status <status>', 'new status (IDEA, PLANNED, IN_PROGRESS, REVIEW, COMPLETED, CANCELLED)')
202
- .option('--name <name>', 'new requirement name')
203
- .action(async (id, opts) => {
204
- const result = await handlers.handleRequirementUpdate(id, opts);
205
- console.log(result.message);
206
- if (!result.success) {
207
- process.exit(1);
208
- }
209
- });
210
- requirement
211
- .command('delete <id>')
212
- .description('Delete a requirement')
213
- .option('--force', 'force deletion without confirmation')
214
- .action(async (id, opts) => {
215
- const result = await handlers.handleRequirementDelete(id, opts);
216
- console.log(result.message);
217
- if (!result.success) {
218
- process.exit(1);
219
- }
220
- });
221
- // ============================================
222
- // TASK RESOURCE COMMANDS
223
- // ============================================
224
- const task = program.command('task').description('Manage tasks');
225
- task
226
- .command('list')
227
- .description('List tasks for a requirement')
228
- .option('-r, --requirement <id>', 'requirement ID (REQ-456 or PROJ-123/REQ-456, auto-detects project if initialized)')
229
- .option('--format <format>', 'output format (table or json)', 'table')
230
- .action(async (opts) => {
231
- const result = await handlers.handleTaskList(opts);
232
- console.log(result.message);
233
- if (!result.success) {
234
- process.exit(1);
235
- }
236
- });
237
- task
238
- .command('show <id>')
239
- .description('Show task details')
240
- .action(async (id) => {
241
- const result = await handlers.handleTaskShow(id);
242
- console.log(result.message);
243
- if (!result.success) {
244
- process.exit(1);
245
- }
246
- });
247
- task
248
- .command('create')
249
- .description('Create a new task')
250
- .option('-r, --requirement <id>', 'requirement ID (REQ-456 or PROJ-123/REQ-456, auto-detects project if initialized)')
251
- .requiredOption('--title <title>', 'task title')
252
- .option('--content <content>', 'task content/description')
253
- .action(async (opts) => {
254
- const result = await handlers.handleTaskCreate(opts);
255
- console.log(result.message);
256
- if (!result.success) {
257
- process.exit(1);
258
- }
259
- });
260
- task
261
- .command('update <id>')
262
- .description('Update task information')
263
- .option('--status <status>', 'new status (PLANNED, IN_PROGRESS, COMPLETED, CANCELLED)')
264
- .option('--title <title>', 'new task title')
265
- .action(async (id, opts) => {
266
- const result = await handlers.handleTaskUpdate(id, opts);
267
- console.log(result.message);
268
- if (!result.success) {
269
- process.exit(1);
270
- }
271
- });
272
- task
273
- .command('delete <id>')
274
- .description('Delete a task')
275
- .option('--force', 'force deletion without confirmation')
276
- .action(async (id, opts) => {
277
- const result = await handlers.handleTaskDelete(id, opts);
278
- console.log(result.message);
279
- if (!result.success) {
280
- process.exit(1);
281
- }
282
- });
283
- program.parse();
9
+ // Check for --rpc flag early
10
+ const isRpcMode = process.argv.includes('--rpc');
11
+ // If in RPC mode, start the JSON-RPC server
12
+ if (isRpcMode) {
13
+ const server = new JsonRpcServer();
14
+ server.start();
15
+ // Keep the process running
16
+ process.on('SIGINT', async () => {
17
+ await server.stop();
18
+ process.exit(0);
19
+ });
20
+ process.on('SIGTERM', async () => {
21
+ await server.stop();
22
+ process.exit(0);
23
+ });
24
+ }
25
+ else {
26
+ // Traditional CLI mode
27
+ program
28
+ .name('braingrid')
29
+ .description('BrainGrid CLI - Manage projects, requirements, and tasks')
30
+ .version(packageJson.version, '-v, --version', 'output the current version')
31
+ .option('--rpc', 'Start in JSON-RPC server mode')
32
+ .showHelpAfterError('(use --help for usage)');
33
+ // ============================================
34
+ // AUTH COMMANDS
35
+ // ============================================
36
+ program
37
+ .command('login')
38
+ .description('Authenticate with BrainGrid')
39
+ .action(async () => {
40
+ const result = await handlers.handleLogin();
41
+ console.log(result.message);
42
+ if (!result.success) {
43
+ process.exit(1);
44
+ }
45
+ });
46
+ program
47
+ .command('logout')
48
+ .description('Sign out from BrainGrid')
49
+ .action(async () => {
50
+ const result = await handlers.handleLogout();
51
+ console.log(result.message);
52
+ if (!result.success) {
53
+ process.exit(1);
54
+ }
55
+ });
56
+ program
57
+ .command('whoami')
58
+ .description('Show current user information')
59
+ .action(async () => {
60
+ const result = await handlers.handleWhoami();
61
+ console.log(result.message);
62
+ if (!result.success) {
63
+ process.exit(1);
64
+ }
65
+ });
66
+ program
67
+ .command('status')
68
+ .description('Show CLI status (authentication, git, config)')
69
+ .action(async () => {
70
+ const result = await handlers.handleStatus();
71
+ console.log(result.message);
72
+ if (!result.success) {
73
+ process.exit(1);
74
+ }
75
+ });
76
+ program
77
+ .command('init')
78
+ .description('Initialize BrainGrid project in current repository')
79
+ .option('--project <id>', 'project ID to initialize with (auto-detects if not provided)')
80
+ .option('--wizard', 'run interactive wizard')
81
+ .option('--force', 'force reinitialization if already initialized')
82
+ .action(async (opts) => {
83
+ const result = await handlers.handleInit(opts);
84
+ console.log(result.message);
85
+ if (!result.success) {
86
+ process.exit(1);
87
+ }
88
+ });
89
+ program
90
+ .command('update')
91
+ .description('Update BrainGrid CLI to the latest version')
92
+ .option('--check', 'check for updates without installing')
93
+ .action(async (opts) => {
94
+ const result = await handlers.handleUpdate(opts);
95
+ console.log(result.message);
96
+ if (!result.success) {
97
+ process.exit(1);
98
+ }
99
+ });
100
+ // ============================================
101
+ // PROJECT RESOURCE COMMANDS
102
+ // ============================================
103
+ const project = program.command('project').description('Manage projects');
104
+ project
105
+ .command('list')
106
+ .description('List all projects')
107
+ .option('--format <format>', 'output format (table or json)', 'table')
108
+ .option('--page <page>', 'page number for pagination', '1')
109
+ .option('--limit <limit>', 'number of projects per page', '20')
110
+ .action(async (opts) => {
111
+ const result = await handlers.handleProjectList(opts);
112
+ console.log(result.message);
113
+ if (!result.success) {
114
+ process.exit(1);
115
+ }
116
+ });
117
+ project
118
+ .command('show')
119
+ .description('Show projects for a repository (defaults to current git repo)')
120
+ .option('--repository, --repo <owner/name>', 'specify repository (e.g., microsoft/vscode)')
121
+ .option('--format <format>', 'output format (table or json)', 'table')
122
+ .option('--page <page>', 'page number for pagination', '1')
123
+ .option('--limit <limit>', 'number of projects per page', '20')
124
+ .action(async (opts) => {
125
+ const result = await handlers.handleProjectShow(opts);
126
+ console.log(result.message);
127
+ if (!result.success) {
128
+ process.exit(1);
129
+ }
130
+ });
131
+ project
132
+ .command('get <id>')
133
+ .description('Get a specific project by ID')
134
+ .action(async (id) => {
135
+ const result = await handlers.handleProjectGet(id);
136
+ console.log(result.message);
137
+ if (!result.success) {
138
+ process.exit(1);
139
+ }
140
+ });
141
+ project
142
+ .command('create')
143
+ .description('Create a new project')
144
+ .requiredOption('--name <name>', 'project name')
145
+ .option('--description <description>', 'project description')
146
+ .action(async (opts) => {
147
+ const result = await handlers.handleProjectCreate(opts);
148
+ console.log(result.message);
149
+ if (!result.success) {
150
+ process.exit(1);
151
+ }
152
+ });
153
+ project
154
+ .command('update <id>')
155
+ .description('Update project information')
156
+ .option('--name <name>', 'new project name')
157
+ .option('--description <description>', 'new project description')
158
+ .action(async (id, opts) => {
159
+ const result = await handlers.handleProjectUpdate(id, opts);
160
+ console.log(result.message);
161
+ if (!result.success) {
162
+ process.exit(1);
163
+ }
164
+ });
165
+ project
166
+ .command('delete <id>')
167
+ .description('Delete a project')
168
+ .option('--force', 'force deletion without confirmation')
169
+ .action(async (id, opts) => {
170
+ const result = await handlers.handleProjectDelete(id, opts);
171
+ console.log(result.message);
172
+ if (!result.success) {
173
+ process.exit(1);
174
+ }
175
+ });
176
+ // ============================================
177
+ // REQUIREMENT RESOURCE COMMANDS
178
+ // ============================================
179
+ const requirement = program.command('requirement').description('Manage requirements');
180
+ requirement
181
+ .command('list')
182
+ .description('List requirements for a project')
183
+ .option('-p, --project <id>', 'project ID (auto-detects from .braingrid/project.json if not provided)')
184
+ .option('--status <status>', 'filter by status (IDEA, PLANNED, IN_PROGRESS, REVIEW, COMPLETED, CANCELLED)')
185
+ .option('--format <format>', 'output format (table or json)', 'table')
186
+ .option('--page <page>', 'page number for pagination', '1')
187
+ .option('--limit <limit>', 'number of requirements per page', '20')
188
+ .action(async (opts) => {
189
+ const result = await handlers.handleRequirementList(opts);
190
+ console.log(result.message);
191
+ if (!result.success) {
192
+ process.exit(1);
193
+ }
194
+ });
195
+ requirement
196
+ .command('show <id>')
197
+ .description('Show requirement details')
198
+ .action(async (id) => {
199
+ const result = await handlers.handleRequirementShow(id);
200
+ console.log(result.message);
201
+ if (!result.success) {
202
+ process.exit(1);
203
+ }
204
+ });
205
+ requirement
206
+ .command('create')
207
+ .description('Create a new requirement')
208
+ .option('-p, --project <id>', 'project ID (auto-detects from .braingrid/project.json if not provided)')
209
+ .requiredOption('--prompt <prompt>', 'requirement prompt/description')
210
+ .option('--repositories <repos>', 'comma-separated list of repositories (owner/repo)')
211
+ .action(async (opts) => {
212
+ const result = await handlers.handleRequirementCreate(opts);
213
+ console.log(result.message);
214
+ if (!result.success) {
215
+ process.exit(1);
216
+ }
217
+ });
218
+ requirement
219
+ .command('update <id>')
220
+ .description('Update requirement information')
221
+ .option('--status <status>', 'new status (IDEA, PLANNED, IN_PROGRESS, REVIEW, COMPLETED, CANCELLED)')
222
+ .option('--name <name>', 'new requirement name')
223
+ .action(async (id, opts) => {
224
+ const result = await handlers.handleRequirementUpdate(id, opts);
225
+ console.log(result.message);
226
+ if (!result.success) {
227
+ process.exit(1);
228
+ }
229
+ });
230
+ requirement
231
+ .command('delete <id>')
232
+ .description('Delete a requirement')
233
+ .option('--force', 'force deletion without confirmation')
234
+ .action(async (id, opts) => {
235
+ const result = await handlers.handleRequirementDelete(id, opts);
236
+ console.log(result.message);
237
+ if (!result.success) {
238
+ process.exit(1);
239
+ }
240
+ });
241
+ // ============================================
242
+ // TASK RESOURCE COMMANDS
243
+ // ============================================
244
+ const task = program.command('task').description('Manage tasks');
245
+ task
246
+ .command('list')
247
+ .description('List tasks for a requirement')
248
+ .option('-r, --requirement <id>', 'requirement ID (REQ-456 or PROJ-123/REQ-456, auto-detects project if initialized)')
249
+ .option('--format <format>', 'output format (table or json)', 'table')
250
+ .action(async (opts) => {
251
+ const result = await handlers.handleTaskList(opts);
252
+ console.log(result.message);
253
+ if (!result.success) {
254
+ process.exit(1);
255
+ }
256
+ });
257
+ task
258
+ .command('show <id>')
259
+ .description('Show task details')
260
+ .action(async (id) => {
261
+ const result = await handlers.handleTaskShow(id);
262
+ console.log(result.message);
263
+ if (!result.success) {
264
+ process.exit(1);
265
+ }
266
+ });
267
+ task
268
+ .command('create')
269
+ .description('Create a new task')
270
+ .option('-r, --requirement <id>', 'requirement ID (REQ-456 or PROJ-123/REQ-456, auto-detects project if initialized)')
271
+ .requiredOption('--title <title>', 'task title')
272
+ .option('--content <content>', 'task content/description')
273
+ .action(async (opts) => {
274
+ const result = await handlers.handleTaskCreate(opts);
275
+ console.log(result.message);
276
+ if (!result.success) {
277
+ process.exit(1);
278
+ }
279
+ });
280
+ task
281
+ .command('update <id>')
282
+ .description('Update task information')
283
+ .option('--status <status>', 'new status (PLANNED, IN_PROGRESS, COMPLETED, CANCELLED)')
284
+ .option('--title <title>', 'new task title')
285
+ .action(async (id, opts) => {
286
+ const result = await handlers.handleTaskUpdate(id, opts);
287
+ console.log(result.message);
288
+ if (!result.success) {
289
+ process.exit(1);
290
+ }
291
+ });
292
+ task
293
+ .command('delete <id>')
294
+ .description('Delete a task')
295
+ .option('--force', 'force deletion without confirmation')
296
+ .action(async (id, opts) => {
297
+ const result = await handlers.handleTaskDelete(id, opts);
298
+ console.log(result.message);
299
+ if (!result.success) {
300
+ process.exit(1);
301
+ }
302
+ });
303
+ program.parse();
304
+ }
284
305
  //# sourceMappingURL=cli.js.map