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

Method list

packages/agent-core/src/services/fs/fsService.ts:60–161  ·  view source on GitHub ↗
(sessionId: string, req: FsListRequest)

Source from the content-addressed store, hash-verified

58 }
59
60 async list(sessionId: string, req: FsListRequest): Promise<FsListResponse> {
61 const session = await this.sessions.get(sessionId);
62 const cwd = session.metadata.cwd;
63 const safe = await resolveSafePath(cwd, req.path);
64
65 let topStat: import('node:fs').Stats;
66 try {
67 topStat = await fs.stat(safe.absolute);
68 } catch (err) {
69 throw mapStatError(err, req.path);
70 }
71 if (!topStat.isDirectory()) {
72
73 throw new FsPathNotFoundError(req.path);
74 }
75
76 const realCwd = await fs.realpath(cwd);
77 const matcher = req.follow_gitignore ? await this.matcher(realCwd) : undefined;
78
79 const items: FsEntry[] = [];
80 const childrenByPath: Record<string, FsEntry[]> = {};
81 let truncated = false;
82
83 interface QueueEntry {
84 absPath: string;
85
86 relPath: string;
87 depthRemaining: number;
88 }
89 const queue: QueueEntry[] = [
90 {
91 absPath: safe.absolute,
92 relPath: safe.relative === '.' ? '' : safe.relative,
93 depthRemaining: req.depth,
94 },
95 ];
96
97 while (queue.length > 0) {
98 const entry = queue.shift()!;
99 let dirents: import('node:fs').Dirent[];
100 try {
101 dirents = await fs.readdir(entry.absPath, { withFileTypes: true });
102 } catch (err) {
103
104 if (entry.absPath === safe.absolute) {
105 throw mapStatError(err, req.path);
106 }
107 continue;
108 }
109
110 const visible: import('node:fs').Dirent[] = [];
111 for (const d of dirents) {
112 if (!req.show_hidden && isHidden(d.name)) continue;
113 const childRel = entry.relPath === '' ? d.name : `${entry.relPath}/${d.name}`;
114 if (matcher) {
115
116 const probe = d.isDirectory() ? `${childRel}/` : childRel;
117 if (matcher.ignores(probe)) continue;

Callers 1

listManyMethod · 0.95

Calls 11

matcherMethod · 0.95
resolveSafePathFunction · 0.90
mapStatErrorFunction · 0.85
isHiddenFunction · 0.85
sortDirentsFunction · 0.85
buildFsEntryFunction · 0.85
keysMethod · 0.80
matchesAnyGlobFunction · 0.70
getMethod · 0.65
statMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected