forked from TrafficGuard/typedai
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcodeTaskService.ts
More file actions
256 lines (227 loc) · 11.3 KB
/
codeTaskService.ts
File metadata and controls
256 lines (227 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import type {
CodeTask,
CodeTaskPreset,
CommitChangesData,
CreateCodeTaskData,
UpdateCodeReviewData,
UpdateCodeTaskData,
} from '#shared/codeTask/codeTask.model';
import type { FileSystemNode } from '#shared/files/fileSystemService';
/**
* Interface for managing CodeTask data and orchestrating the CodeTask Coding workflow.
*/
export interface CodeTaskService {
// --- Core CRUD ---
/**
* Creates a new CodeTask based on initial user input.
* Sets the status to 'initializing'.
* Asynchronously triggers the initialization process (cloning, file selection, design gen).
* @param userId The ID of the user creating the codeTask.
* @param codeTaskData Data for the new codeTask (title, instructions, repo info, etc.).
* @returns The newly created CodeTask with status 'initializing'.
*/
createCodeTask(userId: string, codeTaskData: CreateCodeTaskData): Promise<CodeTask>;
/**
* Retrieves a specific CodeTask by its ID for a given user.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask to retrieve.
* @returns The CodeTask if found and authorized, otherwise null.
*/
getCodeTask(userId: string, codeTaskId: string): Promise<CodeTask | null>;
/**
* Lists all CodeTasks for the current user, ordered by creation date descending.
* @param userId The ID of the user whose codeTasks to list.
* @returns An array of CodeTasks.
*/
listCodeTasks(userId: string): Promise<CodeTask[]>;
/**
* Updates specified fields of a CodeTask. Use for simple updates like editing
* the title, instructions, manually changing fileSelection, or internal status updates.
* For actions triggering agents, use specific methods below.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask to update.
* @param updates An object containing the fields to update. Must match UpdateCodeTaskData.
* @returns {Promise<void>}
*/
updateCodeTask(userId: string, codeTaskId: string, updates: UpdateCodeTaskData): Promise<void>;
/**
* Deletes a CodeTask by its ID for a given user. Cleans up associated resources (e.g., workspace).
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask to delete.
* @returns {Promise<void>}
*/
deleteCodeTask(userId: string, codeTaskId: string): Promise<void>;
// --- Preset Management ---
/**
* Saves a new CodeTask Preset configuration for the user.
* @param userId The ID of the user saving the preset.
* @param name The user-defined name for the preset.
* @param config The configuration data to save, excluding title and instructions.
* @returns The newly created CodeTaskPreset object.
*/
saveCodeTaskPreset(userId: string, name: string, config: Omit<CreateCodeTaskData, 'title' | 'instructions'>): Promise<CodeTaskPreset>;
/**
* Lists all CodeTask Presets saved by the user.
* @param userId The ID of the user whose presets to list.
* @returns An array of CodeTaskPreset objects.
*/
listCodeTaskPresets(userId: string): Promise<CodeTaskPreset[]>;
/**
* Deletes a specific CodeTask Preset for the user.
* @param userId The ID of the user owning the preset.
* @param presetId The ID of the CodeTaskPreset to delete.
* @returns {Promise<void>}
*/
/**
* Saves a new CodeTask Preset configuration for the user.
* @param userId The ID of the user saving the preset.
* @param name The user-defined name for the preset.
* @param config The configuration data to save, excluding title and instructions.
* @returns The newly created CodeTaskPreset object.
*/
saveCodeTaskPreset(userId: string, name: string, config: Omit<CreateCodeTaskData, 'title' | 'instructions'>): Promise<CodeTaskPreset>;
/**
* Lists all CodeTask Presets saved by the user.
* @param userId The ID of the user whose presets to list.
* @returns An array of CodeTaskPreset objects.
*/
listCodeTaskPresets(userId: string): Promise<CodeTaskPreset[]>;
/**
* Deletes a specific CodeTask Preset for the user.
* @param userId The ID of the user owning the preset.
* @param presetId The ID of the CodeTaskPreset to delete.
* @returns {Promise<void>}
*/
deleteCodeTaskPreset(userId: string, presetId: string): Promise<void>;
// --- Workflow Actions ---
/**
* [Internal or Explicit Trigger] Handles the initialization after creation:
* Clones repo, creates branch (if needed), runs selectFilesAgent, generates initial design.
* Updates codeTask status from 'initializing' to 'design_review' or 'error'.
* Populates 'fileSelection' and 'designAnswer'.
* NOTE: This might be triggered internally after createCodeTask or via a dedicated endpoint/call.
* If triggered explicitly:
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask to initialize.
* @returns {Promise<void>} Resolves when the initialization process is queued or complete.
*/
// initializeCodeTask?(userId: string, codeTaskId: string): Promise<void>; // Keep optional depending on trigger mechanism
/**
* Updates the file selection based on user prompt.
* Triggers agent, sets status to `updating_selection`.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param prompt The user's prompt for refining the file selection.
* @returns {Promise<void>} Resolves when the update process is queued.
*/
updateSelectionWithPrompt(userId: string, codeTaskId: string, prompt: string): Promise<void>;
/**
* Generates a detailed design, potentially with variations.
* Triggers agent, sets status to `generating_design`.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param variations The number of design variations to generate (optional, defaults might apply).
* @returns {Promise<void>} Resolves when the design generation is queued.
*/
generateDetailedDesign(userId: string, codeTaskId: string, variations: number): Promise<void>;
/**
* Accepts a specific design variation and proceeds to the coding phase.
* Sets status to `coding`, stores selected variations.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param variations The number/index of the design variation accepted by the user.
* @returns {Promise<void>} Resolves when the acceptance is processed and coding is queued.
*/
acceptDesign(userId: string, codeTaskId: string, variations: number): Promise<void>;
/**
* Updates the design from manual user edits
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param updatedDesign The updated design provided by the user
* @returns {Promise<void>} Resolves when updated design is saved to the repository.
*/
updateDesign(userId: string, codeTaskId: string, updatedDesign: string): Promise<void>;
/**
* Updates the design ('designAnswer') based on user instructions for an LLM agent to update.
* Triggers an AI agent call. Updates codeTask status if needed (e.g., back to 'design_review').
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param designUpdateInstructions Instructions on how to update the design.
*/
updateDesignFromInstructions(userId: string, codeTaskId: string, designUpdateInstructions: string): Promise<void>;
/**
* Executes the approved design by triggering code generation.
* Triggers `codeEditingAgent`, sets status to `coding`.
* Consider if `startCoding` can be reused/adapted in implementation.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @returns {Promise<void>} Resolves when the coding process is queued.
*/
executeDesign(userId: string, codeTaskId: string): Promise<void>;
/**
* Starts the code generation process based on the current 'fileSelection' and 'designAnswer'.
* Sets status to 'coding'. Asynchronously triggers the CodeEditingAgent.
* Agent completion will update status to 'code_review' and populate 'codeDiff'.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @returns {Promise<void>} Resolves when the coding process is queued.
*/
startCoding(userId: string, codeTaskId: string): Promise<void>;
/**
* Requests revisions to the generated code based on user review comments.
* Sets status back to 'coding'. Asynchronously triggers the CodeEditingAgent with comments.
* Agent completion will update status to 'code_review' and update 'codeDiff'.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param data Object containing the review comments/instructions.
* @returns {Promise<void>} Resolves when the code revision process is queued.
*/
updateCodeWithComments(userId: string, codeTaskId: string, data: UpdateCodeReviewData): Promise<void>;
/**
* Finalizes the Code task: commits the changes, pushes the branch,
* and optionally creates a Pull/Merge Request.
* Updates codeTask with commit SHA, PR URL (if applicable), and sets status to 'completed' or 'monitoring_ci'.
* Requires codeTask status to be 'code_review' (or similar state indicating readiness).
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param data Object containing the final commit title and message.
* @returns The final commit SHA and PR URL.
*/
commitChanges(userId: string, codeTaskId: string, data: CommitChangesData): Promise<{ commitSha: string; pullRequestUrl?: string }>;
// --- Helper / Supporting Methods ---
/**
* Retrieves the list of branches for a given repository.
* Needed for the UI during codeTask creation.
* @param userId The ID of the user making the request.
* @param codeTaskId
* @param repositorySource The source type ('local', 'github', 'gitlab').
* @param repositoryId The specific repository identifier.
* @returns A promise resolving to an array of branch names.
*/
getBranchList(userId: string, codeTaskId: string, repositorySource: 'local' | 'github' | 'gitlab', repositoryId: string): Promise<string[]>;
/**
* Retrieves the file system tree structure for the checked-out repository within a codeTask's workspace.
* Needed for the UI file selection component. Requires the codeTask to be initialized.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param directoryPath The subdirectory to list (optional, defaults to root).
* @returns A promise resolving to the FileSystemNode root object.
*/
getFileSystemTree(userId: string, codeTaskId: string, directoryPath?: string): Promise<FileSystemNode>;
/**
* Retrieves the content of a specific file within the codeTask's workspace.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @param filePath The path to the file relative to the repository root.
* @returns A promise resolving to the file content as a string.
*/
getFileContent(userId: string, codeTaskId: string, filePath: string): Promise<string>;
/**
* (Optional) Applies the AI-proposed fix for a CI/CD failure.
* May trigger another coding/commit cycle.
* @param userId The ID of the user owning the codeTask.
* @param codeTaskId The ID of the CodeTask.
* @returns {Promise<void>}
*/
applyCiCdFix?(userId: string, codeTaskId: string): Promise<void>;
}