@codeguide/core 0.0.28 → 0.0.29

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/__tests__/services/usage/usage-service.test.ts +442 -83
  2. package/codeguide.ts +3 -0
  3. package/dist/codeguide.d.ts +2 -1
  4. package/dist/codeguide.js +1 -0
  5. package/dist/index.d.ts +4 -3
  6. package/dist/services/base/base-service.d.ts +21 -0
  7. package/dist/services/base/base-service.js +114 -0
  8. package/dist/services/codespace/codespace-service.d.ts +55 -1
  9. package/dist/services/codespace/codespace-service.js +257 -0
  10. package/dist/services/codespace/codespace-types.d.ts +192 -12
  11. package/dist/services/codespace/index.d.ts +1 -1
  12. package/dist/services/index.d.ts +2 -0
  13. package/dist/services/index.js +4 -1
  14. package/dist/services/projects/project-types.d.ts +66 -32
  15. package/dist/services/starter-kits/index.d.ts +2 -0
  16. package/dist/services/starter-kits/index.js +20 -0
  17. package/dist/services/starter-kits/starter-kits-service.d.ts +13 -0
  18. package/dist/services/starter-kits/starter-kits-service.js +27 -0
  19. package/dist/services/starter-kits/starter-kits-types.d.ts +34 -0
  20. package/dist/services/starter-kits/starter-kits-types.js +2 -0
  21. package/dist/services/tasks/task-service.d.ts +2 -1
  22. package/dist/services/tasks/task-service.js +8 -0
  23. package/dist/services/tasks/task-types.d.ts +26 -7
  24. package/dist/services/usage/usage-service.d.ts +5 -2
  25. package/dist/services/usage/usage-service.js +58 -9
  26. package/dist/services/usage/usage-types.d.ts +150 -26
  27. package/docs/.vitepress/README.md +51 -0
  28. package/docs/.vitepress/config.ts +139 -0
  29. package/docs/.vitepress/theme/custom.css +80 -0
  30. package/docs/.vitepress/theme/index.ts +13 -0
  31. package/docs/.vitepress/tsconfig.json +19 -0
  32. package/docs/QUICKSTART.md +77 -0
  33. package/docs/README.md +134 -0
  34. package/docs/README_SETUP.md +46 -0
  35. package/docs/authentication.md +351 -0
  36. package/docs/codeguide-client.md +350 -0
  37. package/docs/codespace-models.md +1004 -0
  38. package/docs/codespace-service.md +444 -0
  39. package/docs/index.md +135 -0
  40. package/docs/package.json +14 -0
  41. package/docs/projects-service.md +688 -0
  42. package/docs/security-keys-service.md +773 -0
  43. package/docs/starter-kits-service.md +249 -0
  44. package/docs/task-service.md +955 -0
  45. package/docs/testsprite_tests/TC001_Homepage_Load_and_Hero_Section_Display.py +70 -0
  46. package/docs/testsprite_tests/TC002_Sidebar_Navigation_ExpandCollapse_Functionality.py +73 -0
  47. package/docs/testsprite_tests/TC003_Full_Text_Local_Search_with_Keyboard_Shortcut.py +90 -0
  48. package/docs/testsprite_tests/TC004_Dark_Mode_Toggle_and_Persistence.py +73 -0
  49. package/docs/testsprite_tests/TC005_Mobile_Responsiveness_and_Touch_Navigation.py +113 -0
  50. package/docs/testsprite_tests/TC006_GitHub_Integration_Edit_this_page_Links.py +73 -0
  51. package/docs/testsprite_tests/TC007_Syntax_Highlighting_and_Code_Copy_Functionality.py +73 -0
  52. package/docs/testsprite_tests/TC008_Auto_Generated_Table_of_Contents_Accuracy.py +73 -0
  53. package/docs/testsprite_tests/TC009_SEO_and_Content_Discoverability_Verification.py +73 -0
  54. package/docs/testsprite_tests/TC010_Accessibility_Compliance_WCAG_AA.py +73 -0
  55. package/docs/testsprite_tests/TC011_Local_Development_Workflow_Build_and_Hot_Reload.py +74 -0
  56. package/docs/testsprite_tests/TC012_Performance_Metrics_Compliance.py +73 -0
  57. package/docs/testsprite_tests/standard_prd.json +122 -0
  58. package/docs/testsprite_tests/testsprite-mcp-test-report.html +2508 -0
  59. package/docs/testsprite_tests/testsprite-mcp-test-report.md +273 -0
  60. package/docs/testsprite_tests/testsprite_frontend_test_plan.json +390 -0
  61. package/docs/usage-service.md +291 -1
  62. package/index.ts +11 -3
  63. package/package.json +16 -2
  64. package/plans/CODESPACE_LOGS_STREAMING_GUIDE.md +320 -0
  65. package/plans/CODESPACE_TASK_LOGS_API_COMPLETE_GUIDE.md +821 -0
  66. package/services/base/base-service.ts +130 -0
  67. package/services/codespace/codespace-service.ts +337 -0
  68. package/services/codespace/codespace-types.ts +262 -13
  69. package/services/codespace/index.ts +16 -1
  70. package/services/index.ts +2 -0
  71. package/services/projects/README.md +107 -34
  72. package/services/projects/project-types.ts +69 -32
  73. package/services/starter-kits/index.ts +2 -0
  74. package/services/starter-kits/starter-kits-service.ts +33 -0
  75. package/services/starter-kits/starter-kits-types.ts +38 -0
  76. package/services/tasks/task-service.ts +10 -0
  77. package/services/tasks/task-types.ts +29 -7
  78. package/services/usage/usage-service.ts +59 -10
  79. package/services/usage/usage-types.ts +178 -27
@@ -0,0 +1,955 @@
1
+ # Task Service Documentation
2
+
3
+ This guide covers how to use the Task Service methods through the CodeGuide service for managing project tasks, task groups, and automated task generation.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Setup](#setup)
8
+ - [Authentication](#authentication)
9
+ - [Methods Overview](#methods-overview)
10
+ - [Detailed Method Documentation](#detailed-method-documentation)
11
+ - [Error Handling](#error-handling)
12
+ - [Examples](#examples)
13
+
14
+ ## Setup
15
+
16
+ ### Installation
17
+
18
+ ```bash
19
+ npm install @codeguide/core
20
+ ```
21
+
22
+ ### Basic Initialization
23
+
24
+ ```typescript
25
+ import { CodeGuide } from '@codeguide/core'
26
+
27
+ // Initialize the CodeGuide service
28
+ const codeguide = new CodeGuide({
29
+ baseUrl: 'https://api.codeguide.dev',
30
+ databaseApiKey: 'sk_your_database_api_key_here', // Recommended
31
+ // Alternative authentication methods:
32
+ // apiKey: 'your_legacy_api_key',
33
+ // jwtToken: 'your_clerk_jwt_token',
34
+ timeout: 30000,
35
+ })
36
+
37
+ // Access the task service
38
+ const tasks = codeguide.tasks
39
+ ```
40
+
41
+ ### Configuration Options
42
+
43
+ The `APIServiceConfig` interface accepts:
44
+
45
+ - `baseUrl` (required): API base URL
46
+ - `databaseApiKey`: Database API key (format: `sk_...`) - **Highest priority**
47
+ - `apiKey`: Legacy API key - **Medium priority**
48
+ - `jwtToken`: Clerk JWT token - **Lowest priority**
49
+ - `timeout`: Request timeout in milliseconds (optional)
50
+
51
+ ## Authentication
52
+
53
+ The service supports multiple authentication methods with automatic priority handling:
54
+
55
+ 1. **Database API Key** (recommended): `sk_...` format
56
+ 2. **Legacy API Key**: Older API key format
57
+ 3. **Clerk JWT Token**: JWT-based authentication
58
+
59
+ The service will automatically use the highest priority authentication method available.
60
+
61
+ ## Methods Overview
62
+
63
+ The Task Service provides the following methods:
64
+
65
+ | Method | Description | Endpoint |
66
+ | --------------------------------- | -------------------------------------- | -------------------------------------- |
67
+ | `getAllTaskGroups()` | Get all task groups | `GET /task-groups` |
68
+ | `getPaginatedTaskGroups()` | Get paginated task groups | `GET /task-groups/paginated` |
69
+ | `getTaskGroupById()` | Get task group by ID | `GET /task-groups/{id}` |
70
+ | `createTaskGroup()` | Create a new task group | `POST /task-groups` |
71
+ | `createTaskGroupWithCodespace()` | Create task group with codespace task | Custom method |
72
+ | `updateTaskGroup()` | Update task group | `PUT /project-tasks/task-groups/{id}` |
73
+ | `deleteTaskGroup()` | Delete task group | `DELETE /task-groups/{id}` |
74
+ | `getAllProjectTasks()` | Get all project tasks | `GET /project-tasks` |
75
+ | `getPaginatedProjectTasks()` | Get paginated project tasks | `GET /project-tasks/paginated` |
76
+ | `getProjectTaskById()` | Get project task by ID | `GET /project-tasks/{id}` |
77
+ | `createProjectTask()` | Create a new project task | `POST /project-tasks` |
78
+ | `updateProjectTask()` | Update project task | `PUT /project-tasks/{id}` |
79
+ | `deleteProjectTask()` | Delete project task | `DELETE /project-tasks/{id}` |
80
+ | `generateTasks()` | Generate tasks for project | `POST /project-tasks/generate-tasks` |
81
+ | `getTasksByProject()` | Get tasks by project | `GET /project-tasks/by-project/{id}` |
82
+ | `updateTask()` | Update task with AI result | `PUT /project-tasks/{id}` |
83
+
84
+ ## Detailed Method Documentation
85
+
86
+ ### Task Groups Methods
87
+
88
+ #### 1. getAllTaskGroups()
89
+
90
+ Retrieves all task groups for the authenticated user.
91
+
92
+ ##### Signature
93
+
94
+ ```typescript
95
+ async getAllTaskGroups(): Promise<TaskGroup[]>
96
+ ```
97
+
98
+ ##### Response
99
+
100
+ ```typescript
101
+ interface TaskGroup {
102
+ id: string
103
+ name: string
104
+ description?: string
105
+ user_id: string
106
+ project_id: string
107
+ created_at: string
108
+ updated_at: string
109
+ project_tasks: ProjectTask[]
110
+ prd_content?: string
111
+ raw_tasks?: {
112
+ tasks: RawTask[]
113
+ expanded_tasks: RawTask[]
114
+ }
115
+ codespace_task_id?: string
116
+ }
117
+
118
+ interface RawTask {
119
+ id: number
120
+ title: string
121
+ description?: string
122
+ priority?: string
123
+ status?: string
124
+ }
125
+ ```
126
+
127
+ ##### Example
128
+
129
+ ```typescript
130
+ const taskGroups = await tasks.getAllTaskGroups()
131
+
132
+ console.log(`Found ${taskGroups.length} task groups`)
133
+ taskGroups.forEach(group => {
134
+ console.log(`- ${group.name} (${group.project_tasks?.length || 0} tasks)`)
135
+ if (group.codespace_task_id) {
136
+ console.log(` Codespace Task: ${group.codespace_task_id}`)
137
+ }
138
+ })
139
+ ```
140
+
141
+ #### 2. getPaginatedTaskGroups()
142
+
143
+ Retrieves task groups with pagination support.
144
+
145
+ ##### Signature
146
+
147
+ ```typescript
148
+ async getPaginatedTaskGroups(params: PaginatedTaskGroupsRequest): Promise<PaginatedTaskGroupsResponse>
149
+ ```
150
+
151
+ ##### Parameters
152
+
153
+ ```typescript
154
+ interface PaginatedTaskGroupsRequest {
155
+ page?: number // Optional (default: 1)
156
+ page_size?: number // Optional (default: 20)
157
+ project_id?: string // Optional: Filter by project ID
158
+ }
159
+ ```
160
+
161
+ ##### Response
162
+
163
+ ```typescript
164
+ interface PaginatedTaskGroupsResponse {
165
+ status: string
166
+ data: TaskGroup[]
167
+ pagination: {
168
+ total: number
169
+ page: number
170
+ page_size: number
171
+ total_pages: number
172
+ }
173
+ }
174
+ ```
175
+
176
+ ##### Example
177
+
178
+ ```typescript
179
+ const response = await tasks.getPaginatedTaskGroups({
180
+ page: 1,
181
+ page_size: 10,
182
+ project_id: 'project_123'
183
+ })
184
+
185
+ console.log(`Page ${response.pagination.page} of ${response.pagination.total_pages}`)
186
+ console.log(`Total: ${response.pagination.total} task groups`)
187
+
188
+ response.data.forEach(group => {
189
+ console.log(`- ${group.name}`)
190
+ })
191
+ ```
192
+
193
+ #### 3. getTaskGroupById()
194
+
195
+ Retrieves a specific task group by ID.
196
+
197
+ ##### Signature
198
+
199
+ ```typescript
200
+ async getTaskGroupById(taskGroupId: string): Promise<TaskGroup>
201
+ ```
202
+
203
+ ##### Parameters
204
+
205
+ - `taskGroupId` (string, required): The ID of the task group
206
+
207
+ ##### Example
208
+
209
+ ```typescript
210
+ const taskGroup = await tasks.getTaskGroupById('task_group_123')
211
+
212
+ console.log(`Task Group: ${taskGroup.name}`)
213
+ if (taskGroup.description) {
214
+ console.log(`Description: ${taskGroup.description}`)
215
+ }
216
+ console.log(`Tasks: ${taskGroup.project_tasks?.length || 0}`)
217
+ ```
218
+
219
+ #### 4. createTaskGroup()
220
+
221
+ Creates a new task group.
222
+
223
+ ##### Signature
224
+
225
+ ```typescript
226
+ async createTaskGroup(request: CreateTaskGroupRequest): Promise<TaskGroup>
227
+ ```
228
+
229
+ ##### Parameters
230
+
231
+ ```typescript
232
+ interface CreateTaskGroupRequest {
233
+ name: string // Required
234
+ description?: string // Optional
235
+ project_id: string // Required
236
+ include_codespace_task?: boolean // Optional
237
+ project_description?: string // Optional
238
+ }
239
+ ```
240
+
241
+ ##### Example
242
+
243
+ ```typescript
244
+ const taskGroup = await tasks.createTaskGroup({
245
+ name: 'User Authentication',
246
+ description: 'Tasks related to user authentication and authorization',
247
+ project_id: 'project_123'
248
+ })
249
+
250
+ console.log(`Created task group: ${taskGroup.id}`)
251
+ ```
252
+
253
+ #### 5. createTaskGroupWithCodespace()
254
+
255
+ Creates a task group and optionally generates a codespace task from the project description.
256
+
257
+ ##### Signature
258
+
259
+ ```typescript
260
+ async createTaskGroupWithCodespace(
261
+ request: CreateTaskGroupRequest,
262
+ codespaceService: CodespaceService
263
+ ): Promise<TaskGroup>
264
+ ```
265
+
266
+ ##### Parameters
267
+
268
+ - `request`: Same as `createTaskGroup()` but with optional `include_codespace_task` and `project_description`
269
+ - `codespaceService`: An instance of the CodespaceService
270
+
271
+ ##### Example
272
+
273
+ ```typescript
274
+ const taskGroup = await tasks.createTaskGroupWithCodespace(
275
+ {
276
+ name: 'E-commerce Features',
277
+ description: 'Core e-commerce functionality',
278
+ project_id: 'project_123',
279
+ include_codespace_task: true,
280
+ project_description: 'Implement shopping cart, checkout process, and payment integration'
281
+ },
282
+ codeguide.codespace
283
+ )
284
+
285
+ console.log(`Created task group: ${taskGroup.name}`)
286
+ if (taskGroup.codespace_task_id) {
287
+ console.log(`Associated codespace task: ${taskGroup.codespace_task_id}`)
288
+ }
289
+ ```
290
+
291
+ #### 6. updateTaskGroup()
292
+
293
+ Updates an existing task group.
294
+
295
+ ##### Signature
296
+
297
+ ```typescript
298
+ async updateTaskGroup(taskGroupId: string, request: UpdateTaskGroupRequest): Promise<TaskGroup>
299
+ ```
300
+
301
+ ##### Parameters
302
+
303
+ ```typescript
304
+ interface UpdateTaskGroupRequest {
305
+ project_id?: string
306
+ prd_content?: string
307
+ raw_tasks?: {
308
+ tasks: RawTask[]
309
+ expanded_tasks: RawTask[]
310
+ }
311
+ codespace_task_id?: string
312
+ }
313
+ ```
314
+
315
+ ##### Example
316
+
317
+ ```typescript
318
+ const updatedGroup = await tasks.updateTaskGroup('task_group_123', {
319
+ prd_content: 'Updated product requirements document...',
320
+ codespace_task_id: 'codespace_task_456'
321
+ })
322
+
323
+ console.log(`Updated task group: ${updatedGroup.name}`)
324
+ ```
325
+
326
+ #### 7. deleteTaskGroup()
327
+
328
+ Deletes a task group.
329
+
330
+ ##### Signature
331
+
332
+ ```typescript
333
+ async deleteTaskGroup(taskGroupId: string): Promise<{ status: string; message: string }>
334
+ ```
335
+
336
+ ##### Parameters
337
+
338
+ - `taskGroupId` (string, required): The ID of the task group to delete
339
+
340
+ ##### Example
341
+
342
+ ```typescript
343
+ const response = await tasks.deleteTaskGroup('task_group_123')
344
+
345
+ console.log(response.message) // "Task group deleted successfully"
346
+ ```
347
+
348
+ ### Project Tasks Methods
349
+
350
+ #### 8. getAllProjectTasks()
351
+
352
+ Retrieves all project tasks with optional filtering.
353
+
354
+ ##### Signature
355
+
356
+ ```typescript
357
+ async getAllProjectTasks(filters?: {
358
+ task_group_id?: string
359
+ parent_task_id?: string
360
+ status?: string
361
+ }): Promise<ProjectTask[]>
362
+ ```
363
+
364
+ ##### Parameters
365
+
366
+ - `filters` (optional): Object containing filter criteria
367
+
368
+ ##### Response
369
+
370
+ ```typescript
371
+ interface ProjectTask {
372
+ id: string
373
+ title: string
374
+ description?: string
375
+ status: string
376
+ priority?: string
377
+ user_id: string
378
+ task_group_id: string
379
+ parent_task_id?: string
380
+ ordinal: number
381
+ created_at: string
382
+ updated_at: string
383
+ subtasks?: ProjectTask[]
384
+ }
385
+ ```
386
+
387
+ ##### Example
388
+
389
+ ```typescript
390
+ // Get all tasks
391
+ const allTasks = await tasks.getAllProjectTasks()
392
+
393
+ // Filter by task group
394
+ const groupTasks = await tasks.getAllProjectTasks({
395
+ task_group_id: 'task_group_123'
396
+ })
397
+
398
+ // Filter by status
399
+ const completedTasks = await tasks.getAllProjectTasks({
400
+ status: 'completed'
401
+ })
402
+
403
+ console.log(`Found ${completedTasks.length} completed tasks`)
404
+ ```
405
+
406
+ #### 9. getPaginatedProjectTasks()
407
+
408
+ Retrieves project tasks with pagination and advanced filtering.
409
+
410
+ ##### Signature
411
+
412
+ ```typescript
413
+ async getPaginatedProjectTasks(params: PaginatedProjectTasksRequest): Promise<PaginatedProjectTasksResponse>
414
+ ```
415
+
416
+ ##### Parameters
417
+
418
+ ```typescript
419
+ interface PaginatedProjectTasksRequest {
420
+ page?: number // Optional (default: 1)
421
+ page_size?: number // Optional (default: 20)
422
+ task_group_id?: string // Optional
423
+ parent_task_id?: string // Optional
424
+ status?: string // Optional
425
+ search_query?: string // Optional
426
+ }
427
+ ```
428
+
429
+ ##### Response
430
+
431
+ ```typescript
432
+ interface PaginatedProjectTasksResponse {
433
+ status: string
434
+ data: ProjectTask[]
435
+ pagination: {
436
+ total: number
437
+ page: number
438
+ page_size: number
439
+ total_pages: number
440
+ }
441
+ }
442
+ ```
443
+
444
+ ##### Example
445
+
446
+ ```typescript
447
+ const response = await tasks.getPaginatedProjectTasks({
448
+ page: 1,
449
+ page_size: 15,
450
+ status: 'in_progress',
451
+ search_query: 'authentication'
452
+ })
453
+
454
+ console.log(`Found ${response.pagination.total} matching tasks`)
455
+ response.data.forEach(task => {
456
+ console.log(`- ${task.title} (${task.status})`)
457
+ })
458
+ ```
459
+
460
+ #### 10. getProjectTaskById()
461
+
462
+ Retrieves a specific project task by ID.
463
+
464
+ ##### Signature
465
+
466
+ ```typescript
467
+ async getProjectTaskById(taskId: string): Promise<ProjectTask>
468
+ ```
469
+
470
+ ##### Parameters
471
+
472
+ - `taskId` (string, required): The ID of the project task
473
+
474
+ ##### Example
475
+
476
+ ```typescript
477
+ const task = await tasks.getProjectTaskById('task_123')
478
+
479
+ console.log(`Task: ${task.title}`)
480
+ console.log(`Status: ${task.status}`)
481
+ console.log(`Priority: ${task.priority || 'Not set'}`)
482
+
483
+ if (task.subtasks && task.subtasks.length > 0) {
484
+ console.log(`Subtasks: ${task.subtasks.length}`)
485
+ }
486
+ ```
487
+
488
+ #### 11. createProjectTask()
489
+
490
+ Creates a new project task.
491
+
492
+ ##### Signature
493
+
494
+ ```typescript
495
+ async createProjectTask(request: CreateProjectTaskRequest): Promise<ProjectTask>
496
+ ```
497
+
498
+ ##### Parameters
499
+
500
+ ```typescript
501
+ interface CreateProjectTaskRequest {
502
+ title: string // Required
503
+ description?: string // Optional
504
+ task_group_id: string // Required
505
+ parent_task_id?: string // Optional
506
+ ordinal?: number // Optional
507
+ }
508
+ ```
509
+
510
+ ##### Example
511
+
512
+ ```typescript
513
+ const task = await tasks.createProjectTask({
514
+ title: 'Implement login API endpoint',
515
+ description: 'Create RESTful API endpoint for user authentication',
516
+ task_group_id: 'task_group_123',
517
+ ordinal: 1
518
+ })
519
+
520
+ console.log(`Created task: ${task.id}`)
521
+ ```
522
+
523
+ #### 12. updateProjectTask()
524
+
525
+ Updates an existing project task.
526
+
527
+ ##### Signature
528
+
529
+ ```typescript
530
+ async updateProjectTask(taskId: string, request: UpdateProjectTaskRequest): Promise<ProjectTask>
531
+ ```
532
+
533
+ ##### Parameters
534
+
535
+ ```typescript
536
+ interface UpdateProjectTaskRequest {
537
+ title?: string
538
+ description?: string
539
+ status?: string
540
+ task_group_id?: string
541
+ parent_task_id?: string
542
+ ordinal?: number
543
+ }
544
+ ```
545
+
546
+ ##### Example
547
+
548
+ ```typescript
549
+ const updatedTask = await tasks.updateProjectTask('task_123', {
550
+ status: 'completed',
551
+ description: 'Updated description with implementation details'
552
+ })
553
+
554
+ console.log(`Task status: ${updatedTask.status}`)
555
+ ```
556
+
557
+ #### 13. deleteProjectTask()
558
+
559
+ Deletes a project task.
560
+
561
+ ##### Signature
562
+
563
+ ```typescript
564
+ async deleteProjectTask(taskId: string): Promise<{ status: string; message: string }>
565
+ ```
566
+
567
+ ##### Parameters
568
+
569
+ - `taskId` (string, required): The ID of the project task to delete
570
+
571
+ ##### Example
572
+
573
+ ```typescript
574
+ const response = await tasks.deleteProjectTask('task_123')
575
+
576
+ console.log(response.message) // "Task deleted successfully"
577
+ ```
578
+
579
+ ### Advanced Methods
580
+
581
+ #### 14. generateTasks()
582
+
583
+ Automatically generates tasks for a project using AI.
584
+
585
+ ##### Signature
586
+
587
+ ```typescript
588
+ async generateTasks(request: GenerateTasksRequest): Promise<GenerateTasksResponse>
589
+ ```
590
+
591
+ ##### Parameters
592
+
593
+ ```typescript
594
+ interface GenerateTasksRequest {
595
+ project_id: string // Required
596
+ }
597
+ ```
598
+
599
+ ##### Response
600
+
601
+ ```typescript
602
+ interface GenerateTasksResponse {
603
+ status: string
604
+ message: string
605
+ data?: {
606
+ task_groups_created: number
607
+ tasks_created: number
608
+ }
609
+ }
610
+ ```
611
+
612
+ ##### Example
613
+
614
+ ```typescript
615
+ const response = await tasks.generateTasks({
616
+ project_id: 'project_123'
617
+ })
618
+
619
+ console.log(response.message)
620
+ if (response.data) {
621
+ console.log(`Created ${response.data.task_groups_created} task groups`)
622
+ console.log(`Created ${response.data.tasks_created} tasks`)
623
+ }
624
+ ```
625
+
626
+ #### 15. getTasksByProject()
627
+
628
+ Retrieves all tasks and task groups for a specific project.
629
+
630
+ ##### Signature
631
+
632
+ ```typescript
633
+ async getTasksByProject(request: GetTasksByProjectRequest): Promise<GetTasksByProjectResponse>
634
+ ```
635
+
636
+ ##### Parameters
637
+
638
+ ```typescript
639
+ interface GetTasksByProjectRequest {
640
+ project_id: string // Required
641
+ status?: string // Optional
642
+ task_group_id?: string // Optional
643
+ }
644
+ ```
645
+
646
+ ##### Response
647
+
648
+ ```typescript
649
+ interface GetTasksByProjectResponse {
650
+ status: string
651
+ data: {
652
+ task_groups: TaskGroup[]
653
+ tasks: ProjectTask[]
654
+ }
655
+ }
656
+ ```
657
+
658
+ ##### Example
659
+
660
+ ```typescript
661
+ const response = await tasks.getTasksByProject({
662
+ project_id: 'project_123',
663
+ status: 'in_progress'
664
+ })
665
+
666
+ console.log(`Project has ${response.data.task_groups.length} task groups`)
667
+ console.log(`Project has ${response.data.tasks.length} tasks`)
668
+
669
+ response.data.task_groups.forEach(group => {
670
+ console.log(`- Group: ${group.name}`)
671
+ })
672
+ ```
673
+
674
+ #### 16. updateTask()
675
+
676
+ Updates a task with AI-generated results or other fields.
677
+
678
+ ##### Signature
679
+
680
+ ```typescript
681
+ async updateTask(taskId: string, request: UpdateTaskRequest): Promise<UpdateTaskResponse>
682
+ ```
683
+
684
+ ##### Parameters
685
+
686
+ ```typescript
687
+ interface UpdateTaskRequest {
688
+ status?: string
689
+ ai_result?: string // AI-generated content or results
690
+ title?: string
691
+ description?: string
692
+ }
693
+ ```
694
+
695
+ ##### Response
696
+
697
+ ```typescript
698
+ interface UpdateTaskResponse {
699
+ status: string
700
+ message: string
701
+ data: {
702
+ task: ProjectTask
703
+ }
704
+ }
705
+ ```
706
+
707
+ ##### Example
708
+
709
+ ```typescript
710
+ const response = await tasks.updateTask('task_123', {
711
+ status: 'completed',
712
+ ai_result: 'AI-generated implementation suggestions and code review results'
713
+ })
714
+
715
+ console.log(response.message)
716
+ console.log(`Updated task: ${response.data.task.title}`)
717
+ ```
718
+
719
+ ## Error Handling
720
+
721
+ All methods throw errors for various failure conditions. Common error types include:
722
+
723
+ ### Validation Errors
724
+
725
+ ```typescript
726
+ try {
727
+ await tasks.createTaskGroup({})
728
+ } catch (error) {
729
+ console.error(error.message) // "name is required" or "project_id is required"
730
+ }
731
+ ```
732
+
733
+ ### Network/Server Errors
734
+
735
+ ```typescript
736
+ try {
737
+ await tasks.getProjectTaskById('invalid_id')
738
+ } catch (error) {
739
+ if (error.response?.status === 404) {
740
+ console.error('Task not found')
741
+ } else if (error.response?.status === 401) {
742
+ console.error('Unauthorized - check your API credentials')
743
+ } else {
744
+ console.error('Network error:', error.message)
745
+ }
746
+ }
747
+ ```
748
+
749
+ ### Timeout Errors
750
+
751
+ ```typescript
752
+ try {
753
+ await tasks.generateTasks({ project_id: 'large_project_id' })
754
+ } catch (error) {
755
+ if (error.code === 'ECONNABORTED') {
756
+ console.error('Request timed out. The task generation might take longer.')
757
+ }
758
+ }
759
+ ```
760
+
761
+ ## Complete Examples
762
+
763
+ ### Example 1: Complete Task Management Workflow
764
+
765
+ ```typescript
766
+ import { CodeGuide } from '@codeguide/core'
767
+
768
+ const codeguide = new CodeGuide({
769
+ baseUrl: 'https://api.codeguide.dev',
770
+ databaseApiKey: process.env.CODEGUIDE_API_KEY,
771
+ })
772
+
773
+ async function completeTaskWorkflow() {
774
+ try {
775
+ // 1. Create a task group with codespace integration
776
+ const taskGroup = await codeguide.tasks.createTaskGroupWithCodespace(
777
+ {
778
+ name: 'API Development',
779
+ description: 'RESTful API endpoints for user management',
780
+ project_id: 'project_123',
781
+ include_codespace_task: true,
782
+ project_description: 'Create comprehensive REST API for user authentication, registration, and profile management'
783
+ },
784
+ codeguide.codespace
785
+ )
786
+
787
+ console.log(`Created task group: ${taskGroup.name}`)
788
+
789
+ // 2. Create individual tasks
790
+ const loginTask = await codeguide.tasks.createProjectTask({
791
+ title: 'Implement login endpoint',
792
+ description: 'POST /api/auth/login with JWT token generation',
793
+ task_group_id: taskGroup.id,
794
+ ordinal: 1
795
+ })
796
+
797
+ const registerTask = await codeguide.tasks.createProjectTask({
798
+ title: 'Implement registration endpoint',
799
+ description: 'POST /api/auth/register with email verification',
800
+ task_group_id: taskGroup.id,
801
+ ordinal: 2
802
+ })
803
+
804
+ console.log(`Created tasks: ${loginTask.title}, ${registerTask.title}`)
805
+
806
+ // 3. Update task with AI-generated results
807
+ await codeguide.tasks.updateTask(loginTask.id, {
808
+ ai_result: 'Implemented secure login with bcrypt password hashing and JWT tokens',
809
+ status: 'completed'
810
+ })
811
+
812
+ // 4. Get all tasks for the project
813
+ const projectTasks = await codeguide.tasks.getTasksByProject({
814
+ project_id: 'project_123'
815
+ })
816
+
817
+ console.log(`Project now has ${projectTasks.data.tasks.length} tasks`)
818
+ console.log(`Project has ${projectTasks.data.task_groups.length} task groups`)
819
+
820
+ } catch (error) {
821
+ console.error('Workflow failed:', error.message)
822
+ }
823
+ }
824
+
825
+ completeTaskWorkflow()
826
+ ```
827
+
828
+ ### Example 2: Paginated Task Management
829
+
830
+ ```typescript
831
+ async function paginatedTaskManagement() {
832
+ const taskGroupId = 'task_group_123'
833
+ let currentPage = 1
834
+ const pageSize = 10
835
+
836
+ try {
837
+ // Get paginated tasks
838
+ const response = await codeguide.tasks.getPaginatedProjectTasks({
839
+ page: currentPage,
840
+ page_size: pageSize,
841
+ task_group_id: taskGroupId
842
+ })
843
+
844
+ console.log(`Page ${currentPage} of ${response.pagination.total_pages}`)
845
+ console.log(`Showing ${response.data.length} of ${response.pagination.total} tasks`)
846
+
847
+ // Display tasks
848
+ response.data.forEach(task => {
849
+ console.log(`${task.ordinal}. ${task.title} - ${task.status}`)
850
+ if (task.description) {
851
+ console.log(` ${task.description.substring(0, 100)}...`)
852
+ }
853
+ })
854
+
855
+ // Load more pages if needed
856
+ if (currentPage < response.pagination.total_pages) {
857
+ currentPage++
858
+ // Load next page...
859
+ }
860
+
861
+ } catch (error) {
862
+ console.error('Failed to load paginated tasks:', error.message)
863
+ }
864
+ }
865
+ ```
866
+
867
+ ### Example 3: Task Search and Filtering
868
+
869
+ ```typescript
870
+ async function taskSearchAndFilter() {
871
+ try {
872
+ // Search for tasks
873
+ const searchResults = await codeguide.tasks.getPaginatedProjectTasks({
874
+ page: 1,
875
+ page_size: 20,
876
+ search_query: 'authentication',
877
+ status: 'in_progress'
878
+ })
879
+
880
+ console.log(`Found ${searchResults.pagination.total} tasks matching "authentication"`)
881
+
882
+ // Filter by task group
883
+ const groupTasks = await codeguide.tasks.getAllProjectTasks({
884
+ task_group_id: 'task_group_123',
885
+ status: 'completed'
886
+ })
887
+
888
+ console.log(`Completed tasks in group: ${groupTasks.length}`)
889
+
890
+ // Get tasks with subtasks
891
+ const tasksWithSubtasks = groupTasks.filter(task =>
892
+ task.subtasks && task.subtasks.length > 0
893
+ )
894
+
895
+ tasksWithSubtasks.forEach(task => {
896
+ console.log(`Task: ${task.title}`)
897
+ console.log(`Subtasks: ${task.subtasks?.length}`)
898
+ task.subtasks?.forEach(subtask => {
899
+ console.log(` - ${subtask.title} (${subtask.status})`)
900
+ })
901
+ })
902
+
903
+ } catch (error) {
904
+ console.error('Task search failed:', error.message)
905
+ }
906
+ }
907
+ ```
908
+
909
+ ## Best Practices
910
+
911
+ 1. **Use Pagination** for large datasets to avoid memory issues
912
+ 2. **Implement Proper Error Handling** with try-catch blocks and status code checking
913
+ 3. **Use Ordinal Field** to maintain task order within groups
914
+ 4. **Leverage Parent-Child Relationships** for complex task hierarchies
915
+ 5. **Cache Task Data** when possible to reduce API calls
916
+ 6. **Use Search Functionality** for finding specific tasks quickly
917
+ 7. **Combine with Codespace Service** for AI-powered task creation and management
918
+
919
+ ## Type Exports
920
+
921
+ The package exports the following types for TypeScript users:
922
+
923
+ ```typescript
924
+ import type {
925
+ TaskGroup,
926
+ ProjectTask,
927
+ RawTask,
928
+ CreateTaskGroupRequest,
929
+ UpdateTaskGroupRequest,
930
+ CreateProjectTaskRequest,
931
+ UpdateProjectTaskRequest,
932
+ TaskGroupListResponse,
933
+ TaskGroupResponse,
934
+ ProjectTaskListResponse,
935
+ ProjectTaskResponse,
936
+ PaginatedTaskGroupsRequest,
937
+ PaginatedTaskGroupsResponse,
938
+ PaginatedProjectTasksRequest,
939
+ PaginatedProjectTasksResponse,
940
+ GenerateTasksRequest,
941
+ GenerateTasksResponse,
942
+ GetTasksByProjectRequest,
943
+ GetTasksByProjectResponse,
944
+ UpdateTaskRequest,
945
+ UpdateTaskResponse,
946
+ } from '@codeguide/core'
947
+ ```
948
+
949
+ ## Related Documentation
950
+
951
+ - [Projects Service](./projects-service.md) - Project management
952
+ - [Codespace Service](./codespace-service.md) - AI-powered coding tasks
953
+ - [CodeGuide Client](./codeguide-client.md) - Client initialization
954
+
955
+ For more information, visit the [API documentation](https://docs.codeguide.dev) or check the [GitHub repository](https://github.com/codeguide/cli).