MCPcopy Create free account
hub / github.com/Noumena-Network/code / findHighestTaskIdFromFiles

Function findHighestTaskIdFromFiles

src/utils/tasks.ts:247–266  ·  view source on GitHub ↗

* Finds the highest task ID from existing task files (not including high water mark).

(taskListId: string)

Source from the content-addressed store, hash-verified

245 * Finds the highest task ID from existing task files (not including high water mark).
246 */
247async function findHighestTaskIdFromFiles(taskListId: string): Promise<number> {
248 const dir = getTasksDir(taskListId)
249 let files: string[]
250 try {
251 files = await readdir(dir)
252 } catch {
253 return 0
254 }
255 let highest = 0
256 for (const file of files) {
257 if (!file.endsWith('.json')) {
258 continue
259 }
260 const taskId = parseInt(file.replace('.json', ''), 10)
261 if (!isNaN(taskId) && taskId > highest) {
262 highest = taskId
263 }
264 }
265 return highest
266}
267
268/**
269 * Finds the highest task ID ever assigned, considering both existing files

Callers 2

resetTaskListFunction · 0.85
findHighestTaskIdFunction · 0.85

Calls 2

getTasksDirFunction · 0.85
readdirFunction · 0.85

Tested by

no test coverage detected