MCPcopy Index your code
hub / github.com/MrLesk/Backlog.md / getTaskPath

Function getTaskPath

src/utils/task-path.ts:148–195  ·  view source on GitHub ↗
(taskId: string, core?: Core | TaskPathContext)

Source from the content-addressed store, hash-verified

146 * For numeric-only IDs, automatically detects the prefix from existing files.
147 */
148export 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

Callers 12

getTaskContentMethod · 0.90
updateTaskMethod · 0.90
archiveTaskMethod · 0.90
completeTaskMethod · 0.90
listTasksWithMetadataMethod · 0.90
editTaskInTuiMethod · 0.90
task-path.test.tsFile · 0.90
saveTaskMethod · 0.90
loadTaskMethod · 0.90
archiveTaskMethod · 0.90
completeTaskMethod · 0.90
taskFileExistsFunction · 0.85

Calls 5

extractAnyPrefixFunction · 0.90
buildGlobPatternFunction · 0.90
findMatchingFileFunction · 0.85
numericPartsEqualFunction · 0.85

Tested by

no test coverage detected