forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-tools-context.ts
More file actions
37 lines (32 loc) · 1.34 KB
/
cli-tools-context.ts
File metadata and controls
37 lines (32 loc) · 1.34 KB
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
34
35
36
37
import { detectAllCliTools } from './cli-tools-detect';
import { CLI_TOOLS_CATALOG, EXTRA_WELL_KNOWN_BINS } from './cli-tools-catalog';
/**
* Build a concise CLI tools context block for chat system prompt injection.
* Includes both catalog tools and extra well-known binaries detected on the system.
* Returns null if no tools are installed.
*/
export async function buildCliToolsContext(): Promise<string | null> {
try {
const { catalog, extra } = await detectAllCliTools();
const catalogLines = catalog
.filter(t => t.status === 'installed')
.map(t => {
const def = CLI_TOOLS_CATALOG.find(c => c.id === t.id);
if (!def) return null;
const ver = t.version ? ` (v${t.version})` : '';
return `- ${def.name}${ver}: ${def.summaryEn}`;
})
.filter(Boolean);
const extraLines = extra.map(t => {
const entry = EXTRA_WELL_KNOWN_BINS.find(([eid]) => eid === t.id);
const name = entry?.[1] ?? t.id;
const ver = t.version ? ` (v${t.version})` : '';
return `- ${name}${ver}`;
});
const allLines = [...catalogLines, ...extraLines];
if (allLines.length === 0) return null;
return `<available_cli_tools>\nThe following CLI tools are installed on this system and available for use:\n${allLines.join('\n')}\n</available_cli_tools>`;
} catch {
return null;
}
}