@prmichaelsen/task-mcp 0.2.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 (142) hide show
  1. package/.env.example +19 -0
  2. package/AGENT.md +1165 -0
  3. package/CHANGELOG.md +72 -0
  4. package/agent/commands/acp.commit.md +511 -0
  5. package/agent/commands/acp.init.md +376 -0
  6. package/agent/commands/acp.package-install.md +347 -0
  7. package/agent/commands/acp.proceed.md +311 -0
  8. package/agent/commands/acp.report.md +392 -0
  9. package/agent/commands/acp.status.md +280 -0
  10. package/agent/commands/acp.sync.md +323 -0
  11. package/agent/commands/acp.update.md +301 -0
  12. package/agent/commands/acp.validate.md +385 -0
  13. package/agent/commands/acp.version-check-for-updates.md +275 -0
  14. package/agent/commands/acp.version-check.md +190 -0
  15. package/agent/commands/acp.version-update.md +288 -0
  16. package/agent/commands/command.template.md +273 -0
  17. package/agent/commands/git.commit.md +511 -0
  18. package/agent/commands/git.init.md +513 -0
  19. package/agent/design/.gitkeep +0 -0
  20. package/agent/design/acp-task-execution-requirements.md +555 -0
  21. package/agent/design/api-dto-design.md +394 -0
  22. package/agent/design/code-extraction-guide.md +827 -0
  23. package/agent/design/design.template.md +136 -0
  24. package/agent/design/requirements.template.md +387 -0
  25. package/agent/design/rest-api-integration.md +489 -0
  26. package/agent/design/sdk-export-requirements.md +549 -0
  27. package/agent/milestones/.gitkeep +0 -0
  28. package/agent/milestones/milestone-1-{title}.template.md +206 -0
  29. package/agent/milestones/milestone-2-task-infrastructure.md +232 -0
  30. package/agent/milestones/milestone-4-autonomous-execution.md +235 -0
  31. package/agent/patterns/.gitkeep +0 -0
  32. package/agent/patterns/bootstrap.md +1271 -0
  33. package/agent/patterns/bootstrap.template.md +1237 -0
  34. package/agent/patterns/pattern.template.md +364 -0
  35. package/agent/progress.template.yaml +158 -0
  36. package/agent/progress.yaml +375 -0
  37. package/agent/scripts/check-for-updates.sh +88 -0
  38. package/agent/scripts/install.sh +157 -0
  39. package/agent/scripts/uninstall.sh +75 -0
  40. package/agent/scripts/update.sh +139 -0
  41. package/agent/scripts/version.sh +35 -0
  42. package/agent/tasks/.gitkeep +0 -0
  43. package/agent/tasks/task-1-{title}.template.md +225 -0
  44. package/agent/tasks/task-86-task-data-model-schemas.md +143 -0
  45. package/agent/tasks/task-87-task-database-service.md +220 -0
  46. package/agent/tasks/task-88-firebase-client-wrapper.md +139 -0
  47. package/agent/tasks/task-88-task-execution-engine.md +277 -0
  48. package/agent/tasks/task-89-mcp-server-implementation.md +197 -0
  49. package/agent/tasks/task-90-build-configuration.md +146 -0
  50. package/agent/tasks/task-91-deployment-configuration.md +128 -0
  51. package/coverage/base.css +224 -0
  52. package/coverage/block-navigation.js +87 -0
  53. package/coverage/favicon.png +0 -0
  54. package/coverage/index.html +191 -0
  55. package/coverage/lcov-report/base.css +224 -0
  56. package/coverage/lcov-report/block-navigation.js +87 -0
  57. package/coverage/lcov-report/favicon.png +0 -0
  58. package/coverage/lcov-report/index.html +191 -0
  59. package/coverage/lcov-report/prettify.css +1 -0
  60. package/coverage/lcov-report/prettify.js +2 -0
  61. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  62. package/coverage/lcov-report/sorter.js +210 -0
  63. package/coverage/lcov-report/src/client.ts.html +1030 -0
  64. package/coverage/lcov-report/src/constant/collections.ts.html +469 -0
  65. package/coverage/lcov-report/src/constant/index.html +116 -0
  66. package/coverage/lcov-report/src/dto/index.html +116 -0
  67. package/coverage/lcov-report/src/dto/transformers.ts.html +568 -0
  68. package/coverage/lcov-report/src/index.html +146 -0
  69. package/coverage/lcov-report/src/schemas/index.html +116 -0
  70. package/coverage/lcov-report/src/schemas/task.ts.html +547 -0
  71. package/coverage/lcov-report/src/server-factory.ts.html +418 -0
  72. package/coverage/lcov-report/src/server.ts.html +289 -0
  73. package/coverage/lcov-report/src/services/index.html +116 -0
  74. package/coverage/lcov-report/src/services/task-database.service.ts.html +1495 -0
  75. package/coverage/lcov-report/src/tools/index.html +236 -0
  76. package/coverage/lcov-report/src/tools/index.ts.html +292 -0
  77. package/coverage/lcov-report/src/tools/task-add-message.ts.html +277 -0
  78. package/coverage/lcov-report/src/tools/task-complete-task-item.ts.html +343 -0
  79. package/coverage/lcov-report/src/tools/task-create-milestone.ts.html +286 -0
  80. package/coverage/lcov-report/src/tools/task-create-task-item.ts.html +358 -0
  81. package/coverage/lcov-report/src/tools/task-get-next-step.ts.html +460 -0
  82. package/coverage/lcov-report/src/tools/task-get-status.ts.html +316 -0
  83. package/coverage/lcov-report/src/tools/task-report-completion.ts.html +343 -0
  84. package/coverage/lcov-report/src/tools/task-update-progress.ts.html +232 -0
  85. package/coverage/lcov.info +974 -0
  86. package/coverage/prettify.css +1 -0
  87. package/coverage/prettify.js +2 -0
  88. package/coverage/sort-arrow-sprite.png +0 -0
  89. package/coverage/sorter.js +210 -0
  90. package/coverage/src/client.ts.html +1030 -0
  91. package/coverage/src/constant/collections.ts.html +469 -0
  92. package/coverage/src/constant/index.html +116 -0
  93. package/coverage/src/dto/index.html +116 -0
  94. package/coverage/src/dto/transformers.ts.html +568 -0
  95. package/coverage/src/index.html +146 -0
  96. package/coverage/src/schemas/index.html +116 -0
  97. package/coverage/src/schemas/task.ts.html +547 -0
  98. package/coverage/src/server-factory.ts.html +418 -0
  99. package/coverage/src/server.ts.html +289 -0
  100. package/coverage/src/services/index.html +116 -0
  101. package/coverage/src/services/task-database.service.ts.html +1495 -0
  102. package/coverage/src/tools/index.html +236 -0
  103. package/coverage/src/tools/index.ts.html +292 -0
  104. package/coverage/src/tools/task-add-message.ts.html +277 -0
  105. package/coverage/src/tools/task-complete-task-item.ts.html +343 -0
  106. package/coverage/src/tools/task-create-milestone.ts.html +286 -0
  107. package/coverage/src/tools/task-create-task-item.ts.html +358 -0
  108. package/coverage/src/tools/task-get-next-step.ts.html +460 -0
  109. package/coverage/src/tools/task-get-status.ts.html +316 -0
  110. package/coverage/src/tools/task-report-completion.ts.html +343 -0
  111. package/coverage/src/tools/task-update-progress.ts.html +232 -0
  112. package/firestore.rules +95 -0
  113. package/jest.config.js +31 -0
  114. package/package.json +67 -0
  115. package/src/client.spec.ts +199 -0
  116. package/src/client.ts +315 -0
  117. package/src/constant/collections.ts +128 -0
  118. package/src/dto/index.ts +47 -0
  119. package/src/dto/task-api.dto.ts +219 -0
  120. package/src/dto/transformers.spec.ts +462 -0
  121. package/src/dto/transformers.ts +161 -0
  122. package/src/schemas/task.ts +154 -0
  123. package/src/server-factory.spec.ts +70 -0
  124. package/src/server-factory.ts +111 -0
  125. package/src/server.ts +68 -0
  126. package/src/services/task-database.service.e2e.ts +116 -0
  127. package/src/services/task-database.service.spec.ts +479 -0
  128. package/src/services/task-database.service.ts +470 -0
  129. package/src/test-schemas.ts +161 -0
  130. package/src/tools/index.ts +69 -0
  131. package/src/tools/task-add-message.ts +64 -0
  132. package/src/tools/task-complete-task-item.ts +86 -0
  133. package/src/tools/task-create-milestone.ts +67 -0
  134. package/src/tools/task-create-task-item.ts +91 -0
  135. package/src/tools/task-get-next-step.spec.ts +136 -0
  136. package/src/tools/task-get-next-step.ts +125 -0
  137. package/src/tools/task-get-status.spec.ts +213 -0
  138. package/src/tools/task-get-status.ts +77 -0
  139. package/src/tools/task-report-completion.ts +86 -0
  140. package/src/tools/task-update-progress.ts +49 -0
  141. package/src/tools/tools.spec.ts +194 -0
  142. package/tsconfig.json +31 -0
