MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / splitPathsAndText

Function splitPathsAndText

src/utils/image-paths.ts:88–111  ·  view source on GitHub ↗
(text: string, cwd: string)

Source from the content-addressed store, hash-verified

86 * Pure.
87 */
88export function splitPathsAndText(text: string, cwd: string): { paths: FsPath[]; text: string } {
89 const paths: FsPath[] = [];
90 const seen = new Set<string>();
91 const rawPathTokens: string[] = [];
92 for (const m of text.matchAll(PATH_TOKEN_RE)) {
93 const tok = m[0]!;
94 if (!looksLikePathToken(tok)) continue;
95 const cleaned = tok.replace(/^['"]|['"]$/g, '');
96 const abs = resolvePath(cleaned, cwd);
97 if (seen.has(abs)) continue;
98 try {
99 const st = fsSync.statSync(abs);
100 const kind = st.isDirectory() ? 'dir' : st.isFile() ? 'file' : null;
101 if (!kind) continue;
102 seen.add(abs);
103 paths.push({ abs, kind, name: path.basename(abs) });
104 rawPathTokens.push(tok);
105 } catch { /* doesn't exist — not a path */ }
106 }
107 let remainder = text;
108 for (const t of rawPathTokens) remainder = remainder.replace(t, ' ');
109 remainder = remainder.replace(/\s+/g, ' ').trim();
110 return { paths, text: remainder };
111}
112
113/**
114 * Existing filesystem paths (files OR directories) referenced in `text`, resolved absolute.

Callers 3

findFsPathsFunction · 0.85
ChatInputFunction · 0.85

Calls 5

looksLikePathTokenFunction · 0.85
resolvePathFunction · 0.85
addMethod · 0.80
hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected