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

Function discoverLogFiles

apps/vis/server/src/lib/log-reader.ts:38–66  ·  view source on GitHub ↗
(baseLogPath: string)

Source from the content-addressed store, hash-verified

36 * away may contain only `<base>.1`, etc. — which the Logs tab must still find.
37 */
38export async function discoverLogFiles(baseLogPath: string): Promise<string[]> {
39 const dir = dirname(baseLogPath);
40 const base = basename(baseLogPath);
41 let names: string[];
42 try {
43 names = (await readdir(dir, { withFileTypes: true }))
44 .filter((e) => e.isFile())
45 .map((e) => e.name);
46 } catch {
47 return [];
48 }
49 let hasActive = false;
50 const rotated: { n: number; name: string }[] = [];
51 const prefix = `${base}.`;
52 for (const name of names) {
53 if (name === base) {
54 hasActive = true;
55 continue;
56 }
57 if (name.startsWith(prefix)) {
58 const suffix = name.slice(prefix.length);
59 if (/^\d+$/.test(suffix)) rotated.push({ n: Number(suffix), name });
60 }
61 }
62 rotated.sort((a, b) => b.n - a.n); // highest index == oldest → first
63 const ordered = rotated.map((r) => join(dir, r.name));
64 if (hasActive) ordered.push(join(dir, base)); // active is newest → last
65 return ordered;
66}
67
68/**
69 * Read and parse the given log files in order, concatenated into one structured

Callers 1

logsRouteFunction · 0.90

Calls 3

basenameFunction · 0.85
readdirFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected