MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / describeWindowsProcess

Function describeWindowsProcess

src/mcp/process-identity.ts:65–89  ·  view source on GitHub ↗
(pid: number)

Source from the content-addressed store, hash-verified

63}
64
65async function describeWindowsProcess(pid: number): Promise<ProcessDescription> {
66 // Win32_Process has the command line; tasklist, the fallback when PowerShell
67 // can't run, has only the image name.
68 const script =
69 "$ErrorActionPreference = 'Stop'; [Console]::OutputEncoding = [Text.Encoding]::UTF8; " +
70 `$p = Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}'; ` +
71 'if ($p) { [Console]::Out.Write((ConvertTo-Json -Compress @{ name = $p.Name; commandLine = $p.CommandLine })) }';
72 const json = await query(windowsTool('WindowsPowerShell', 'v1.0', 'powershell.exe'),
73 ['-NoProfile', '-NonInteractive', '-NoLogo', '-Command', script]);
74 if (json?.trim()) {
75 try {
76 const found = JSON.parse(json) as { name?: unknown; commandLine?: unknown };
77 return {
78 name: typeof found.name === 'string' && found.name ? found.name : null,
79 commandLine: typeof found.commandLine === 'string' && found.commandLine.trim() ? found.commandLine : null,
80 };
81 } catch { /* fall back to tasklist */ }
82 }
83 const csv = await query(windowsTool('tasklist.exe'), ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH']);
84 for (const line of csv?.split(/\r?\n/) ?? []) {
85 const fields = /^"([^"]*)","(\d+)"/.exec(line);
86 if (fields && Number(fields[2]) === pid) return { name: fields[1] || null, commandLine: null };
87 }
88 return { name: null, commandLine: null };
89}
90
91function describeLinuxProcess(pid: number): ProcessDescription {
92 let commandLine: string | null = null;

Callers 1

describeProcessFunction · 0.85

Calls 5

windowsToolFunction · 0.85
NumberInterface · 0.85
parseMethod · 0.80
queryFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected