(taskId: string, parentId?: string)
| 113 | |
| 114 | // Execute a single task |
| 115 | async function executeTask(taskId: string, parentId?: string) { |
| 116 | const sessionName = getSessionName(taskId, parentId); |
| 117 | const logFile = path.join(LOG_DIR, `${sessionName}.log`); |
| 118 | |
| 119 | console.log(`\n${colors.cyan}Starting autonomous execution:${colors.reset}`); |
| 120 | console.log(` Task: ${colors.bright}${taskId}${colors.reset}`); |
| 121 | if (parentId) { |
| 122 | console.log(` Parent: ${colors.bright}${parentId}${colors.reset}`); |
| 123 | } |
| 124 | console.log(` Session: ${colors.dim}${sessionName}${colors.reset}`); |
| 125 | console.log(` Log: ${colors.dim}${logFile}${colors.reset}`); |
| 126 | |
| 127 | try { |
| 128 | // Create session with meaningful name |
| 129 | const s = session({ |
| 130 | name: sessionName, |
| 131 | autoSave: true, |
| 132 | }); |
| 133 | |
| 134 | // Save session info for monitor |
| 135 | await saveSessionInfo(sessionName, taskId, parentId, logFile); |
| 136 | |
| 137 | console.log(`${colors.yellow}Starting detached process...${colors.reset}`); |
| 138 | |
| 139 | // Build the prompt with task context |
| 140 | const promptFile = '.tasks/.modes/implement/autonomous.md'; |
| 141 | |
| 142 | // Start detached process |
| 143 | const result = await s.detached(promptFile, { |
| 144 | data: { |
| 145 | taskId, |
| 146 | ...(parentId && { parentId }), |
| 147 | }, |
| 148 | logFile, |
| 149 | stream: true, |
| 150 | outputFormat: 'stream-json', |
| 151 | }); |
| 152 | |
| 153 | if (result.success) { |
| 154 | console.log(`${colors.green}✅ Task started successfully${colors.reset}`); |
| 155 | if (result.pid) { |
| 156 | console.log(` PID: ${result.pid}`); |
| 157 | |
| 158 | // Update session info with PID |
| 159 | const info = await loadSessionInfo(taskId); |
| 160 | if (info) { |
| 161 | info.pid = result.pid; |
| 162 | await fs.writeFile(getSessionInfoPath(sessionName), JSON.stringify(info, null, 2)); |
| 163 | } |
| 164 | } |
| 165 | console.log(` Monitor with: ${colors.cyan}monitor-auto${colors.reset}`); |
| 166 | console.log(` Continue with: ${colors.cyan}implement-auto --continue ${taskId}${colors.reset}`); |
| 167 | |
| 168 | return { success: true, taskId, parentId, sessionName, logFile }; |
| 169 | } else { |
| 170 | console.error(`${colors.red}❌ Failed to start task: ${result.error}${colors.reset}`); |
| 171 | return { success: false, taskId, parentId, error: result.error }; |
| 172 | } |
no test coverage detected
searching dependent graphs…