@@ -0,0 +1,827 @@
1
+ # Code Extraction Guide: Roo Code to task-mcp
2
+
3
+ **Purpose**: Document specific code patterns and components to extract from Roo Code for task-mcp implementation
4
+ **Created**: 2026-02-16
5
+ **Status**: Active Reference
6
+ **Roo Code Repository**: `/home/prmichaelsen/Roo-Code`
7
+
8
+ ---
9
+
10
+ ## Overview
11
+
12
+ This document identifies specific code samples from Roo Code that should be ported to task-mcp, with adaptation notes for the MCP server environment.
13
+
14
+ **Important**: When referencing Roo Code source files, use the full path `/home/prmichaelsen/Roo-Code/` to locate files. This is the root directory of the Roo Code repository that contains the implementation patterns we're porting.
15
+
16
+ ### How to Use This Guide
17
+
18
+ 1. **Locate Source Files**: All file paths are relative to `/home/prmichaelsen/Roo-Code/`
19
+ 2. **Read Source Code**: Use the full path when reading files (e.g., `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts`)
20
+ 3. **Validate Assumptions**: Cross-reference this guide with actual source code before implementing
21
+ 4. **Search for Patterns**: Use `search_files` tool in `/home/prmichaelsen/Roo-Code/` to find additional examples
22
+
23
+ ---
24
+
25
+ ## 1. Message Queue System
26
+
27
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/message-queue/MessageQueueService.ts`
28
+
29
+ **What it does**: Queues user messages while agent is working, processes them when idle
30
+
31
+ **Key Features**:
32
+ - Add/remove/update messages in queue
33
+ - Dequeue messages for processing
34
+ - Event emission for state changes
35
+ - Simple in-memory queue
36
+
37
+ **Port Strategy**:
38
+ ```typescript
39
+ // task-mcp/src/utils/message-queue.ts
40
+ import { EventEmitter } from 'events'
41
+
42
+ export interface QueuedMessage {
43
+ id: string
44
+ timestamp: number
45
+ text: string
46
+ images?: string[]
47
+ }
48
+
49
+ export class MessageQueue extends EventEmitter {
50
+ private messages: QueuedMessage[] = []
51
+
52
+ addMessage(text: string, images?: string[]): QueuedMessage {
53
+ const message = {
54
+ id: crypto.randomUUID(),
55
+ timestamp: Date.now(),
56
+ text,
57
+ images
58
+ }
59
+ this.messages.push(message)
60
+ this.emit('stateChanged', this.messages)
61
+ return message
62
+ }
63
+
64
+ dequeue(): QueuedMessage | undefined {
65
+ const message = this.messages.shift()
66
+ this.emit('stateChanged', this.messages)
67
+ return message
68
+ }
69
+
70
+ isEmpty(): boolean {
71
+ return this.messages.length === 0
72
+ }
73
+
74
+ // ... other methods
75
+ }
76
+ ```
77
+
78
+ **Adaptations**:
79
+ - ✅ Keep as-is (no VSCode dependencies)
80
+ - ✅ Use in task execution loop
81
+ - ✅ Persist queue to Firestore for resumability
82
+ - ✅ Add priority handling (optional)
83
+
84
+ ---
85
+
86
+ ## 2. Tool Execution Pattern
87
+
88
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/tools/BaseTool.ts` and tool implementations
89
+
90
+ **What it does**: Base class for all tools with common execution logic
91
+
92
+ **Key Pattern**:
93
+ ```typescript
94
+ // Roo Code pattern
95
+ export abstract class BaseTool<TName extends ToolName> {
96
+ abstract readonly name: TName
97
+
98
+ async handle(
99
+ task: Task,
100
+ toolUse: ToolUse<TName>,
101
+ callbacks: ToolCallbacks
102
+ ): Promise<void> {
103
+ // 1. Validate parameters
104
+ // 2. Ask for approval if needed
105
+ // 3. Execute tool logic
106
+ // 4. Format result
107
+ // 5. Push result to task
108
+ }
109
+ }
110
+ ```
111
+
112
+ **Port Strategy for task-mcp**:
113
+ ```typescript
114
+ // task-mcp/src/tools/base-tool.ts
115
+ export interface ToolDefinition {
116
+ name: string
117
+ description: string
118
+ inputSchema: object
119
+ }
120
+
121
+ export interface ToolHandler {
122
+ (client: FirebaseClient, args: any): Promise<string>
123
+ }
124
+
125
+ // Each tool exports both definition and handler
126
+ export interface Tool {
127
+ definition: ToolDefinition
128
+ handler: ToolHandler
129
+ }
130
+ ```
131
+
132
+ **Adaptations**:
133
+ - ❌ Remove BaseTool class (not needed for MCP)
134
+ - ✅ Use simple function exports per bootstrap pattern
135
+ - ✅ Each tool file exports definition + handler
136
+ - ❌ Remove approval logic (handled by agent)
137
+ - ✅ Return JSON strings directly
138
+
139
+ ---
140
+
141
+ ## 3. Tool Examples to Port
142
+
143
+ ### Example 1: UpdateTodoListTool
144
+
145
+ **Source**: `/home/prmichaelsen/Roo-Code/src/core/tools/UpdateTodoListTool.ts`
146
+
147
+ **Roo Code Implementation**:
148
+ ```typescript
149
+ export class UpdateTodoListTool extends BaseTool<"update_todo_list"> {
150
+ readonly name = "update_todo_list" as const
151
+
152
+ async handle(task: Task, toolUse: ToolUse<"update_todo_list">, callbacks: ToolCallbacks) {
153
+ const { todos } = toolUse.params
154
+
155
+ // Parse markdown checklist
156
+ const todoItems = parseTodoList(todos)
157
+
158
+ // Update task's todo list
159
+ task.todoList = todoItems
160
+
161
+ // Save to disk
162
+ await saveTodoList(task.taskId, todoItems)
163
+
164
+ // Push result
165
+ await task.pushToolResult(toolUse, "Todo list updated")
166
+ }
167
+ }
168
+ ```
169
+
170
+ **task-mcp Port**:
171
+ ```typescript
172
+ // task-mcp/src/tools/task-update-todos.ts
173
+ export const taskUpdateTodosTool = {
174
+ name: 'task_update_todos',
175
+ description: 'Update the todo list for a task',
176
+ inputSchema: {
177
+ type: 'object',
178
+ properties: {
179
+ task_id: { type: 'string', description: 'Task ID' },
180
+ todos: { type: 'string', description: 'Markdown checklist' }
181
+ },
182
+ required: ['task_id', 'todos']
183
+ }
184
+ }
185
+
186
+ export async function handleTaskUpdateTodos(
187
+ client: FirebaseClient,
188
+ args: { task_id: string; todos: string }
189
+ ): Promise<string> {
190
+ // Parse markdown checklist
191
+ const todoItems = parseTodoList(args.todos)
192
+
193
+ // Update in Firestore
194
+ await client.updateTaskTodos(args.task_id, todoItems)
195
+
196
+ return JSON.stringify({
197
+ success: true,
198
+ todos_count: todoItems.length,
199
+ completed: todoItems.filter(t => t.completed).length
200
+ }, null, 2)
201
+ }
202
+ ```
203
+
204
+ **Key Differences**:
205
+ - No Task class dependency
206
+ - No callbacks needed
207
+ - Direct Firestore operations
208
+ - Returns JSON string
209
+ - Simpler, more focused
210
+
211
+ ### Example 2: ExecuteCommandTool (NOT PORTED)
212
+
213
+ **Source**: `/home/prmichaelsen/Roo-Code/src/core/tools/ExecuteCommandTool.ts`
214
+
215
+ **Why NOT port**:
216
+ - Requires terminal access (not available in MCP server)
217
+ - VSCode-specific terminal integration
218
+ - Not applicable to task management
219
+
220
+ **Alternative**:
221
+ - Tasks in agentbase.me will use external integrations (GitHub API, Vercel API, etc.)
222
+ - No direct command execution in web environment
223
+
224
+ ### Example 3: ReadFileTool (ADAPTED)
225
+
226
+ **Source**: `/home/prmichaelsen/Roo-Code/src/core/tools/ReadFileTool.ts`
227
+
228
+ **Roo Code**: Reads files from local file system
229
+
230
+ **task-mcp Adaptation**: Read files from virtual file system (Firestore/R2)
231
+
232
+ ```typescript
233
+ // task-mcp/src/tools/task-read-file.ts
234
+ export const taskReadFileTool = {
235
+ name: 'task_read_file',
236
+ description: 'Read a file from the task virtual file system',
237
+ inputSchema: {
238
+ type: 'object',
239
+ properties: {
240
+ task_id: { type: 'string' },
241
+ path: { type: 'string', description: 'Virtual file path' }
242
+ },
243
+ required: ['task_id', 'path']
244
+ }
245
+ }
246
+
247
+ export async function handleTaskReadFile(
248
+ client: FirebaseClient,
249
+ args: { task_id: string; path: string }
250
+ ): Promise<string> {
251
+ // Read from Firestore or R2
252
+ const content = await client.readVirtualFile(args.task_id, args.path)
253
+
254
+ return JSON.stringify({
255
+ path: args.path,
256
+ content,
257
+ size: content.length
258
+ }, null, 2)
259
+ }
260
+ ```
261
+
262
+ ---
263
+
264
+ ## 4. Task Lifecycle Management
265
+
266
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts` (lines 1924-2100)
267
+
268
+ **Full Path**: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts`
269
+
270
+ **Key Methods**:
271
+ ```typescript
272
+ private async startTask(task?: string, images?: string[]): Promise<void>
273
+ private async resumeTaskFromHistory(): Promise<void>
274
+ async pauseTask(): Promise<void>
275
+ async abortTask(): Promise<void>
276
+ ```
277
+
278
+ **Port Strategy**:
279
+ ```typescript
280
+ // task-mcp/src/tools/task-lifecycle.ts
281
+
282
+ // Tool: task_start
283
+ export async function handleTaskStart(
284
+ client: FirebaseClient,
285
+ args: { task_id: string }
286
+ ): Promise<string> {
287
+ await client.updateTaskStatus(args.task_id, 'in_progress')
288
+ await client.setTaskStartTime(args.task_id, new Date().toISOString())
289
+
290
+ return JSON.stringify({
291
+ status: 'started',
292
+ task_id: args.task_id,
293
+ started_at: new Date().toISOString()
294
+ }, null, 2)
295
+ }
296
+
297
+ // Tool: task_pause
298
+ export async function handleTaskPause(
299
+ client: FirebaseClient,
300
+ args: { task_id: string }
301
+ ): Promise<string> {
302
+ await client.updateTaskStatus(args.task_id, 'paused')
303
+
304
+ return JSON.stringify({
305
+ status: 'paused',
306
+ task_id: args.task_id
307
+ }, null, 2)
308
+ }
309
+
310
+ // Tool: task_resume
311
+ export async function handleTaskResume(
312
+ client: FirebaseClient,
313
+ args: { task_id: string }
314
+ ): Promise<string> {
315
+ await client.updateTaskStatus(args.task_id, 'in_progress')
316
+
317
+ return JSON.stringify({
318
+ status: 'resumed',
319
+ task_id: args.task_id
320
+ }, null, 2)
321
+ }
322
+ ```
323
+
324
+ **Adaptations**:
325
+ - ❌ Remove VSCode-specific code
326
+ - ✅ Keep state management logic
327
+ - ✅ Use Firestore instead of file system
328
+ - ✅ Emit events for WebSocket updates (via client)
329
+
330
+ ---
331
+
332
+ ## 5. Progress Tracking
333
+
334
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/task-persistence/taskMetadata.ts`
335
+
336
+ **What it does**: Manages task metadata and progress tracking
337
+
338
+ **Key Concepts**:
339
+ - Task metadata stored alongside messages
340
+ - Progress percentages calculated
341
+ - Milestone/task completion tracking
342
+
343
+ **Port Strategy**:
344
+ ```typescript
345
+ // task-mcp/src/utils/progress-calculator.ts
346
+
347
+ export function calculateMilestoneProgress(milestone: Milestone): number {
348
+ if (milestone.tasks_total === 0) return 0
349
+ return Math.round((milestone.tasks_completed / milestone.tasks_total) * 100)
350
+ }
351
+
352
+ export function calculateOverallProgress(milestones: Milestone[]): number {
353
+ if (milestones.length === 0) return 0
354
+
355
+ const totalProgress = milestones.reduce((sum, m) => sum + m.progress, 0)
356
+ return Math.round(totalProgress / milestones.length)
357
+ }
358
+
359
+ export function findCurrentTask(
360
+ tasks: Record<string, TaskItem[]>,
361
+ currentMilestone: string
362
+ ): TaskItem | null {
363
+ const milestoneTasks = tasks[currentMilestone] || []
364
+ return milestoneTasks.find(t =>
365
+ t.status === 'in_progress' || t.status === 'not_started'
366
+ ) || null
367
+ }
368
+ ```
369
+
370
+ **Adaptations**:
371
+ - ✅ Extract calculation logic
372
+ - ✅ Make pure functions (no side effects)
373
+ - ✅ Use in tools for progress updates
374
+
375
+ ---
376
+
377
+ ## 6. API Message History
378
+
379
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts` (lines 862-1010)
380
+
381
+ **Full Path**: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts`
382
+
383
+ **What it does**: Manages conversation history with API
384
+
385
+ **Key Methods**:
386
+ ```typescript
387
+ private async getSavedApiConversationHistory(): Promise<ApiMessage[]>
388
+ private async addToApiConversationHistory(message: Anthropic.MessageParam)
389
+ ```
390
+
391
+ **Port Strategy**:
392
+ ```typescript
393
+ // task-mcp/src/client.ts (Firebase client method)
394
+
395
+ export class FirebaseClient {
396
+ async getApiMessages(taskId: string): Promise<any[]> {
397
+ const task = await this.getTask(taskId)
398
+ return task?.execution.api_messages || []
399
+ }
400
+
401
+ async addApiMessage(taskId: string, message: any): Promise<void> {
402
+ const task = await this.getTask(taskId)
403
+ if (!task) throw new Error('Task not found')
404
+
405
+ task.execution.api_messages.push({
406
+ ...message,
407
+ ts: Date.now()
408
+ })
409
+
410
+ await this.updateTask(taskId, {
411
+ execution: task.execution,
412
+ updated_at: new Date().toISOString()
413
+ })
414
+ }
415
+ }
416
+ ```
417
+
418
+ **Adaptations**:
419
+ - ✅ Store in Firestore instead of file system
420
+ - ✅ Keep message format compatible with Anthropic API
421
+ - ✅ Add timestamp for ordering
422
+ - ❌ Remove VSCode-specific metadata
423
+
424
+ ---
425
+
426
+ ## 7. Tool Result Formatting
427
+
428
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/tools/helpers/toolResultFormatting.ts`
429
+
430
+ **What it does**: Formats tool invocations and results for display
431
+
432
+ **Key Function**:
433
+ ```typescript
434
+ export function formatToolInvocation(toolName: string, params: Record<string, any>): string {
435
+ // Creates readable format for tool calls
436
+ return `Tool: ${toolName}\nParameters: ${JSON.stringify(params, null, 2)}`
437
+ }
438
+ ```
439
+
440
+ **Port Strategy**:
441
+ ```typescript
442
+ // task-mcp/src/utils/tool-formatter.ts
443
+
444
+ export function formatToolCall(
445
+ toolName: string,
446
+ args: any
447
+ ): string {
448
+ return `[Tool Call] ${toolName}\n${JSON.stringify(args, null, 2)}`
449
+ }
450
+
451
+ export function formatToolResult(
452
+ toolName: string,
453
+ result: any,
454
+ error?: string
455
+ ): string {
456
+ if (error) {
457
+ return `[Tool Error] ${toolName}\n${error}`
458
+ }
459
+ return `[Tool Result] ${toolName}\n${result}`
460
+ }
461
+ ```
462
+
463
+ **Adaptations**:
464
+ - ✅ Keep formatting logic
465
+ - ✅ Simplify for MCP context
466
+ - ✅ Use for audit logging
467
+
468
+ ---
469
+
470
+ ## 8. Auto-Approval Logic
471
+
472
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/auto-approval/AutoApprovalHandler.ts`
473
+
474
+ **What it does**: Automatically approves certain tool calls based on patterns
475
+
476
+ **Key Concept**: Pattern-based approval rules
477
+
478
+ **Port Strategy**:
479
+ ```typescript
480
+ // task-mcp/src/utils/auto-approval.ts
481
+
482
+ export interface ApprovalRule {
483
+ toolName: string
484
+ condition?: (args: any) => boolean
485
+ autoApprove: boolean
486
+ }
487
+
488
+ export const DEFAULT_APPROVAL_RULES: ApprovalRule[] = [
489
+ // All task tools are auto-approved
490
+ { toolName: 'task_get_status', autoApprove: true },
491
+ { toolName: 'task_create_milestone', autoApprove: true },
492
+ { toolName: 'task_create_task', autoApprove: true },
493
+ { toolName: 'task_update_progress', autoApprove: true },
494
+ { toolName: 'task_complete_task', autoApprove: true },
495
+ // ... all task tools
496
+ ]
497
+
498
+ export function shouldAutoApprove(
499
+ toolName: string,
500
+ args: any,
501
+ rules: ApprovalRule[] = DEFAULT_APPROVAL_RULES
502
+ ): boolean {
503
+ const rule = rules.find(r => r.toolName === toolName)
504
+ if (!rule) return false
505
+
506
+ if (rule.condition) {
507
+ return rule.condition(args)
508
+ }
509
+
510
+ return rule.autoApprove
511
+ }
512
+ ```
513
+
514
+ **Adaptations**:
515
+ - ✅ Simplify for task-mcp (all tools auto-approved)
516
+ - ✅ Keep rule system for extensibility
517
+ - ❌ Remove complex approval UI (not needed in MCP server)
518
+
519
+ ---
520
+
521
+ ## 9. Error Handling Patterns
522
+
523
+ ### Source: Multiple tool files in `/home/prmichaelsen/Roo-Code/src/core/tools/`
524
+
525
+ **Common Pattern**:
526
+ ```typescript
527
+ try {
528
+ // Tool logic
529
+ const result = await doSomething()
530
+ return formatSuccess(result)
531
+ } catch (error) {
532
+ throw new Error(`Tool failed: ${error instanceof Error ? error.message : String(error)}`)
533
+ }
534
+ ```
535
+
536
+ **Port Strategy**:
537
+ ```typescript
538
+ // task-mcp/src/utils/error-handler.ts
539
+
540
+ export function wrapToolHandler<T extends any[], R>(
541
+ toolName: string,
542
+ handler: (...args: T) => Promise<R>
543
+ ): (...args: T) => Promise<string> {
544
+ return async (...args: T): Promise<string> => {
545
+ try {
546
+ const result = await handler(...args)
547
+ return JSON.stringify(result, null, 2)
548
+ } catch (error) {
549
+ const errorMessage = error instanceof Error ? error.message : String(error)
550
+ throw new Error(`${toolName} failed: ${errorMessage}`)
551
+ }
552
+ }
553
+ }
554
+
555
+ // Usage
556
+ export const handleTaskGetStatus = wrapToolHandler(
557
+ 'task_get_status',
558
+ async (client: FirebaseClient, args: { task_id: string }) => {
559
+ const task = await client.getTask(args.task_id)
560
+ if (!task) throw new Error('Task not found')
561
+ return { /* status data */ }
562
+ }
563
+ )
564
+ ```
565
+
566
+ **Adaptations**:
567
+ - ✅ Keep error wrapping pattern
568
+ - ✅ Add tool name to errors
569
+ - ✅ Return structured error responses
570
+
571
+ ---
572
+
573
+ ## 10. State Persistence
574
+
575
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/task-persistence/`
576
+
577
+ **What it does**: Save and restore task state from file system
578
+
579
+ **Key Functions**:
580
+ ```typescript
581
+ export async function saveApiMessages(options: SaveOptions): Promise<void>
582
+ export async function readApiMessages(options: ReadOptions): Promise<ApiMessage[]>
583
+ export async function saveTaskMessages(options: SaveOptions): Promise<void>
584
+ export async function readTaskMessages(options: ReadOptions): Promise<ClineMessage[]>
585
+ ```
586
+
587
+ **Port Strategy**:
588
+ ```typescript
589
+ // task-mcp/src/client.ts (Firebase client methods)
590
+
591
+ export class FirebaseClient {
592
+ // Save API messages
593
+ async saveApiMessages(taskId: string, messages: any[]): Promise<void> {
594
+ await this.firestore
595
+ .collection('users').doc(this.userId)
596
+ .collection('tasks').doc(taskId)
597
+ .update({
598
+ 'execution.api_messages': messages,
599
+ updated_at: new Date().toISOString()
600
+ })
601
+ }
602
+
603
+ // Read API messages
604
+ async getApiMessages(taskId: string): Promise<any[]> {
605
+ const task = await this.getTask(taskId)
606
+ return task?.execution.api_messages || []
607
+ }
608
+
609
+ // Save task messages (to subcollection)
610
+ async addTaskMessage(
611
+ taskId: string,
612
+ role: 'user' | 'assistant' | 'system',
613
+ content: string
614
+ ): Promise<string> {
615
+ const messageRef = await this.firestore
616
+ .collection('users').doc(this.userId)
617
+ .collection('tasks').doc(taskId)
618
+ .collection('messages')
619
+ .add({
620
+ role,
621
+ content,
622
+ timestamp: new Date().toISOString()
623
+ })
624
+
625
+ return messageRef.id
626
+ }
627
+ }
628
+ ```
629
+
630
+ **Adaptations**:
631
+ - ❌ Replace file system with Firestore
632
+ - ✅ Keep message format
633
+ - ✅ Use subcollections for messages
634
+ - ✅ Add timestamps for ordering
635
+
636
+ ---
637
+
638
+ ## 11. Event Emission for UI Updates
639
+
640
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts` (EventEmitter usage)
641
+
642
+ **Full Path**: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts`
643
+
644
+ **What it does**: Emits events for UI to listen to
645
+
646
+ **Roo Code Pattern**:
647
+ ```typescript
648
+ export class Task extends EventEmitter<TaskEvents> {
649
+ // Emit events
650
+ this.emit('task:started', { taskId: this.taskId })
651
+ this.emit('task:progress', { progress: 50 })
652
+ this.emit('task:completed', { taskId: this.taskId })
653
+ }
654
+ ```
655
+
656
+ **Port Strategy**:
657
+ ```typescript
658
+ // task-mcp/src/client.ts
659
+
660
+ export class FirebaseClient {
661
+ private eventEmitter = new EventEmitter()
662
+
663
+ // Emit event and save to Firestore
664
+ async emitTaskEvent(
665
+ taskId: string,
666
+ eventType: string,
667
+ data: any
668
+ ): Promise<void> {
669
+ // Save event to Firestore for WebSocket pickup
670
+ await this.firestore
671
+ .collection('users').doc(this.userId)
672
+ .collection('task_events')
673
+ .add({
674
+ task_id: taskId,
675
+ event_type: eventType,
676
+ data,
677
+ timestamp: new Date().toISOString()
678
+ })
679
+
680
+ // Also emit locally
681
+ this.eventEmitter.emit(eventType, data)
682
+ }
683
+ }
684
+ ```
685
+
686
+ **Adaptations**:
687
+ - ✅ Keep event pattern
688
+ - ✅ Save events to Firestore
689
+ - ✅ WebSocket server listens to Firestore events
690
+ - ✅ Stream to UI in real-time
691
+
692
+ ---
693
+
694
+ ## 12. Tool Registry Pattern
695
+
696
+ ### Source: `/home/prmichaelsen/Roo-Code/src/core/prompts/tools/native-tools/index.ts`
697
+
698
+ **What it does**: Registers all available tools
699
+
700
+ **Roo Code Pattern**:
701
+ ```typescript
702
+ export const nativeTools = [
703
+ readFileTool,
704
+ writeToFileTool,
705
+ executeCommandTool,
706
+ // ... all tools
707
+ ]
708
+ ```
709
+
710
+ **Port Strategy**:
711
+ ```typescript
712
+ // task-mcp/src/tools/index.ts
713
+
714
+ import { taskGetStatusTool, handleTaskGetStatus } from './task-get-status.js'
715
+ import { taskCreateMilestoneTool, handleTaskCreateMilestone } from './task-create-milestone.js'
716
+ // ... import all tools
717
+
718
+ export const allTools = [
719
+ taskGetStatusTool,
720
+ taskCreateMilestoneTool,
721
+ taskCreateTaskTool,
722
+ taskUpdateProgressTool,
723
+ taskCompleteTaskTool,
724
+ taskCompleteMilestoneTool,
725
+ taskPauseTool,
726
+ taskResumeTool,
727
+ taskInitTool,
728
+ taskGetDetailedStatusTool,
729
+ taskSyncTool,
730
+ taskGenerateReportTool,
731
+ taskValidateTool
732
+ ]
733
+
734
+ export const toolHandlers = {
735
+ 'task_get_status': handleTaskGetStatus,
736
+ 'task_create_milestone': handleTaskCreateMilestone,
737
+ // ... all handlers
738
+ }
739
+ ```
740
+
741
+ **Adaptations**:
742
+ - ✅ Keep registry pattern
743
+ - ✅ Export both definitions and handlers
744
+ - ✅ Use in MCP server setup
745
+
746
+ ---
747
+
748
+ ## Summary of Ports
749
+
750
+ ### ✅ Port These Components:
751
+ 1. **MessageQueue** - Queue user messages during execution
752
+ 2. **Progress Calculation** - Calculate milestone/task percentages
753
+ 3. **Tool Result Formatting** - Format tool calls/results
754
+ 4. **Error Handling** - Wrap errors with context
755
+ 5. **State Persistence Logic** - Save/restore patterns (adapted for Firestore)
756
+ 6. **Event Emission** - Notify UI of changes
757
+ 7. **Tool Registry** - Register all tools
758
+
759
+ ### ❌ Don't Port These:
760
+ 1. **Terminal Integration** - Not applicable to web
761
+ 2. **File System Tools** - Use virtual file system instead
762
+ 3. **VSCode-specific APIs** - No VSCode in MCP server
763
+ 4. **Diff View Provider** - UI-specific, not needed
764
+ 5. **Checkpoint System** - Git-based, not applicable
765
+
766
+ ### 🔄 Adapt These:
767
+ 1. **Tool Execution** - Simplify for MCP protocol
768
+ 2. **File Operations** - Use Firestore/R2 instead of file system
769
+ 3. **Lifecycle Management** - Remove VSCode dependencies
770
+ 4. **Auto-Approval** - Simplify (all tools auto-approved in task mode)
771
+
772
+ ---
773
+
774
+ ## Quick Reference: Key Roo Code Files
775
+
776
+ For quick access when implementing task-mcp, here are the most important source files:
777
+
778
+ ### Core Task Implementation
779
+ - **Main Task Class**: `/home/prmichaelsen/Roo-Code/src/core/task/Task.ts`
780
+ - Lines 1924-2100: Lifecycle management (start, pause, resume, abort)
781
+ - Lines 862-1010: API message history management
782
+ - Full file: ~2500 lines of task execution logic
783
+
784
+ ### Tool System
785
+ - **Base Tool**: `/home/prmichaelsen/Roo-Code/src/core/tools/BaseTool.ts`
786
+ - **Tool Registry**: `/home/prmichaelsen/Roo-Code/src/core/prompts/tools/native-tools/index.ts`
787
+ - **Tool Implementations**: `/home/prmichaelsen/Roo-Code/src/core/tools/*.ts`
788
+
789
+ ### State Management
790
+ - **Message Queue**: `/home/prmichaelsen/Roo-Code/src/core/message-queue/MessageQueueService.ts`
791
+ - **Task Persistence**: `/home/prmichaelsen/Roo-Code/src/core/task-persistence/`
792
+ - **Task Metadata**: `/home/prmichaelsen/Roo-Code/src/core/task-persistence/taskMetadata.ts`
793
+
794
+ ### Utilities
795
+ - **Tool Formatting**: `/home/prmichaelsen/Roo-Code/src/core/tools/helpers/toolResultFormatting.ts`
796
+ - **Auto-Approval**: `/home/prmichaelsen/Roo-Code/src/core/auto-approval/AutoApprovalHandler.ts`
797
+
798
+ ### Search Tips
799
+
800
+ When you need to find specific patterns in Roo Code:
801
+
802
+ ```bash
803
+ # Search for tool implementations
804
+ search_files path="/home/prmichaelsen/Roo-Code/src/core/tools" regex="class.*Tool.*extends.*BaseTool"
805
+
806
+ # Search for event emissions
807
+ search_files path="/home/prmichaelsen/Roo-Code/src/core/task" regex="this\.emit\("
808
+
809
+ # Search for Firestore operations (if any)
810
+ search_files path="/home/prmichaelsen/Roo-Code" regex="firestore|Firestore"
811
+
812
+ # Search for API message handling
813
+ search_files path="/home/prmichaelsen/Roo-Code/src/core/task" regex="ApiMessage|api.*message"
814
+ ```
815
+
816
+ ## Next Steps
817
+
818
+ 1. Create detailed extraction documents for each component
819
+ 2. Create code samples for each tool
820
+ 3. Document Firebase client methods needed
821
+ 4. Create migration guide for each pattern
822
+
823
+ ---
824
+
825
+ **Status**: Active Reference
826
+ **Roo Code Path**: `/home/prmichaelsen/Roo-Code`
827
+ **Last Updated**: 2026-02-16