(taskId: string, core?: Core | TaskPathContext)
| 146 | * For numeric-only IDs, automatically detects the prefix from existing files. |
| 147 | */ |
| 148 | export async function getTaskPath(taskId: string, core?: Core | TaskPathContext): Promise<string | null> { |
| 149 | const coreInstance = core || new Core(process.cwd()); |
| 150 | |
| 151 | // Extract prefix from the taskId |
| 152 | const detectedPrefix = extractAnyPrefix(taskId); |
| 153 | |
| 154 | // If prefix is detected, search only for that prefix |
| 155 | if (detectedPrefix) { |
| 156 | const globPattern = buildGlobPattern(detectedPrefix); |
| 157 | try { |
| 158 | const files = await Array.fromAsync( |
| 159 | new Bun.Glob(globPattern).scan({ cwd: coreInstance.filesystem.tasksDir, followSymlinks: true }), |
| 160 | ); |
| 161 | const taskFile = findMatchingFile(files, taskId, detectedPrefix); |
| 162 | if (taskFile) { |
| 163 | return join(coreInstance.filesystem.tasksDir, taskFile); |
| 164 | } |
| 165 | } catch { |
| 166 | // Fall through to return null |
| 167 | } |
| 168 | return null; |
| 169 | } |
| 170 | |
| 171 | // For numeric-only IDs, scan all .md files and find one matching the number |
| 172 | try { |
| 173 | const allFiles = await Array.fromAsync( |
| 174 | new Bun.Glob("*.md").scan({ cwd: coreInstance.filesystem.tasksDir, followSymlinks: true }), |
| 175 | ); |
| 176 | |
| 177 | // Look for a file matching this numeric ID with any prefix |
| 178 | // Pattern: <prefix>-<number> - <title>.md (e.g., "back-358 - Title.md") |
| 179 | const numericPart = taskId.trim(); |
| 180 | for (const file of allFiles) { |
| 181 | // Extract prefix from filename and check if numeric part matches |
| 182 | const filePrefix = extractAnyPrefix(file); |
| 183 | if (filePrefix) { |
| 184 | const fileBody = extractTaskBodyFromFilename(file, filePrefix); |
| 185 | if (fileBody && numericPartsEqual(numericPart, fileBody)) { |
| 186 | return join(coreInstance.filesystem.tasksDir, file); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | return null; |
| 192 | } catch { |
| 193 | return null; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Helper to find a matching file from a list of files |
no test coverage detected