MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / readCronTasks

Function readCronTasks

source code/utils/cronTasks.ts:93–142  ·  view source on GitHub ↗
(dir?: string)

Source from the content-addressed store, hash-verified

91 * blocks the whole file.
92 */
93export async function readCronTasks(dir?: string): Promise<CronTask[]> {
94 const fs = getFsImplementation()
95 let raw: string
96 try {
97 raw = await fs.readFile(getCronFilePath(dir), { encoding: 'utf-8' })
98 } catch (e: unknown) {
99 if (isFsInaccessible(e)) return []
100 logError(e)
101 return []
102 }
103
104 const parsed = safeParseJSON(raw, false)
105 if (!parsed || typeof parsed !== 'object') return []
106 const file = parsed as Partial<CronFile>
107 if (!Array.isArray(file.tasks)) return []
108
109 const out: CronTask[] = []
110 for (const t of file.tasks) {
111 if (
112 !t ||
113 typeof t.id !== 'string' ||
114 typeof t.cron !== 'string' ||
115 typeof t.prompt !== 'string' ||
116 typeof t.createdAt !== 'number'
117 ) {
118 logForDebugging(
119 `[ScheduledTasks] skipping malformed task: ${jsonStringify(t)}`,
120 )
121 continue
122 }
123 if (!parseCronExpression(t.cron)) {
124 logForDebugging(
125 `[ScheduledTasks] skipping task ${t.id} with invalid cron '${t.cron}'`,
126 )
127 continue
128 }
129 out.push({
130 id: t.id,
131 cron: t.cron,
132 prompt: t.prompt,
133 createdAt: t.createdAt,
134 ...(typeof t.lastFiredAt === 'number'
135 ? { lastFiredAt: t.lastFiredAt }
136 : {}),
137 ...(t.recurring ? { recurring: true } : {}),
138 ...(t.permanent ? { permanent: true } : {}),
139 })
140 }
141 return out
142}
143
144/**
145 * Sync check for whether the cron file has any valid tasks. Used by

Callers 5

addCronTaskFunction · 0.85
removeCronTasksFunction · 0.85
markCronTasksFiredFunction · 0.85
listAllCronTasksFunction · 0.85
loadFunction · 0.85

Calls 8

getFsImplementationFunction · 0.85
getCronFilePathFunction · 0.85
isFsInaccessibleFunction · 0.85
logForDebuggingFunction · 0.85
jsonStringifyFunction · 0.85
parseCronExpressionFunction · 0.85
readFileMethod · 0.80
logErrorFunction · 0.70

Tested by

no test coverage detected