cast-code 1.0.9 → 1.0.11
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.
- package/dist/modules/core/services/deep-agent.service.js +1 -1
- package/dist/modules/core/services/deep-agent.service.js.map +1 -1
- package/dist/modules/kanban/kanban.module.js +36 -0
- package/dist/modules/kanban/kanban.module.js.map +1 -0
- package/dist/modules/kanban/services/kanban-server.service.js +322 -0
- package/dist/modules/kanban/services/kanban-server.service.js.map +1 -0
- package/dist/modules/kanban/views/kanban-ui.js +858 -0
- package/dist/modules/kanban/views/kanban-ui.js.map +1 -0
- package/dist/modules/mentions/services/mentions.service.js +3 -3
- package/dist/modules/mentions/services/mentions.service.js.map +1 -1
- package/dist/modules/permissions/services/prompt.service.js +17 -70
- package/dist/modules/permissions/services/prompt.service.js.map +1 -1
- package/dist/modules/repl/repl.module.js +3 -1
- package/dist/modules/repl/repl.module.js.map +1 -1
- package/dist/modules/repl/services/commands/project-commands.service.js +7 -9
- package/dist/modules/repl/services/commands/project-commands.service.js.map +1 -1
- package/dist/modules/repl/services/repl.service.js +112 -38
- package/dist/modules/repl/services/repl.service.js.map +1 -1
- package/dist/modules/repl/services/smart-input.js +2 -2
- package/dist/modules/repl/services/smart-input.js.map +1 -1
- package/dist/modules/tasks/services/plan-executor.service.js +2 -2
- package/dist/modules/tasks/services/plan-executor.service.js.map +1 -1
- package/dist/modules/tasks/services/plan-mode.service.js +11 -10
- package/dist/modules/tasks/services/plan-mode.service.js.map +1 -1
- package/dist/modules/tasks/services/task-management.service.js +54 -21
- package/dist/modules/tasks/services/task-management.service.js.map +1 -1
- package/dist/modules/tasks/services/task-tools.service.js +2 -2
- package/dist/modules/tasks/services/task-tools.service.js.map +1 -1
- package/dist/modules/tasks/types/task.types.js.map +1 -1
- package/package.json +1 -1
|
@@ -118,9 +118,9 @@ let PlanExecutorService = class PlanExecutorService {
|
|
|
118
118
|
console.log(` ${_theme.Colors.dim}${task.description}${_theme.Colors.reset}`);
|
|
119
119
|
console.log('');
|
|
120
120
|
this.taskService.updateTask(task.id, {
|
|
121
|
-
status: _tasktypes.TaskStatus.IN_PROGRESS
|
|
121
|
+
status: _tasktypes.TaskStatus.IN_PROGRESS,
|
|
122
|
+
assignedAgent: 'main'
|
|
122
123
|
});
|
|
123
|
-
// Executar task via DeepAgent
|
|
124
124
|
const deepAgent = await this.getDeepAgent();
|
|
125
125
|
const result = await deepAgent.executeTask(task);
|
|
126
126
|
if (!result.success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/tasks/services/plan-executor.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { ModuleRef } from '@nestjs/core';\nimport { TaskManagementService } from './task-management.service';\nimport { PlanPersistenceService } from './plan-persistence.service';\nimport { PromptService } from '../../permissions/services/prompt.service';\nimport { Colors } from '../../repl/utils/theme';\nimport { Task, TaskStatus } from '../types/task.types';\n\n@Injectable()\nexport class PlanExecutorService {\n private executing = false;\n private aborted = false;\n private currentPlanFile: string | null = null;\n private deepAgent: any = null;\n\n constructor(\n private taskService: TaskManagementService,\n private planPersistence: PlanPersistenceService,\n private promptService: PromptService,\n private moduleRef: ModuleRef,\n ) {}\n\n private async getDeepAgent() {\n if (!this.deepAgent) {\n const { DeepAgentService } = await import('../../core/services/deep-agent.service');\n this.deepAgent = this.moduleRef.get(DeepAgentService, { strict: false });\n }\n return this.deepAgent;\n }\n\n async executePlan(planId: string, autoApprove: boolean): Promise<void> {\n const plan = this.taskService.getPlans().get(planId);\n if (!plan) {\n throw new Error('Plan not found');\n }\n\n // Salvar plano\n this.currentPlanFile = await this.planPersistence.savePlan(plan, autoApprove);\n this.promptService.info(`📝 Plano salvo: ${this.currentPlanFile}`);\n console.log('');\n\n // Setup Ctrl+C handler\n const ctrlCHandler = () => {\n if (this.executing) {\n this.aborted = true;\n console.log(`\\n${Colors.warning}⚠ Interrupção solicitada. Finalizando tarefa atual...${Colors.reset}\\n`);\n }\n };\n process.on('SIGINT', ctrlCHandler);\n\n this.executing = true;\n plan.status = 'executing';\n\n const startTime = Date.now();\n const completedTasks: string[] = [];\n const errors: string[] = [];\n\n try {\n for (let i = 0; i < plan.tasks.length; i++) {\n if (this.aborted) {\n this.promptService.warning('Execução cancelada pelo usuário');\n break;\n }\n\n const task = plan.tasks[i];\n\n // Verificar dependências\n const depsSatisfied = task.dependencies.every(depId => {\n const dep = this.taskService.getTask(depId);\n return dep && dep.status === TaskStatus.COMPLETED;\n });\n\n if (!depsSatisfied) {\n errors.push(`Task ${task.id}: dependências não satisfeitas`);\n continue;\n }\n\n // Executar tarefa\n console.log(`${Colors.primary}►${Colors.reset} ${Colors.bold}Executando: ${task.subject}${Colors.reset}`);\n console.log(` ${Colors.dim}${task.description}${Colors.reset}`);\n console.log('');\n\n this.taskService.updateTask(task.id, { status: TaskStatus.IN_PROGRESS });\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/tasks/services/plan-executor.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { ModuleRef } from '@nestjs/core';\nimport { TaskManagementService } from './task-management.service';\nimport { PlanPersistenceService } from './plan-persistence.service';\nimport { PromptService } from '../../permissions/services/prompt.service';\nimport { Colors } from '../../repl/utils/theme';\nimport { Task, TaskStatus } from '../types/task.types';\n\n@Injectable()\nexport class PlanExecutorService {\n private executing = false;\n private aborted = false;\n private currentPlanFile: string | null = null;\n private deepAgent: any = null;\n\n constructor(\n private taskService: TaskManagementService,\n private planPersistence: PlanPersistenceService,\n private promptService: PromptService,\n private moduleRef: ModuleRef,\n ) {}\n\n private async getDeepAgent() {\n if (!this.deepAgent) {\n const { DeepAgentService } = await import('../../core/services/deep-agent.service');\n this.deepAgent = this.moduleRef.get(DeepAgentService, { strict: false });\n }\n return this.deepAgent;\n }\n\n async executePlan(planId: string, autoApprove: boolean): Promise<void> {\n const plan = this.taskService.getPlans().get(planId);\n if (!plan) {\n throw new Error('Plan not found');\n }\n\n // Salvar plano\n this.currentPlanFile = await this.planPersistence.savePlan(plan, autoApprove);\n this.promptService.info(`📝 Plano salvo: ${this.currentPlanFile}`);\n console.log('');\n\n // Setup Ctrl+C handler\n const ctrlCHandler = () => {\n if (this.executing) {\n this.aborted = true;\n console.log(`\\n${Colors.warning}⚠ Interrupção solicitada. Finalizando tarefa atual...${Colors.reset}\\n`);\n }\n };\n process.on('SIGINT', ctrlCHandler);\n\n this.executing = true;\n plan.status = 'executing';\n\n const startTime = Date.now();\n const completedTasks: string[] = [];\n const errors: string[] = [];\n\n try {\n for (let i = 0; i < plan.tasks.length; i++) {\n if (this.aborted) {\n this.promptService.warning('Execução cancelada pelo usuário');\n break;\n }\n\n const task = plan.tasks[i];\n\n // Verificar dependências\n const depsSatisfied = task.dependencies.every(depId => {\n const dep = this.taskService.getTask(depId);\n return dep && dep.status === TaskStatus.COMPLETED;\n });\n\n if (!depsSatisfied) {\n errors.push(`Task ${task.id}: dependências não satisfeitas`);\n continue;\n }\n\n // Executar tarefa\n console.log(`${Colors.primary}►${Colors.reset} ${Colors.bold}Executando: ${task.subject}${Colors.reset}`);\n console.log(` ${Colors.dim}${task.description}${Colors.reset}`);\n console.log('');\n\n this.taskService.updateTask(task.id, { status: TaskStatus.IN_PROGRESS, assignedAgent: 'main' });\n\n const deepAgent = await this.getDeepAgent();\n const result = await deepAgent.executeTask(task);\n\n if (!result.success) {\n errors.push(`Task ${task.id}: ${result.error || 'Falha na execução'}`);\n this.taskService.updateTask(task.id, { status: TaskStatus.FAILED });\n } else {\n this.taskService.updateTask(task.id, { status: TaskStatus.COMPLETED });\n completedTasks.push(task.id);\n console.log(` ${Colors.success}✓ Concluído${Colors.reset}`);\n }\n\n // Atualizar progresso no arquivo\n await this.planPersistence.updatePlanProgress(this.currentPlanFile!, {\n currentTask: i + 1,\n completedTasks: completedTasks.length,\n status: 'executing',\n });\n\n console.log('');\n }\n\n // Marcar plano como completo\n plan.status = 'completed';\n const duration = Date.now() - startTime;\n\n await this.planPersistence.markPlanCompleted(this.currentPlanFile!, {\n success: errors.length === 0,\n duration,\n errors: errors.length > 0 ? errors : undefined,\n });\n\n console.log('');\n console.log('='.repeat(60));\n this.promptService.success(`✓ Plano concluído em ${(duration / 1000).toFixed(1)}s`);\n console.log(` ${Colors.dim}${completedTasks.length}/${plan.tasks.length} tarefas completadas${Colors.reset}`);\n if (errors.length > 0) {\n console.log(` ${Colors.warning}${errors.length} erros${Colors.reset}`);\n }\n console.log('='.repeat(60));\n console.log('');\n\n } finally {\n this.executing = false;\n this.aborted = false;\n this.currentPlanFile = null;\n this.taskService.clearExecutionContext();\n process.removeListener('SIGINT', ctrlCHandler);\n }\n }\n\n isExecuting(): boolean {\n return this.executing;\n }\n\n abort(): void {\n this.aborted = true;\n }\n}\n"],"names":["PlanExecutorService","getDeepAgent","deepAgent","DeepAgentService","moduleRef","get","strict","executePlan","planId","autoApprove","plan","taskService","getPlans","Error","currentPlanFile","planPersistence","savePlan","promptService","info","console","log","ctrlCHandler","executing","aborted","Colors","warning","reset","process","on","status","startTime","Date","now","completedTasks","errors","i","tasks","length","task","depsSatisfied","dependencies","every","depId","dep","getTask","TaskStatus","COMPLETED","push","id","primary","bold","subject","dim","description","updateTask","IN_PROGRESS","assignedAgent","result","executeTask","success","error","FAILED","updatePlanProgress","currentTask","duration","markPlanCompleted","undefined","repeat","toFixed","clearExecutionContext","removeListener","isExecuting","abort"],"mappings":";;;;+BASaA;;;eAAAA;;;wBATc;sBACD;uCACY;wCACC;+BACT;uBACP;2BACU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG1B,IAAA,AAAMA,sBAAN,MAAMA;IAaX,MAAcC,eAAe;QAC3B,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE;YACnB,MAAM,EAAEC,gBAAgB,EAAE,GAAG,MAAM,mEAAA,QAAO;YAC1C,IAAI,CAACD,SAAS,GAAG,IAAI,CAACE,SAAS,CAACC,GAAG,CAACF,kBAAkB;g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AS,GAAG;YACjB,IAAI,CAACC,OAAO,GAAG;YACf,IAAI,CAACT,eAAe,GAAG;YACvB,IAAI,CAACH,WAAW,CAAC0D,qBAAqB;YACtC1C,QAAQ2C,cAAc,CAAC,UAAUjD;QACnC;IACF;IAEAkD,cAAuB;QACrB,OAAO,IAAI,CAACjD,SAAS;IACvB;IAEAkD,QAAc;QACZ,IAAI,CAACjD,OAAO,GAAG;IACjB;IA9HA,YACE,AAAQZ,WAAkC,EAC1C,AAAQI,eAAuC,EAC/C,AAAQE,aAA4B,EACpC,AAAQb,SAAoB,CAC5B;aAJQO,cAAAA;aACAI,kBAAAA;aACAE,gBAAAA;aACAb,YAAAA;aATFkB,YAAY;aACZC,UAAU;aACVT,kBAAiC;aACjCZ,YAAiB;IAOtB;AA0HL"}
|
|
@@ -12,6 +12,7 @@ const _common = require("@nestjs/common");
|
|
|
12
12
|
const _taskmanagementservice = require("./task-management.service");
|
|
13
13
|
const _planexecutorservice = require("./plan-executor.service");
|
|
14
14
|
const _promptservice = require("../../permissions/services/prompt.service");
|
|
15
|
+
const _theme = require("../../repl/utils/theme");
|
|
15
16
|
function _ts_decorate(decorators, target, key, desc) {
|
|
16
17
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
18
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -39,14 +40,14 @@ let PlanModeService = class PlanModeService {
|
|
|
39
40
|
this.planContext.set('title', title);
|
|
40
41
|
this.planContext.set('description', description);
|
|
41
42
|
console.log('');
|
|
42
|
-
console.log(
|
|
43
|
-
this.promptService.info(
|
|
44
|
-
console.log(
|
|
43
|
+
console.log(`${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
44
|
+
this.promptService.info(`${_theme.Colors.bold}📋 Entering PLAN MODE${_theme.Colors.reset}`);
|
|
45
|
+
console.log(`${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
45
46
|
console.log('');
|
|
46
|
-
console.log(
|
|
47
|
-
console.log(description);
|
|
47
|
+
console.log(`${_theme.Colors.bold}Planning:${_theme.Colors.reset} ${title}`);
|
|
48
|
+
console.log(`${_theme.Colors.dim}${description}${_theme.Colors.reset}`);
|
|
48
49
|
console.log('');
|
|
49
|
-
this.promptService.info('I will
|
|
50
|
+
this.promptService.info('I will explore the codebase and create an execution plan.');
|
|
50
51
|
console.log('');
|
|
51
52
|
}
|
|
52
53
|
async exitPlanMode(tasks) {
|
|
@@ -55,11 +56,11 @@ let PlanModeService = class PlanModeService {
|
|
|
55
56
|
}
|
|
56
57
|
try {
|
|
57
58
|
console.log('');
|
|
58
|
-
console.log(
|
|
59
|
-
this.promptService.info(
|
|
60
|
-
console.log(
|
|
59
|
+
console.log(`${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
60
|
+
this.promptService.info(`${_theme.Colors.bold}📋 Exiting PLAN MODE - Presenting Plan${_theme.Colors.reset}`);
|
|
61
|
+
console.log(`${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
61
62
|
console.log('');
|
|
62
|
-
const planTitle = this.planContext.get('title') || '
|
|
63
|
+
const planTitle = this.planContext.get('title') || 'Execution Plan';
|
|
63
64
|
const planDescription = this.planContext.get('description') || '';
|
|
64
65
|
const plan = this.taskService.createPlan(planTitle, planDescription, tasks);
|
|
65
66
|
this.currentPlan = plan;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/tasks/services/plan-mode.service.ts"],"sourcesContent":["import { Injectable, forwardRef, Inject } from '@nestjs/common';\nimport { TaskManagementService } from './task-management.service';\nimport { PlanExecutorService } from './plan-executor.service';\nimport { PromptService } from '../../permissions/services/prompt.service';\nimport { CreateTaskOptions, TaskPlan } from '../types/task.types';\n\n@Injectable()\nexport class PlanModeService {\n private inPlanMode = false;\n private currentPlan: TaskPlan | null = null;\n private planContext: Map<string, any> = new Map();\n\n constructor(\n private taskService: TaskManagementService,\n @Inject(forwardRef(() => PlanExecutorService))\n private planExecutor: PlanExecutorService,\n private promptService: PromptService,\n ) {}\n\n async enterPlanMode(title: string, description: string): Promise<void> {\n if (this.inPlanMode) {\n throw new Error('Already in plan mode');\n }\n\n if (this.taskService.getExecutionContext()) {\n throw new Error('Cannot enter plan mode while executing an approved plan');\n }\n\n this.inPlanMode = true;\n this.planContext.clear();\n this.planContext.set('title', title);\n this.planContext.set('description', description);\n\n console.log('');\n console.log(
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/tasks/services/plan-mode.service.ts"],"sourcesContent":["import { Injectable, forwardRef, Inject } from '@nestjs/common';\nimport { TaskManagementService } from './task-management.service';\nimport { PlanExecutorService } from './plan-executor.service';\nimport { PromptService } from '../../permissions/services/prompt.service';\nimport { CreateTaskOptions, TaskPlan } from '../types/task.types';\nimport { Colors } from '../../repl/utils/theme';\n\n@Injectable()\nexport class PlanModeService {\n private inPlanMode = false;\n private currentPlan: TaskPlan | null = null;\n private planContext: Map<string, any> = new Map();\n\n constructor(\n private taskService: TaskManagementService,\n @Inject(forwardRef(() => PlanExecutorService))\n private planExecutor: PlanExecutorService,\n private promptService: PromptService,\n ) { }\n\n async enterPlanMode(title: string, description: string): Promise<void> {\n if (this.inPlanMode) {\n throw new Error('Already in plan mode');\n }\n\n if (this.taskService.getExecutionContext()) {\n throw new Error('Cannot enter plan mode while executing an approved plan');\n }\n\n this.inPlanMode = true;\n this.planContext.clear();\n this.planContext.set('title', title);\n this.planContext.set('description', description);\n\n console.log('');\n console.log(`${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n this.promptService.info(`${Colors.bold}📋 Entering PLAN MODE${Colors.reset}`);\n console.log(`${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n console.log('');\n console.log(`${Colors.bold}Planning:${Colors.reset} ${title}`);\n console.log(`${Colors.dim}${description}${Colors.reset}`);\n console.log('');\n this.promptService.info('I will explore the codebase and create an execution plan.');\n console.log('');\n }\n\n async exitPlanMode(tasks: CreateTaskOptions[]): Promise<{ approved: boolean; autoApprove: boolean; modification?: string }> {\n if (!this.inPlanMode) {\n throw new Error('Not in plan mode');\n }\n\n try {\n console.log('');\n console.log(`${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n this.promptService.info(`${Colors.bold}📋 Exiting PLAN MODE - Presenting Plan${Colors.reset}`);\n console.log(`${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n console.log('');\n\n const planTitle = this.planContext.get('title') || 'Execution Plan';\n const planDescription = this.planContext.get('description') || '';\n\n const plan = this.taskService.createPlan(planTitle, planDescription, tasks);\n this.currentPlan = plan;\n\n const result = await this.taskService.approvePlan(plan.id);\n\n if (result.approved) {\n // Configurar contexto de execução\n this.taskService.setExecutionContext({\n planId: plan.id,\n autoApprove: result.autoApprove,\n currentTaskIndex: 0,\n startedAt: Date.now(),\n });\n\n // Executar plano usando PlanExecutorService\n await this.planExecutor.executePlan(plan.id, result.autoApprove);\n }\n\n return {\n approved: result.approved,\n autoApprove: result.autoApprove,\n modification: result.modificationRequested,\n };\n } finally {\n this.inPlanMode = false;\n }\n }\n\n isInPlanMode(): boolean {\n return this.inPlanMode;\n }\n\n setPlanContext(key: string, value: any): void {\n this.planContext.set(key, value);\n }\n\n getPlanContext(key: string): any {\n return this.planContext.get(key);\n }\n\n cancelPlanMode(): void {\n if (!this.inPlanMode) return;\n\n this.promptService.warn('Plan mode cancelled');\n this.inPlanMode = false;\n this.currentPlan = null;\n this.planContext.clear();\n }\n\n getCurrentPlan(): TaskPlan | null {\n return this.currentPlan;\n }\n}\n"],"names":["PlanModeService","enterPlanMode","title","description","inPlanMode","Error","taskService","getExecutionContext","planContext","clear","set","console","log","Colors","dim","reset","promptService","info","bold","exitPlanMode","tasks","planTitle","get","planDescription","plan","createPlan","currentPlan","result","approvePlan","id","approved","setExecutionContext","planId","autoApprove","currentTaskIndex","startedAt","Date","now","planExecutor","executePlan","modification","modificationRequested","isInPlanMode","setPlanContext","key","value","getPlanContext","cancelPlanMode","warn","getCurrentPlan","Map","PlanExecutorService"],"mappings":";;;;+BAQaA;;;eAAAA;;;wBARkC;uCACT;qCACF;+BACN;uBAEP;;;;;;;;;;;;;;;AAGhB,IAAA,AAAMA,kBAAN,MAAMA;IAYX,MAAMC,cAAcC,KAAa,EAAEC,WAAmB,EAAiB;QACrE,IAAI,IAAI,CAACC,UAAU,EAAE;YACnB,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAI,IAAI,CAACC,WAAW,CAACC,mBAAmB,IAAI;YAC1C,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,CAACD,UAAU,GAAG;QAClB,IAAI,CAACI,WAAW,CAACC,KAAK;QACtB,IAAI,CAACD,WAAW,CAACE,GAAG,CAAC,SAASR;QAC9B,IAAI,CAACM,WAAW,CAACE,GAAG,CAAC,eAAeP;QAEpCQ,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC,GAAGC,aAAM,CAACC,GAAG,CAAC,4DAA4D,EAAED,aAAM,CAACE,KAAK,EAAE;QACtG,IAAI,CAACC,aAAa,CAACC,IAAI,CAAC,GAAGJ,aAAM,CAACK,IAAI,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CAAmB"}
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "TaskManagementService", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _common = require("@nestjs/common");
|
|
12
|
+
const _events = require("events");
|
|
12
13
|
const _tasktypes = require("../types/task.types");
|
|
13
14
|
const _promptservice = require("../../permissions/services/prompt.service");
|
|
14
15
|
const _theme = require("../../repl/utils/theme");
|
|
@@ -43,6 +44,7 @@ let TaskManagementService = class TaskManagementService {
|
|
|
43
44
|
dep.blocks.push(id);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
this.events.emit('task:created', task);
|
|
46
48
|
return task;
|
|
47
49
|
}
|
|
48
50
|
updateTask(taskId, options) {
|
|
@@ -58,6 +60,7 @@ let TaskManagementService = class TaskManagementService {
|
|
|
58
60
|
if (options.removeDependencies) {
|
|
59
61
|
task.dependencies = task.dependencies.filter((id)=>!options.removeDependencies?.includes(id));
|
|
60
62
|
}
|
|
63
|
+
if (options.assignedAgent !== undefined) task.assignedAgent = options.assignedAgent;
|
|
61
64
|
if (options.metadata) {
|
|
62
65
|
task.metadata = {
|
|
63
66
|
...task.metadata,
|
|
@@ -65,6 +68,11 @@ let TaskManagementService = class TaskManagementService {
|
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
task.updatedAt = Date.now();
|
|
71
|
+
this.events.emit('task:updated', task);
|
|
72
|
+
// Debug log for Kanban updates
|
|
73
|
+
if (options.status) {
|
|
74
|
+
process.stdout.write(`\r Task ${taskId} status updated to: ${options.status}\n`);
|
|
75
|
+
}
|
|
68
76
|
return task;
|
|
69
77
|
}
|
|
70
78
|
getTask(taskId) {
|
|
@@ -94,6 +102,7 @@ let TaskManagementService = class TaskManagementService {
|
|
|
94
102
|
createdAt: Date.now()
|
|
95
103
|
};
|
|
96
104
|
this.plans.set(id, plan);
|
|
105
|
+
this.events.emit('plan:created', plan);
|
|
97
106
|
return plan;
|
|
98
107
|
}
|
|
99
108
|
async approvePlan(planId) {
|
|
@@ -106,63 +115,63 @@ let TaskManagementService = class TaskManagementService {
|
|
|
106
115
|
};
|
|
107
116
|
}
|
|
108
117
|
// Renderizar plano
|
|
109
|
-
console.log(
|
|
110
|
-
this.promptService.info(
|
|
111
|
-
console.log(
|
|
118
|
+
console.log(`\n${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
119
|
+
this.promptService.info(`${_theme.Colors.bold}📋 PLAN: ${plan.title}${_theme.Colors.reset}`);
|
|
120
|
+
console.log(`${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
112
121
|
console.log('');
|
|
113
122
|
console.log(plan.description);
|
|
114
123
|
console.log('');
|
|
115
|
-
console.log(`${_theme.Colors.bold}
|
|
124
|
+
console.log(`${_theme.Colors.bold}Tasks (${plan.tasks.length}):${_theme.Colors.reset}`);
|
|
116
125
|
console.log('');
|
|
117
126
|
plan.tasks.forEach((task, index)=>{
|
|
118
|
-
const depInfo = task.dependencies.length > 0 ? ` ${_theme.Colors.muted}(
|
|
127
|
+
const depInfo = task.dependencies.length > 0 ? ` ${_theme.Colors.muted}(depends on: ${task.dependencies.join(', ')})${_theme.Colors.reset}` : '';
|
|
119
128
|
console.log(` ${_theme.Colors.primary}${index + 1}.${_theme.Colors.reset} ${_theme.Colors.bold}${task.subject}${_theme.Colors.reset}${depInfo}`);
|
|
120
129
|
console.log(` ${_theme.Colors.dim}${task.description}${_theme.Colors.reset}`);
|
|
121
130
|
console.log('');
|
|
122
131
|
});
|
|
123
|
-
console.log(
|
|
132
|
+
console.log(`${_theme.Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${_theme.Colors.reset}`);
|
|
124
133
|
console.log('');
|
|
125
134
|
// Opções aprimoradas
|
|
126
135
|
const choices = [
|
|
127
136
|
{
|
|
128
137
|
key: 'approve',
|
|
129
|
-
label: '
|
|
130
|
-
description: '
|
|
138
|
+
label: 'Approve',
|
|
139
|
+
description: 'Execute the plan'
|
|
131
140
|
},
|
|
132
141
|
{
|
|
133
142
|
key: 'auto-approve',
|
|
134
|
-
label: '
|
|
135
|
-
description: '
|
|
143
|
+
label: 'Auto-approve',
|
|
144
|
+
description: 'Execute without asking for approval on each step'
|
|
136
145
|
},
|
|
137
146
|
{
|
|
138
147
|
key: 'modify',
|
|
139
|
-
label: '
|
|
140
|
-
description: '
|
|
148
|
+
label: 'Modify',
|
|
149
|
+
description: 'Modify the plan before executing'
|
|
141
150
|
},
|
|
142
151
|
{
|
|
143
152
|
key: 'cancel',
|
|
144
|
-
label: '
|
|
145
|
-
description: '
|
|
153
|
+
label: 'Cancel',
|
|
154
|
+
description: 'Cancel and do not execute'
|
|
146
155
|
}
|
|
147
156
|
];
|
|
148
|
-
const choice = await this.promptService.choice('
|
|
157
|
+
const choice = await this.promptService.choice('What do you want to do?', choices);
|
|
149
158
|
switch(choice){
|
|
150
159
|
case 'approve':
|
|
151
160
|
plan.status = 'approved';
|
|
152
|
-
this.promptService.success('✓
|
|
161
|
+
this.promptService.success('✓ Plan approved! Starting execution...');
|
|
153
162
|
return {
|
|
154
163
|
approved: true,
|
|
155
164
|
autoApprove: false
|
|
156
165
|
};
|
|
157
166
|
case 'auto-approve':
|
|
158
167
|
plan.status = 'approved';
|
|
159
|
-
this.promptService.success('✓
|
|
168
|
+
this.promptService.success('✓ Plan approved with auto-approve! Automatic execution enabled.');
|
|
160
169
|
return {
|
|
161
170
|
approved: true,
|
|
162
171
|
autoApprove: true
|
|
163
172
|
};
|
|
164
173
|
case 'modify':
|
|
165
|
-
const modification = await this.promptService.question(`${_theme.Colors.accent}
|
|
174
|
+
const modification = await this.promptService.question(`${_theme.Colors.accent}How do you want to modify the plan?${_theme.Colors.reset}`);
|
|
166
175
|
plan.status = 'draft';
|
|
167
176
|
return {
|
|
168
177
|
approved: false,
|
|
@@ -171,7 +180,7 @@ let TaskManagementService = class TaskManagementService {
|
|
|
171
180
|
};
|
|
172
181
|
case 'cancel':
|
|
173
182
|
plan.status = 'cancelled';
|
|
174
|
-
this.promptService.info('
|
|
183
|
+
this.promptService.info('Plan cancelled');
|
|
175
184
|
return {
|
|
176
185
|
approved: false,
|
|
177
186
|
autoApprove: false
|
|
@@ -198,6 +207,7 @@ let TaskManagementService = class TaskManagementService {
|
|
|
198
207
|
const firstWord = subject.split(' ')[0].toLowerCase();
|
|
199
208
|
const rest = subject.slice(firstWord.length);
|
|
200
209
|
const gerundMap = {
|
|
210
|
+
// English
|
|
201
211
|
create: 'Creating',
|
|
202
212
|
add: 'Adding',
|
|
203
213
|
implement: 'Implementing',
|
|
@@ -208,9 +218,31 @@ let TaskManagementService = class TaskManagementService {
|
|
|
208
218
|
refactor: 'Refactoring',
|
|
209
219
|
test: 'Testing',
|
|
210
220
|
write: 'Writing',
|
|
211
|
-
read: 'Reading'
|
|
221
|
+
read: 'Reading',
|
|
222
|
+
// Portuguese
|
|
223
|
+
criar: 'Criando',
|
|
224
|
+
adicionar: 'Adicionando',
|
|
225
|
+
implementar: 'Implementando',
|
|
226
|
+
corrigir: 'Corrigindo',
|
|
227
|
+
atualizar: 'Atualizando',
|
|
228
|
+
remover: 'Removendo',
|
|
229
|
+
deletar: 'Deletando',
|
|
230
|
+
refatorar: 'Refatorando',
|
|
231
|
+
testar: 'Testando',
|
|
232
|
+
escrever: 'Escrevendo',
|
|
233
|
+
ler: 'Lendo',
|
|
234
|
+
analisar: 'Analisando',
|
|
235
|
+
fazer: 'Fazendo',
|
|
236
|
+
crie: 'Criando',
|
|
237
|
+
adicione: 'Adicionando',
|
|
238
|
+
implemente: 'Implementando',
|
|
239
|
+
corrija: 'Corrigindo',
|
|
240
|
+
atualize: 'Atualizando',
|
|
241
|
+
remova: 'Removendo',
|
|
242
|
+
analise: 'Analisando',
|
|
243
|
+
faça: 'Fazendo'
|
|
212
244
|
};
|
|
213
|
-
const gerund = gerundMap[firstWord] || subject + '
|
|
245
|
+
const gerund = gerundMap[firstWord] || (subject.length > 20 ? subject.slice(0, 20) + '...' : subject);
|
|
214
246
|
return gerund + rest;
|
|
215
247
|
}
|
|
216
248
|
clearCompletedTasks() {
|
|
@@ -237,6 +269,7 @@ let TaskManagementService = class TaskManagementService {
|
|
|
237
269
|
}
|
|
238
270
|
constructor(promptService){
|
|
239
271
|
this.promptService = promptService;
|
|
272
|
+
this.events = new _events.EventEmitter();
|
|
240
273
|
this.tasks = new Map();
|
|
241
274
|
this.plans = new Map();
|
|
242
275
|
this.taskCounter = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/tasks/services/task-management.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport {\n Task,\n TaskStatus,\n TaskPlan,\n CreateTaskOptions,\n UpdateTaskOptions,\n PlanApprovalOptions,\n PlanExecutionContext,\n} from '../types/task.types';\nimport { PromptService } from '../../permissions/services/prompt.service';\nimport { Colors } from '../../repl/utils/theme';\n\n\n@Injectable()\nexport class TaskManagementService {\n private tasks: Map<string, Task> = new Map();\n private plans: Map<string, TaskPlan> = new Map();\n private taskCounter = 0;\n private planCounter = 0;\n private executionContext: PlanExecutionContext | null = null;\n\n constructor(private promptService: PromptService) {}\n\n createTask(options: CreateTaskOptions): Task {\n const id = `task-${++this.taskCounter}`;\n\n const task: Task = {\n id,\n subject: options.subject,\n description: options.description,\n activeForm: options.activeForm || this.generateActiveForm(options.subject),\n status: TaskStatus.PENDING,\n createdAt: Date.now(),\n updatedAt: Date.now(),\n dependencies: options.dependencies || [],\n blocks: [],\n metadata: options.metadata || {},\n };\n\n this.tasks.set(id, task);\n\n for (const depId of task.dependencies) {\n const dep = this.tasks.get(depId);\n if (dep) {\n dep.blocks.push(id);\n }\n }\n\n return task;\n }\n\n updateTask(taskId: string, options: UpdateTaskOptions): Task | null {\n const task = this.tasks.get(taskId);\n if (!task) return null;\n\n if (options.status) task.status = options.status;\n if (options.subject) task.subject = options.subject;\n if (options.description) task.description = options.description;\n if (options.activeForm) task.activeForm = options.activeForm;\n\n if (options.addDependencies) {\n task.dependencies.push(...options.addDependencies);\n }\n\n if (options.removeDependencies) {\n task.dependencies = task.dependencies.filter(\n (id) => !options.removeDependencies?.includes(id),\n );\n }\n\n if (options.metadata) {\n task.metadata = { ...task.metadata, ...options.metadata };\n }\n\n task.updatedAt = Date.now();\n return task;\n }\n\n getTask(taskId: string): Task | null {\n return this.tasks.get(taskId) || null;\n }\n\n listTasks(): Task[] {\n return Array.from(this.tasks.values());\n }\n\n listPendingTasks(): Task[] {\n return this.listTasks().filter((task) => {\n if (task.status !== TaskStatus.PENDING) return false;\n\n return task.dependencies.every((depId) => {\n const dep = this.tasks.get(depId);\n return dep && dep.status === TaskStatus.COMPLETED;\n });\n });\n }\n\n createPlan(title: string, description: string, tasks: CreateTaskOptions[]): TaskPlan {\n const id = `plan-${++this.planCounter}`;\n\n const createdTasks = tasks.map((taskOpt) => this.createTask(taskOpt));\n\n const plan: TaskPlan = {\n id,\n title,\n description,\n tasks: createdTasks,\n status: 'draft',\n createdAt: Date.now(),\n };\n\n this.plans.set(id, plan);\n return plan;\n }\n\n async approvePlan(planId: string): Promise<PlanApprovalOptions> {\n const plan = this.plans.get(planId);\n if (!plan) {\n this.promptService.error('Plan not found');\n return { approved: false, autoApprove: false };\n }\n\n // Renderizar plano\n console.log('\\n' + '='.repeat(60));\n this.promptService.info(`📋 PLANO: ${plan.title}`);\n console.log('='.repeat(60));\n console.log('');\n console.log(plan.description);\n console.log('');\n console.log(`${Colors.bold}Tarefas (${plan.tasks.length}):${Colors.reset}`);\n console.log('');\n\n plan.tasks.forEach((task, index) => {\n const depInfo =\n task.dependencies.length > 0\n ? ` ${Colors.muted}(depende de: ${task.dependencies.join(', ')})${Colors.reset}`\n : '';\n console.log(` ${Colors.primary}${index + 1}.${Colors.reset} ${Colors.bold}${task.subject}${Colors.reset}${depInfo}`);\n console.log(` ${Colors.dim}${task.description}${Colors.reset}`);\n console.log('');\n });\n\n console.log('='.repeat(60));\n console.log('');\n\n // Opções aprimoradas\n const choices = [\n {\n key: 'approve',\n label: '1 - Sim',\n description: 'Executar o plano'\n },\n {\n key: 'auto-approve',\n label: '2 - Sim com auto-approve',\n description: 'Executar sem pedir aprovação em cada etapa'\n },\n {\n key: 'modify',\n label: '4 - Digite algo',\n description: 'Modificar o plano antes de executar'\n },\n {\n key: 'cancel',\n label: '3 - Não',\n description: 'Cancelar e não executar'\n },\n ];\n\n const choice = await this.promptService.choice('O que você deseja fazer?', choices);\n\n switch (choice) {\n case 'approve':\n plan.status = 'approved';\n this.promptService.success('✓ Plano aprovado! Iniciando execução...');\n return { approved: true, autoApprove: false };\n\n case 'auto-approve':\n plan.status = 'approved';\n this.promptService.success('✓ Plano aprovado com auto-approve! Execução automática ativada.');\n return { approved: true, autoApprove: true };\n\n case 'modify':\n const modification = await this.promptService.question(\n `${Colors.accent}Como deseja modificar o plano?${Colors.reset}`\n );\n plan.status = 'draft';\n return {\n approved: false,\n autoApprove: false,\n modificationRequested: modification\n };\n\n case 'cancel':\n plan.status = 'cancelled';\n this.promptService.info('Plano cancelado');\n return { approved: false, autoApprove: false };\n\n default:\n return { approved: false, autoApprove: false };\n }\n }\n\n async executePlan(planId: string): Promise<void> {\n const plan = this.plans.get(planId);\n if (!plan) {\n throw new Error('Plan not found');\n }\n\n if (plan.status !== 'approved') {\n throw new Error('Plan must be approved before execution');\n }\n\n plan.status = 'executing';\n this.promptService.info('Starting plan execution...');\n }\n\n private generateActiveForm(subject: string): string {\n const firstWord = subject.split(' ')[0].toLowerCase();\n const rest = subject.slice(firstWord.length);\n\n const gerundMap: Record<string, string> = {\n create: 'Creating',\n add: 'Adding',\n implement: 'Implementing',\n fix: 'Fixing',\n update: 'Updating',\n remove: 'Removing',\n delete: 'Deleting',\n refactor: 'Refactoring',\n test: 'Testing',\n write: 'Writing',\n read: 'Reading',\n };\n\n const gerund = gerundMap[firstWord] || subject + 'ing';\n return gerund + rest;\n }\n\n clearCompletedTasks(): void {\n for (const [id, task] of this.tasks.entries()) {\n if (task.status === TaskStatus.COMPLETED || task.status === TaskStatus.CANCELLED) {\n this.tasks.delete(id);\n }\n }\n }\n\n setExecutionContext(context: PlanExecutionContext): void {\n this.executionContext = context;\n }\n\n getExecutionContext(): PlanExecutionContext | null {\n return this.executionContext;\n }\n\n clearExecutionContext(): void {\n this.executionContext = null;\n }\n\n isAutoApproveActive(): boolean {\n return this.executionContext?.autoApprove ?? false;\n }\n\n getPlans(): Map<string, TaskPlan> {\n return this.plans;\n }\n}\n"],"names":["TaskManagementService","createTask","options","id","taskCounter","task","subject","description","activeForm","generateActiveForm","status","TaskStatus","PENDING","createdAt","Date","now","updatedAt","dependencies","blocks","metadata","tasks","set","depId","dep","get","push","updateTask","taskId","addDependencies","removeDependencies","filter","includes","getTask","listTasks","Array","from","values","listPendingTasks","every","COMPLETED","createPlan","title","planCounter","createdTasks","map","taskOpt","plan","plans","approvePlan","planId","promptService","error","approved","autoApprove","console","log","repeat","info","Colors","bold","length","reset","forEach","index","depInfo","muted","join","primary","dim","choices","key","label","choice","success","modification","question","accent","modificationRequested","executePlan","Error","firstWord","split","toLowerCase","rest","slice","gerundMap","create","add","implement","fix","update","remove","delete","refactor","test","write","read","gerund","clearCompletedTasks","entries","CANCELLED","setExecutionContext","context","executionContext","getExecutionContext","clearExecutionContext","isAutoApproveActive","getPlans","Map"],"mappings":";;;;+BAeaA;;;eAAAA;;;wBAfc;2BASpB;+BACuB;uBACP;;;;;;;;;;AAIhB,IAAA,AAAMA,wBAAN,MAAMA;IASXC,WAAWC,OAA0B,EAAQ;QAC3C,MAAMC,KAAK,CAAC,KAAK,EAAE,EAAE,IAAI,CAACC,WAAW,EAAE;QAEvC,MAAMC,OAAa;YACjBF;YACAG,SAASJ,QAAQI,OAAO;YACxBC,aAAaL,QAAQK,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{"version":3,"sources":["../../../../src/modules/tasks/services/task-management.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { EventEmitter } from 'events';\nimport {\n Task,\n TaskStatus,\n TaskPlan,\n CreateTaskOptions,\n UpdateTaskOptions,\n PlanApprovalOptions,\n PlanExecutionContext,\n} from '../types/task.types';\nimport { PromptService } from '../../permissions/services/prompt.service';\nimport { Colors } from '../../repl/utils/theme';\n\n@Injectable()\nexport class TaskManagementService {\n readonly events = new EventEmitter();\n private tasks: Map<string, Task> = new Map();\n private plans: Map<string, TaskPlan> = new Map();\n private taskCounter = 0;\n private planCounter = 0;\n private executionContext: PlanExecutionContext | null = null;\n\n constructor(private promptService: PromptService) { }\n\n createTask(options: CreateTaskOptions): Task {\n const id = `task-${++this.taskCounter}`;\n\n const task: Task = {\n id,\n subject: options.subject,\n description: options.description,\n activeForm: options.activeForm || this.generateActiveForm(options.subject),\n status: TaskStatus.PENDING,\n createdAt: Date.now(),\n updatedAt: Date.now(),\n dependencies: options.dependencies || [],\n blocks: [],\n metadata: options.metadata || {},\n };\n\n this.tasks.set(id, task);\n\n for (const depId of task.dependencies) {\n const dep = this.tasks.get(depId);\n if (dep) {\n dep.blocks.push(id);\n }\n }\n\n this.events.emit('task:created', task);\n return task;\n }\n\n updateTask(taskId: string, options: UpdateTaskOptions): Task | null {\n const task = this.tasks.get(taskId);\n if (!task) return null;\n\n if (options.status) task.status = options.status;\n if (options.subject) task.subject = options.subject;\n if (options.description) task.description = options.description;\n if (options.activeForm) task.activeForm = options.activeForm;\n\n if (options.addDependencies) {\n task.dependencies.push(...options.addDependencies);\n }\n\n if (options.removeDependencies) {\n task.dependencies = task.dependencies.filter(\n (id) => !options.removeDependencies?.includes(id),\n );\n }\n\n if (options.assignedAgent !== undefined) task.assignedAgent = options.assignedAgent;\n\n if (options.metadata) {\n task.metadata = { ...task.metadata, ...options.metadata };\n }\n\n task.updatedAt = Date.now();\n this.events.emit('task:updated', task);\n\n // Debug log for Kanban updates\n if (options.status) {\n process.stdout.write(`\\r Task ${taskId} status updated to: ${options.status}\\n`);\n }\n\n return task;\n }\n\n getTask(taskId: string): Task | null {\n return this.tasks.get(taskId) || null;\n }\n\n listTasks(): Task[] {\n return Array.from(this.tasks.values());\n }\n\n listPendingTasks(): Task[] {\n return this.listTasks().filter((task) => {\n if (task.status !== TaskStatus.PENDING) return false;\n\n return task.dependencies.every((depId) => {\n const dep = this.tasks.get(depId);\n return dep && dep.status === TaskStatus.COMPLETED;\n });\n });\n }\n\n createPlan(title: string, description: string, tasks: CreateTaskOptions[]): TaskPlan {\n const id = `plan-${++this.planCounter}`;\n\n const createdTasks = tasks.map((taskOpt) => this.createTask(taskOpt));\n\n const plan: TaskPlan = {\n id,\n title,\n description,\n tasks: createdTasks,\n status: 'draft',\n createdAt: Date.now(),\n };\n\n this.plans.set(id, plan);\n this.events.emit('plan:created', plan);\n return plan;\n }\n\n async approvePlan(planId: string): Promise<PlanApprovalOptions> {\n const plan = this.plans.get(planId);\n if (!plan) {\n this.promptService.error('Plan not found');\n return { approved: false, autoApprove: false };\n }\n\n // Renderizar plano\n console.log(`\\n${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n this.promptService.info(`${Colors.bold}📋 PLAN: ${plan.title}${Colors.reset}`);\n console.log(`${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n console.log('');\n console.log(plan.description);\n console.log('');\n console.log(`${Colors.bold}Tasks (${plan.tasks.length}):${Colors.reset}`);\n console.log('');\n\n plan.tasks.forEach((task, index) => {\n const depInfo =\n task.dependencies.length > 0\n ? ` ${Colors.muted}(depends on: ${task.dependencies.join(', ')})${Colors.reset}`\n : '';\n console.log(` ${Colors.primary}${index + 1}.${Colors.reset} ${Colors.bold}${task.subject}${Colors.reset}${depInfo}`);\n console.log(` ${Colors.dim}${task.description}${Colors.reset}`);\n console.log('');\n });\n\n console.log(`${Colors.dim}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${Colors.reset}`);\n console.log('');\n\n // Opções aprimoradas\n const choices = [\n {\n key: 'approve',\n label: 'Approve',\n description: 'Execute the plan'\n },\n {\n key: 'auto-approve',\n label: 'Auto-approve',\n description: 'Execute without asking for approval on each step'\n },\n {\n key: 'modify',\n label: 'Modify',\n description: 'Modify the plan before executing'\n },\n {\n key: 'cancel',\n label: 'Cancel',\n description: 'Cancel and do not execute'\n },\n ];\n\n const choice = await this.promptService.choice('What do you want to do?', choices);\n\n switch (choice) {\n case 'approve':\n plan.status = 'approved';\n this.promptService.success('✓ Plan approved! Starting execution...');\n return { approved: true, autoApprove: false };\n\n case 'auto-approve':\n plan.status = 'approved';\n this.promptService.success('✓ Plan approved with auto-approve! Automatic execution enabled.');\n return { approved: true, autoApprove: true };\n\n case 'modify':\n const modification = await this.promptService.question(\n `${Colors.accent}How do you want to modify the plan?${Colors.reset}`\n );\n plan.status = 'draft';\n return {\n approved: false,\n autoApprove: false,\n modificationRequested: modification\n };\n\n case 'cancel':\n plan.status = 'cancelled';\n this.promptService.info('Plan cancelled');\n return { approved: false, autoApprove: false };\n\n default:\n return { approved: false, autoApprove: false };\n }\n }\n\n async executePlan(planId: string): Promise<void> {\n const plan = this.plans.get(planId);\n if (!plan) {\n throw new Error('Plan not found');\n }\n\n if (plan.status !== 'approved') {\n throw new Error('Plan must be approved before execution');\n }\n\n plan.status = 'executing';\n this.promptService.info('Starting plan execution...');\n }\n\n private generateActiveForm(subject: string): string {\n const firstWord = subject.split(' ')[0].toLowerCase();\n const rest = subject.slice(firstWord.length);\n\n const gerundMap: Record<string, string> = {\n // English\n create: 'Creating',\n add: 'Adding',\n implement: 'Implementing',\n fix: 'Fixing',\n update: 'Updating',\n remove: 'Removing',\n delete: 'Deleting',\n refactor: 'Refactoring',\n test: 'Testing',\n write: 'Writing',\n read: 'Reading',\n // Portuguese\n criar: 'Criando',\n adicionar: 'Adicionando',\n implementar: 'Implementando',\n corrigir: 'Corrigindo',\n atualizar: 'Atualizando',\n remover: 'Removendo',\n deletar: 'Deletando',\n refatorar: 'Refatorando',\n testar: 'Testando',\n escrever: 'Escrevendo',\n ler: 'Lendo',\n analisar: 'Analisando',\n fazer: 'Fazendo',\n crie: 'Criando',\n adicione: 'Adicionando',\n implemente: 'Implementando',\n corrija: 'Corrigindo',\n atualize: 'Atualizando',\n remova: 'Removendo',\n analise: 'Analisando',\n faça: 'Fazendo',\n };\n\n const gerund = gerundMap[firstWord] || (subject.length > 20 ? subject.slice(0, 20) + '...' : subject);\n return gerund + rest;\n }\n\n clearCompletedTasks(): void {\n for (const [id, task] of this.tasks.entries()) {\n if (task.status === TaskStatus.COMPLETED || task.status === TaskStatus.CANCELLED) {\n this.tasks.delete(id);\n }\n }\n }\n\n setExecutionContext(context: PlanExecutionContext): void {\n this.executionContext = context;\n }\n\n getExecutionContext(): PlanExecutionContext | null {\n return this.executionContext;\n }\n\n clearExecutionContext(): void {\n this.executionContext = null;\n }\n\n isAutoApproveActive(): boolean {\n return this.executionContext?.autoApprove ?? false;\n }\n\n getPlans(): Map<string, TaskPlan> {\n return this.plans;\n }\n}\n"],"names":["TaskManagementService","createTask","options","id","taskCounter","task","subject","description","activeForm","generateActiveForm","status","TaskStatus","PENDING","createdAt","Date","now","updatedAt","dependencies","blocks","metadata","tasks","set","depId","dep","get","push","events","emit","updateTask","taskId","addDependencies","removeDependencies","filter","includes","assignedAgent","undefined","process","stdout","write","getTask","listTasks","Array","from","values","listPendingTasks","every","COMPLETED","createPlan","title","planCounter","createdTasks","map","taskOpt","plan","plans","approvePlan","planId","promptService","error","approved","autoApprove","console","log","Colors","dim","reset","info","bold","length","forEach","index","depInfo","muted","join","primary","choices","key","label","choice","success","modification","question","accent","modificationRequested","executePlan","Error","firstWord","split","toLowerCase","rest","slice","gerundMap","create","add","implement","fix","update","remove","delete","refactor","test","read","criar","adicionar","implementar","corrigir","atualizar","remover","deletar","refatorar","testar","escrever","ler","analisar","fazer","crie","adicione","implemente","corrija","atualize","remova","analise","faça","gerund","clearCompletedTasks","entries","CANCELLED","setExecutionContext","context","executionContext","getExecutionContext","clearExecutionContext","isAutoApproveActive","getPlans","EventEmitter","Map"],"mappings":";;;;+BAeaA;;;eAAAA;;;wBAfc;wBACE;2BAStB;+BACuB;uBACP;;;;;;;;;;AAGhB,IAAA,AAAMA,wBAAN,MAAMA;IAUXC,WAAWC,OAA0B,EAAQ;QAC3C,MAAMC,KAAK,CAAC,KAAK,EAAE,EAAE,IAAI,CAACC,WAAW,EAAE;QAEvC,MAAMC,OAAa;YACjBF;YACAG,SAASJ,QAAQI,OAAO;YACxBC,aAAaL,QAAQK,WAAW;YAChCC,YAAYN,QAAQM,UAAU,IAAI,IAAI,CAACC,kBAAkB,CAACP,QAAQI,OAAO;YACzEI,QAAQC,qBAAU,CAACC,OAAO;YAC1BC,WAAWC,KAAKC,GAAG;YACnBC,WAAWF,KAAKC,GAAG;YACnBE,cAAcf,QAAQe,YAAY,IAAI,EAAE;YACxCC,QAAQ,EAAE;YACVC,UAAUjB,QAAQiB,QAAQ,IAAI,CAAC;QACjC;QAEA,IAAI,CAACC,KAAK,CAACC,GAAG,CAAClB,IAAIE;QAEnB,KAAK,MAAMiB,SAASjB,KAAKY,YAAY,CAAE;YACrC,MAAMM,MAAM,IAAI,CAACH,KAAK,CAACI,GAAG,CAACF;YAC3B,IAAIC,KAAK;gBACPA,IAAIL,MAAM,CAACO,IAAI,CAACtB;YAClB;QACF;QAEA,IAAI,CAACuB,MAAM,CAACC,IAAI,CAAC,gBAAgBtB;QACjC,OAAOA;IACT;IAEAuB,WAAWC,MAAc,EAAE3B,OAA0B,EAAe;QAClE,MAAMG,OAAO,IAAI,CAACe,KAAK,CAACI,GAAG,CAACK;QAC5B,IAAI,CAACxB,MAAM,OAAO;QAElB,IAAIH,QAAQQ,MA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O,IAAI,CAACH,gBAAgB,EAAErE,eAAe;IAC/C;IAEAyE,WAAkC;QAChC,OAAO,IAAI,CAAC/E,KAAK;IACnB;IAtRA,YAAY,AAAQG,aAA4B,CAAE;aAA9BA,gBAAAA;aAPX/B,SAAS,IAAI4G,oBAAY;aAC1BlH,QAA2B,IAAImH;aAC/BjF,QAA+B,IAAIiF;aACnCnI,cAAc;aACd6C,cAAc;aACdgF,mBAAgD;IAEJ;AAuRtD"}
|
|
@@ -211,7 +211,7 @@ let TaskToolsService = class TaskToolsService {
|
|
|
211
211
|
}
|
|
212
212
|
}, {
|
|
213
213
|
name: 'enter_plan_mode',
|
|
214
|
-
description: 'Enter planning mode for complex tasks. In plan mode, you
|
|
214
|
+
description: 'Enter planning mode for complex tasks. In plan mode, you MUST explore the codebase using read_file, glob, and grep to understand the architecture, then create a detailed plan. IMPORTANT: When using exit_plan_mode, you MUST provide a comprehensive list of tasks that make up the plan.',
|
|
215
215
|
schema: _zod.z.object({
|
|
216
216
|
title: _zod.z.string().describe('Title of the plan (e.g., "Implement user authentication")'),
|
|
217
217
|
description: _zod.z.string().describe('Brief description of what will be planned')
|
|
@@ -240,7 +240,7 @@ let TaskToolsService = class TaskToolsService {
|
|
|
240
240
|
}
|
|
241
241
|
}, {
|
|
242
242
|
name: 'exit_plan_mode',
|
|
243
|
-
description: 'Exit planning mode and present the plan for user approval. The user will see all tasks and can approve, modify, or cancel the plan.',
|
|
243
|
+
description: 'Exit planning mode and present the plan for user approval. CRITICAL: You MUST provide ALL the tasks you planned in the `tasks` array. If you do not provide any tasks, the plan will be empty. The user will see all tasks and can approve, modify, or cancel the plan.',
|
|
244
244
|
schema: _zod.z.object({
|
|
245
245
|
tasks: _zod.z.array(_zod.z.object({
|
|
246
246
|
subject: _zod.z.string().describe('Task title'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/tasks/services/task-tools.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { tool } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { TaskManagementService } from './task-management.service';\nimport { PlanModeService } from './plan-mode.service';\nimport { TaskStatus } from '../types/task.types';\nimport { PromptService } from '../../permissions/services/prompt.service';\n\n@Injectable()\nexport class TaskToolsService {\n constructor(\n private taskService: TaskManagementService,\n private planModeService: PlanModeService,\n private promptService: PromptService,\n ) {}\n\n getTools() {\n return [\n this.createTaskCreateTool(),\n this.createTaskUpdateTool(),\n this.createTaskListTool(),\n this.createTaskGetTool(),\n this.createAskUserQuestionTool(),\n this.createEnterPlanModeTool(),\n this.createExitPlanModeTool(),\n ];\n }\n\n private createTaskCreateTool() {\n return tool(\n async ({ subject, description, activeForm, dependencies, metadata }) => {\n const task = this.taskService.createTask({\n subject,\n description,\n activeForm,\n dependencies: dependencies || [],\n metadata: metadata || {},\n });\n\n return JSON.stringify({\n success: true,\n taskId: task.id,\n task: {\n id: task.id,\n subject: task.subject,\n status: task.status,\n },\n });\n },\n {\n name: 'task_create',\n description:\n 'Create a new task. Use this when breaking down complex work into trackable subtasks. The task will be shown to the user for approval.',\n schema: z.object({\n subject: z.string().describe('Brief task title (e.g., \"Implement login endpoint\")'),\n description: z\n .string()\n .describe('Detailed description of what needs to be done and why'),\n activeForm: z\n .string()\n .optional()\n .describe(\n 'Present continuous form shown when in_progress (e.g., \"Implementing login\")',\n ),\n dependencies: z\n .array(z.string())\n .optional()\n .describe('Array of task IDs that must complete before this one'),\n metadata: z.record(z.any()).optional().describe('Additional metadata'),\n }),\n },\n );\n }\n\n private createTaskUpdateTool() {\n return tool(\n async ({ taskId, status, subject, description, activeForm, addDependencies, metadata }) => {\n const task = this.taskService.updateTask(taskId, {\n status: status as TaskStatus,\n subject,\n description,\n activeForm,\n addDependencies,\n metadata,\n });\n\n if (!task) {\n return JSON.stringify({ success: false, error: 'Task not found' });\n }\n\n return JSON.stringify({\n success: true,\n task: {\n id: task.id,\n subject: task.subject,\n status: task.status,\n },\n });\n },\n {\n name: 'task_update',\n description:\n 'Update an existing task. Use to change status, modify details, or add dependencies.',\n schema: z.object({\n taskId: z.string().describe('ID of the task to update'),\n status: z\n .enum(['pending', 'in_progress', 'completed', 'failed', 'blocked', 'cancelled'])\n .optional()\n .describe('New status for the task'),\n subject: z.string().optional().describe('New subject'),\n description: z.string().optional().describe('New description'),\n activeForm: z.string().optional().describe('New active form'),\n addDependencies: z\n .array(z.string())\n .optional()\n .describe('Task IDs to add as dependencies'),\n metadata: z.record(z.any()).optional().describe('Metadata to merge'),\n }),\n },\n );\n }\n\n private createTaskListTool() {\n return tool(\n async () => {\n const tasks = this.taskService.listTasks();\n const pending = this.taskService.listPendingTasks();\n\n return JSON.stringify({\n total: tasks.length,\n pending: pending.length,\n tasks: tasks.map((t) => ({\n id: t.id,\n subject: t.subject,\n status: t.status,\n dependencies: t.dependencies,\n blocks: t.blocks,\n })),\n });\n },\n {\n name: 'task_list',\n description: 'List all tasks with their current status. Shows which tasks are ready to execute.',\n schema: z.object({}),\n },\n );\n }\n\n private createTaskGetTool() {\n return tool(\n async ({ taskId }) => {\n const task = this.taskService.getTask(taskId);\n\n if (!task) {\n return JSON.stringify({ success: false, error: 'Task not found' });\n }\n\n return JSON.stringify({\n success: true,\n task,\n });\n },\n {\n name: 'task_get',\n description: 'Get full details of a specific task including description and metadata.',\n schema: z.object({\n taskId: z.string().describe('ID of the task to retrieve'),\n }),\n },\n );\n }\n\n private createAskUserQuestionTool() {\n return tool(\n async ({ question, type, choices }) => {\n console.log('');\n\n if (type === 'confirm') {\n const answer = await this.promptService.confirm(question);\n return JSON.stringify({ answer });\n }\n\n if (type === 'choice' && choices) {\n const choiceObjects = choices.map((c, i) => ({\n key: String(i),\n label: c,\n }));\n\n const selectedKey = await this.promptService.choice(question, choiceObjects);\n const selectedIndex = parseInt(selectedKey);\n return JSON.stringify({ answer: choices[selectedIndex] });\n }\n\n if (type === 'text') {\n const answer = await this.promptService.question(question);\n return JSON.stringify({ answer });\n }\n\n return JSON.stringify({ error: 'Invalid question type' });\n },\n {\n name: 'ask_user_question',\n description:\n 'Ask the user a question interactively. Use this when you need clarification, preferences, or decisions from the user before proceeding. This is better than guessing!',\n schema: z.object({\n question: z.string().describe('The question to ask the user'),\n type: z\n .enum(['confirm', 'choice', 'text'])\n .describe('Type of question: confirm (yes/no), choice (multiple options), or text (free form)'),\n choices: z\n .array(z.string())\n .optional()\n .describe('Array of choices for type=choice'),\n }),\n },\n );\n }\n\n private createEnterPlanModeTool() {\n return tool(\n async ({ title, description }) => {\n try {\n await this.planModeService.enterPlanMode(title, description);\n return JSON.stringify({\n success: true,\n message: 'Entered plan mode. Explore the codebase, design your approach, then use exit_plan_mode to present the plan for approval.',\n });\n } catch (error) {\n return JSON.stringify({\n success: false,\n error: (error as Error).message,\n });\n }\n },\n {\n name: 'enter_plan_mode',\n description:\n 'Enter planning mode for complex tasks. In plan mode, you should explore the codebase using read_file, glob, and grep to understand the architecture, then create a detailed plan. Use exit_plan_mode when ready to present the plan for user approval.',\n schema: z.object({\n title: z.string().describe('Title of the plan (e.g., \"Implement user authentication\")'),\n description: z\n .string()\n .describe('Brief description of what will be planned'),\n }),\n },\n );\n }\n\n private createExitPlanModeTool() {\n return tool(\n async ({ tasks }) => {\n try {\n const approval = await this.planModeService.exitPlanMode(\n tasks.map((t) => ({\n subject: t.subject,\n description: t.description,\n activeForm: t.activeForm,\n dependencies: t.dependencies,\n })),\n );\n\n return JSON.stringify({\n success: true,\n approved: approval,\n message: approval.approved\n ? 'Plan approved! You can now execute the tasks.'\n : 'Plan was not approved. Ask the user what they want to change.',\n });\n } catch (error) {\n return JSON.stringify({\n success: false,\n error: (error as Error).message,\n });\n }\n },\n {\n name: 'exit_plan_mode',\n description:\n 'Exit planning mode and present the plan for user approval. The user will see all tasks and can approve, modify, or cancel the plan.',\n schema: z.object({\n tasks: z\n .array(\n z.object({\n subject: z.string().describe('Task title'),\n description: z.string().describe('What this task does'),\n activeForm: z.string().optional().describe('Present continuous form'),\n dependencies: z\n .array(z.string())\n .optional()\n .describe('Task IDs this depends on'),\n }),\n )\n .describe('Array of tasks that make up the plan'),\n }),\n },\n );\n }\n}\n"],"names":["TaskToolsService","getTools","createTaskCreateTool","createTaskUpdateTool","createTaskListTool","createTaskGetTool","createAskUserQuestionTool","createEnterPlanModeTool","createExitPlanModeTool","tool","subject","description","activeForm","dependencies","metadata","task","taskService","createTask","JSON","stringify","success","taskId","id","status","name","schema","z","object","string","describe","optional","array","record","any","addDependencies","updateTask","error","enum","tasks","listTasks","pending","listPendingTasks","total","length","map","t","blocks","getTask","question","type","choices","console","log","answer","promptService","confirm","choiceObjects","c","i","key","String","label","selectedKey","choice","selectedIndex","parseInt","title","planModeService","enterPlanMode","message","approval","exitPlanMode","approved"],"mappings":";;;;+BASaA;;;eAAAA;;;wBATc;uBACN;qBACH;uCACoB;iCACN;+BAEF;;;;;;;;;;AAGvB,IAAA,AAAMA,mBAAN,MAAMA;IAOXC,WAAW;QACT,OAAO;YACL,IAAI,CAACC,oBAAoB;YACzB,IAAI,CAACC,oBAAoB;YACzB,IAAI,CAACC,kBAAkB;YACvB,IAAI,CAACC,iBAAiB;YACtB,IAAI,CAACC,yBAAyB;YAC9B,IAAI,CAACC,uBAAuB;YAC5B,IAAI,CAACC,sBAAsB;SAC5B;IACH;IAEQN,uBAAuB;QAC7B,OAAOO,IAAAA,WAAI,EACT,OAAO,EAAEC,OAAO,EAAEC,WAAW,EAAEC,UAAU,EAAEC,YAAY,EAAEC,QAAQ,EAAE;YACjE,MAAMC,OAAO,IAAI,CAACC,WAAW,CAACC,UAAU,CAAC;gBACvCP;gBACAC;gBACAC;gBACAC,cAAcA,gBAAgB,EAAE;gBAChCC,UAAUA,YAAY,CAAC;YACzB;YAEA,OAAOI,KAAKC,SAAS,CAAC;gBACpBC,SAAS;gBACTC,QAAQN,KAAKO,EAAE;gBACfP,MAAM;oBACJO,IAAIP,KAAKO,EAAE;oBACXZ,SAASK,KAAKL,OAAO;oBACrBa,QAAQR,KAAKQ,MAAM;gB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,MAAM;YACNb,aACE;YACFc,QAAQC,MAAC,CAACC,MAAM,CAAC;gBACfW,OAAOZ,MAAC,CACLK,KAAK,CACJL,MAAC,CAACC,MAAM,CAAC;oBACPjB,SAASgB,MAAC,CAACE,MAAM,GAAGC,QAAQ,CAAC;oBAC7BlB,aAAae,MAAC,CAACE,MAAM,GAAGC,QAAQ,CAAC;oBACjCjB,YAAYc,MAAC,CAACE,MAAM,GAAGE,QAAQ,GAAGD,QAAQ,CAAC;oBAC3ChB,cAAca,MAAC,CACZK,KAAK,CAACL,MAAC,CAACE,MAAM,IACdE,QAAQ,GACRD,QAAQ,CAAC;gBACd,IAEDA,QAAQ,CAAC;YACd;QACF;IAEJ;IA9RA,YACE,AAAQb,WAAkC,EAC1C,AAAQmD,eAAgC,EACxC,AAAQb,aAA4B,CACpC;aAHQtC,cAAAA;aACAmD,kBAAAA;aACAb,gBAAAA;IACP;AA2RL"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/tasks/services/task-tools.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { tool } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { TaskManagementService } from './task-management.service';\nimport { PlanModeService } from './plan-mode.service';\nimport { TaskStatus } from '../types/task.types';\nimport { PromptService } from '../../permissions/services/prompt.service';\n\n@Injectable()\nexport class TaskToolsService {\n constructor(\n private taskService: TaskManagementService,\n private planModeService: PlanModeService,\n private promptService: PromptService,\n ) {}\n\n getTools() {\n return [\n this.createTaskCreateTool(),\n this.createTaskUpdateTool(),\n this.createTaskListTool(),\n this.createTaskGetTool(),\n this.createAskUserQuestionTool(),\n this.createEnterPlanModeTool(),\n this.createExitPlanModeTool(),\n ];\n }\n\n private createTaskCreateTool() {\n return tool(\n async ({ subject, description, activeForm, dependencies, metadata }) => {\n const task = this.taskService.createTask({\n subject,\n description,\n activeForm,\n dependencies: dependencies || [],\n metadata: metadata || {},\n });\n\n return JSON.stringify({\n success: true,\n taskId: task.id,\n task: {\n id: task.id,\n subject: task.subject,\n status: task.status,\n },\n });\n },\n {\n name: 'task_create',\n description:\n 'Create a new task. Use this when breaking down complex work into trackable subtasks. The task will be shown to the user for approval.',\n schema: z.object({\n subject: z.string().describe('Brief task title (e.g., \"Implement login endpoint\")'),\n description: z\n .string()\n .describe('Detailed description of what needs to be done and why'),\n activeForm: z\n .string()\n .optional()\n .describe(\n 'Present continuous form shown when in_progress (e.g., \"Implementing login\")',\n ),\n dependencies: z\n .array(z.string())\n .optional()\n .describe('Array of task IDs that must complete before this one'),\n metadata: z.record(z.any()).optional().describe('Additional metadata'),\n }),\n },\n );\n }\n\n private createTaskUpdateTool() {\n return tool(\n async ({ taskId, status, subject, description, activeForm, addDependencies, metadata }) => {\n const task = this.taskService.updateTask(taskId, {\n status: status as TaskStatus,\n subject,\n description,\n activeForm,\n addDependencies,\n metadata,\n });\n\n if (!task) {\n return JSON.stringify({ success: false, error: 'Task not found' });\n }\n\n return JSON.stringify({\n success: true,\n task: {\n id: task.id,\n subject: task.subject,\n status: task.status,\n },\n });\n },\n {\n name: 'task_update',\n description:\n 'Update an existing task. Use to change status, modify details, or add dependencies.',\n schema: z.object({\n taskId: z.string().describe('ID of the task to update'),\n status: z\n .enum(['pending', 'in_progress', 'completed', 'failed', 'blocked', 'cancelled'])\n .optional()\n .describe('New status for the task'),\n subject: z.string().optional().describe('New subject'),\n description: z.string().optional().describe('New description'),\n activeForm: z.string().optional().describe('New active form'),\n addDependencies: z\n .array(z.string())\n .optional()\n .describe('Task IDs to add as dependencies'),\n metadata: z.record(z.any()).optional().describe('Metadata to merge'),\n }),\n },\n );\n }\n\n private createTaskListTool() {\n return tool(\n async () => {\n const tasks = this.taskService.listTasks();\n const pending = this.taskService.listPendingTasks();\n\n return JSON.stringify({\n total: tasks.length,\n pending: pending.length,\n tasks: tasks.map((t) => ({\n id: t.id,\n subject: t.subject,\n status: t.status,\n dependencies: t.dependencies,\n blocks: t.blocks,\n })),\n });\n },\n {\n name: 'task_list',\n description: 'List all tasks with their current status. Shows which tasks are ready to execute.',\n schema: z.object({}),\n },\n );\n }\n\n private createTaskGetTool() {\n return tool(\n async ({ taskId }) => {\n const task = this.taskService.getTask(taskId);\n\n if (!task) {\n return JSON.stringify({ success: false, error: 'Task not found' });\n }\n\n return JSON.stringify({\n success: true,\n task,\n });\n },\n {\n name: 'task_get',\n description: 'Get full details of a specific task including description and metadata.',\n schema: z.object({\n taskId: z.string().describe('ID of the task to retrieve'),\n }),\n },\n );\n }\n\n private createAskUserQuestionTool() {\n return tool(\n async ({ question, type, choices }) => {\n console.log('');\n\n if (type === 'confirm') {\n const answer = await this.promptService.confirm(question);\n return JSON.stringify({ answer });\n }\n\n if (type === 'choice' && choices) {\n const choiceObjects = choices.map((c, i) => ({\n key: String(i),\n label: c,\n }));\n\n const selectedKey = await this.promptService.choice(question, choiceObjects);\n const selectedIndex = parseInt(selectedKey);\n return JSON.stringify({ answer: choices[selectedIndex] });\n }\n\n if (type === 'text') {\n const answer = await this.promptService.question(question);\n return JSON.stringify({ answer });\n }\n\n return JSON.stringify({ error: 'Invalid question type' });\n },\n {\n name: 'ask_user_question',\n description:\n 'Ask the user a question interactively. Use this when you need clarification, preferences, or decisions from the user before proceeding. This is better than guessing!',\n schema: z.object({\n question: z.string().describe('The question to ask the user'),\n type: z\n .enum(['confirm', 'choice', 'text'])\n .describe('Type of question: confirm (yes/no), choice (multiple options), or text (free form)'),\n choices: z\n .array(z.string())\n .optional()\n .describe('Array of choices for type=choice'),\n }),\n },\n );\n }\n\n private createEnterPlanModeTool() {\n return tool(\n async ({ title, description }) => {\n try {\n await this.planModeService.enterPlanMode(title, description);\n return JSON.stringify({\n success: true,\n message: 'Entered plan mode. Explore the codebase, design your approach, then use exit_plan_mode to present the plan for approval.',\n });\n } catch (error) {\n return JSON.stringify({\n success: false,\n error: (error as Error).message,\n });\n }\n },\n {\n name: 'enter_plan_mode',\n description:\n 'Enter planning mode for complex tasks. In plan mode, you MUST explore the codebase using read_file, glob, and grep to understand the architecture, then create a detailed plan. IMPORTANT: When using exit_plan_mode, you MUST provide a comprehensive list of tasks that make up the plan.',\n schema: z.object({\n title: z.string().describe('Title of the plan (e.g., \"Implement user authentication\")'),\n description: z\n .string()\n .describe('Brief description of what will be planned'),\n }),\n },\n );\n }\n\n private createExitPlanModeTool() {\n return tool(\n async ({ tasks }) => {\n try {\n const approval = await this.planModeService.exitPlanMode(\n tasks.map((t) => ({\n subject: t.subject,\n description: t.description,\n activeForm: t.activeForm,\n dependencies: t.dependencies,\n })),\n );\n\n return JSON.stringify({\n success: true,\n approved: approval,\n message: approval.approved\n ? 'Plan approved! You can now execute the tasks.'\n : 'Plan was not approved. Ask the user what they want to change.',\n });\n } catch (error) {\n return JSON.stringify({\n success: false,\n error: (error as Error).message,\n });\n }\n },\n {\n name: 'exit_plan_mode',\n description:\n 'Exit planning mode and present the plan for user approval. CRITICAL: You MUST provide ALL the tasks you planned in the `tasks` array. If you do not provide any tasks, the plan will be empty. The user will see all tasks and can approve, modify, or cancel the plan.',\n schema: z.object({\n tasks: z\n .array(\n z.object({\n subject: z.string().describe('Task title'),\n description: z.string().describe('What this task does'),\n activeForm: z.string().optional().describe('Present continuous form'),\n dependencies: z\n .array(z.string())\n .optional()\n .describe('Task IDs this depends on'),\n }),\n )\n .describe('Array of tasks that make up the plan'),\n }),\n },\n );\n }\n}\n"],"names":["TaskToolsService","getTools","createTaskCreateTool","createTaskUpdateTool","createTaskListTool","createTaskGetTool","createAskUserQuestionTool","createEnterPlanModeTool","createExitPlanModeTool","tool","subject","description","activeForm","dependencies","metadata","task","taskService","createTask","JSON","stringify","success","taskId","id","status","name","schema","z","object","string","describe","optional","array","record","any","addDependencies","updateTask","error","enum","tasks","listTasks","pending","listPendingTasks","total","length","map","t","blocks","getTask","question","type","choices","console","log","answer","promptService","confirm","choiceObjects","c","i","key","String","label","selectedKey","choice","selectedIndex","parseInt","title","planModeService","enterPlanMode","message","approval","exitPlanMode","approved"],"mappings":";;;;+BASaA;;;eAAAA;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gC,EACxC,AAAQb,aAA4B,CACpC;aAHQtC,cAAAA;aACAmD,kBAAAA;aACAb,gBAAAA;IACP;AA2RL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/tasks/types/task.types.ts"],"sourcesContent":["export enum TaskStatus {\n PENDING = 'pending',\n IN_PROGRESS = 'in_progress',\n COMPLETED = 'completed',\n FAILED = 'failed',\n BLOCKED = 'blocked',\n CANCELLED = 'cancelled',\n}\n\nexport interface Task {\n id: string;\n subject: string;\n description: string;\n activeForm: string;\n status: TaskStatus;\n createdAt: number;\n updatedAt: number;\n dependencies: string[];\n blocks: string[];\n metadata?: Record<string, any>;\n}\n\nexport interface TaskPlan {\n id: string;\n title: string;\n description: string;\n tasks: Task[];\n status: 'draft' | 'approved' | 'executing' | 'completed' | 'cancelled';\n createdAt: number;\n}\n\nexport interface CreateTaskOptions {\n subject: string;\n description: string;\n activeForm?: string;\n dependencies?: string[];\n metadata?: Record<string, any>;\n}\n\nexport interface UpdateTaskOptions {\n status?: TaskStatus;\n subject?: string;\n description?: string;\n activeForm?: string;\n addDependencies?: string[];\n removeDependencies?: string[];\n metadata?: Record<string, any>;\n}\n\nexport interface PlanApprovalOptions {\n approved: boolean;\n autoApprove: boolean;\n modificationRequested?: string;\n}\n\nexport interface PlanExecutionContext {\n planId: string;\n autoApprove: boolean;\n currentTaskIndex: number;\n startedAt: number;\n}\n"],"names":["TaskStatus"],"mappings":";;;;+BAAYA;;;eAAAA;;;AAAL,IAAA,AAAKA,oCAAAA;;;;;;;WAAAA"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/tasks/types/task.types.ts"],"sourcesContent":["export enum TaskStatus {\n PENDING = 'pending',\n IN_PROGRESS = 'in_progress',\n COMPLETED = 'completed',\n FAILED = 'failed',\n BLOCKED = 'blocked',\n CANCELLED = 'cancelled',\n}\n\nexport interface Task {\n id: string;\n subject: string;\n description: string;\n activeForm: string;\n status: TaskStatus;\n createdAt: number;\n updatedAt: number;\n dependencies: string[];\n blocks: string[];\n assignedAgent?: string;\n metadata?: Record<string, any>;\n}\n\nexport interface TaskPlan {\n id: string;\n title: string;\n description: string;\n tasks: Task[];\n status: 'draft' | 'approved' | 'executing' | 'completed' | 'cancelled';\n createdAt: number;\n}\n\nexport interface CreateTaskOptions {\n subject: string;\n description: string;\n activeForm?: string;\n dependencies?: string[];\n metadata?: Record<string, any>;\n}\n\nexport interface UpdateTaskOptions {\n status?: TaskStatus;\n subject?: string;\n description?: string;\n activeForm?: string;\n addDependencies?: string[];\n removeDependencies?: string[];\n assignedAgent?: string;\n metadata?: Record<string, any>;\n}\n\nexport interface PlanApprovalOptions {\n approved: boolean;\n autoApprove: boolean;\n modificationRequested?: string;\n}\n\nexport interface PlanExecutionContext {\n planId: string;\n autoApprove: boolean;\n currentTaskIndex: number;\n startedAt: number;\n}\n"],"names":["TaskStatus"],"mappings":";;;;+BAAYA;;;eAAAA;;;AAAL,IAAA,AAAKA,oCAAAA;;;;;;;WAAAA"}
|