File size: 1,168 Bytes
7c5ed63 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import { Hono } from 'hono';
import { KIMI_CODE_HOME } from '../config';
import type { CronTask } from '../lib/agent-record-types';
import { readSessionDetail } from '../lib/session-store';
import { listCronTasks } from '../lib/cron-store';
export function cronRoute(home: string = KIMI_CODE_HOME): Hono {
const r = new Hono();
r.get('/:id/cron', async (c) => {
const id = c.req.param('id');
const detail = await readSessionDetail(home, id);
if (!detail) {
return c.json({ error: 'session not found', code: 'NOT_FOUND' }, 404);
}
// Cron state is per-agent (wire records in each agent's `wire.jsonl`,
// plus legacy `<homedir>/cron/*.json` files), not the session root.
// Aggregate across agents; sub agents simply contribute nothing.
const cron: CronTask[] = [];
const seen = new Set<string>();
for (const agent of detail.agents) {
for (const job of await listCronTasks(agent.homedir)) {
if (seen.has(job.id)) continue;
seen.add(job.id);
cron.push(job);
}
}
cron.sort((a, b) => a.createdAt - b.createdAt);
return c.json({ sessionId: id, cron });
});
return r;
}
|