MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / listCronTasks

Function listCronTasks

apps/vis/server/src/lib/cron-store.ts:33–56  ·  view source on GitHub ↗
(agentDir: string)

Source from the content-addressed store, hash-verified

31 * to read/parse, and records missing the required cron fields.
32 */
33export async function listCronTasks(agentDir: string): Promise<CronTask[]> {
34 const dir = cronDirOf(agentDir);
35 let entries: import('node:fs').Dirent[];
36 try {
37 entries = await readdir(dir, { withFileTypes: true });
38 } catch {
39 return [];
40 }
41 const out: CronTask[] = [];
42 for (const entry of entries) {
43 if (!entry.isFile() || !entry.name.endsWith('.json')) continue;
44 const id = entry.name.slice(0, -'.json'.length);
45 if (!VALID_CRON_ID.test(id)) continue;
46 let parsed: unknown;
47 try {
48 parsed = JSON.parse(await readFile(join(dir, entry.name), 'utf8'));
49 } catch {
50 continue;
51 }
52 if (isCronTask(parsed)) out.push(parsed);
53 }
54 out.sort((a, b) => a.createdAt - b.createdAt);
55 return out;
56}
57
58function isCronTask(value: unknown): value is CronTask {
59 if (typeof value !== 'object' || value === null) return false;

Callers 2

cron-store.test.tsFile · 0.90
cronRouteFunction · 0.90

Calls 5

cronDirOfFunction · 0.85
isCronTaskFunction · 0.85
readdirFunction · 0.50
readFileFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected