@memoraone/mcp 0.1.66 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.cjs CHANGED
@@ -232,6 +232,7 @@ function formatMissingInitializeWorkspaceError(options) {
232
232
 
233
233
  // src/socketPaths.ts
234
234
  var BASE_DIR = process.env.MEMORAONE_MCP_LOCK_DIR || path4.join(os2.homedir(), ".memoraone-mcp");
235
+ var WINDOWS_PIPE_PREFIX = "\\\\.\\pipe\\memoraone-";
235
236
  var HASH_SOCKET_FILENAME_RE = new RegExp(
236
237
  `^mcp-[0-9a-f]{${BINDING_SOCKET_HASH_LENGTH}}\\.sock$`,
237
238
  "i"
@@ -316,6 +317,10 @@ function getBindingSocketFilename(binding, env2 = process.env, ideTypeOverride)
316
317
  return `mcp-${hash}.sock`;
317
318
  }
318
319
  function getBindingSocketPath(binding, env2 = process.env, ideTypeOverride) {
320
+ if (process.platform === "win32") {
321
+ const filename = getBindingSocketFilename(binding, env2, ideTypeOverride);
322
+ return `${WINDOWS_PIPE_PREFIX}${filename.slice(0, -".sock".length)}`;
323
+ }
319
324
  return path4.join(BASE_DIR, getBindingSocketFilename(binding, env2, ideTypeOverride));
320
325
  }
321
326
  function ensureBaseDir() {
@@ -805,12 +810,18 @@ async function readLinuxDeviceId() {
805
810
  throw new Error("[memoraone-mcp] Unable to read Linux machine-id");
806
811
  }
807
812
  async function readWindowsDeviceId() {
808
- const { stdout } = await execFileAsync("reg", [
809
- "query",
810
- "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
811
- "/v",
812
- "MachineGuid"
813
- ]);
813
+ const { stdout } = await execFileAsync(
814
+ "reg",
815
+ [
816
+ "query",
817
+ "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
818
+ "/v",
819
+ "MachineGuid"
820
+ ],
821
+ {
822
+ windowsHide: true
823
+ }
824
+ );
814
825
  const match = stdout.match(/MachineGuid\s+REG_SZ\s+(.+)/i);
815
826
  if (!match?.[1]) {
816
827
  throw new Error("[memoraone-mcp] Unable to read Windows MachineGuid");
@@ -4137,35 +4148,74 @@ var WINDOWS_LIST_PROCESSES_PS = [
4137
4148
  " [Console]::Error.WriteLine([string]$_)",
4138
4149
  " exit 1",
4139
4150
  "}",
4140
- "$currentIdentity = [string][System.Security.Principal.WindowsIdentity]::GetCurrent().Name",
4141
- "if ([string]::IsNullOrWhiteSpace($currentIdentity)) {",
4142
- ' throw "Unable to determine the current Windows identity."',
4151
+ "$currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()",
4152
+ "$currentUserSid = [string]$currentIdentity.User.Value",
4153
+ "if ([string]::IsNullOrWhiteSpace($currentUserSid)) {",
4154
+ ' throw "Unable to determine the current Windows identity SID."',
4143
4155
  "}",
4144
- "$systemDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)",
4145
- "if ([string]::IsNullOrWhiteSpace($systemDirectory)) {",
4146
- ' throw "Unable to determine the Windows system directory."',
4147
- "}",
4148
- '$tasklistPath = [System.IO.Path]::Combine($systemDirectory, "tasklist.exe")',
4149
- '$tasklistArgs = @("/FI", "USERNAME eq $currentIdentity", "/FO", "CSV", "/NH")',
4150
- "$tasklistRows = @(& $tasklistPath $tasklistArgs)",
4151
- "$tasklistExitCode = $LASTEXITCODE",
4152
- "if ($tasklistExitCode -ne 0) {",
4153
- ' throw "tasklist.exe failed with exit code $tasklistExitCode."',
4156
+ "$ownerLookupSource = @'",
4157
+ "using System;",
4158
+ "using System.Collections.Generic;",
4159
+ "using System.Runtime.InteropServices;",
4160
+ "using System.Security.Principal;",
4161
+ "",
4162
+ "public static class MemoraOneProcessOwner {",
4163
+ " private const uint ProcessQueryLimitedInformation = 0x1000;",
4164
+ " private const uint TokenQuery = 0x0008;",
4165
+ " private const int TokenUser = 1;",
4166
+ "",
4167
+ ' [DllImport("kernel32.dll", SetLastError = true)]',
4168
+ " private static extern IntPtr OpenProcess(uint access, bool inheritHandle, int processId);",
4169
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
4170
+ " private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);",
4171
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
4172
+ " private static extern bool GetTokenInformation(IntPtr tokenHandle, int tokenInformationClass, IntPtr tokenInformation, int tokenInformationLength, out int returnLength);",
4173
+ ' [DllImport("kernel32.dll")]',
4174
+ " private static extern bool CloseHandle(IntPtr handle);",
4175
+ "",
4176
+ " public static int[] OwnedProcessIds(int[] processIds, string currentSid) {",
4177
+ " var expectedSid = new SecurityIdentifier(currentSid);",
4178
+ " var owned = new List<int>();",
4179
+ " foreach (int processId in processIds) {",
4180
+ " IntPtr processHandle = OpenProcess(ProcessQueryLimitedInformation, false, processId);",
4181
+ " if (processHandle == IntPtr.Zero) continue;",
4182
+ " try {",
4183
+ " IntPtr tokenHandle;",
4184
+ " if (!OpenProcessToken(processHandle, TokenQuery, out tokenHandle)) continue;",
4185
+ " try {",
4186
+ " int tokenLength;",
4187
+ " GetTokenInformation(tokenHandle, TokenUser, IntPtr.Zero, 0, out tokenLength);",
4188
+ " if (tokenLength <= 0) continue;",
4189
+ " IntPtr tokenBuffer = Marshal.AllocHGlobal(tokenLength);",
4190
+ " try {",
4191
+ " if (!GetTokenInformation(tokenHandle, TokenUser, tokenBuffer, tokenLength, out tokenLength)) continue;",
4192
+ " IntPtr sidPointer = Marshal.ReadIntPtr(tokenBuffer);",
4193
+ " if (expectedSid.Equals(new SecurityIdentifier(sidPointer))) owned.Add(processId);",
4194
+ " } finally {",
4195
+ " Marshal.FreeHGlobal(tokenBuffer);",
4196
+ " }",
4197
+ " } finally {",
4198
+ " CloseHandle(tokenHandle);",
4199
+ " }",
4200
+ " } finally {",
4201
+ " CloseHandle(processHandle);",
4202
+ " }",
4203
+ " }",
4204
+ " return owned.ToArray();",
4205
+ " }",
4154
4206
  "}",
4207
+ "'@",
4208
+ "Add-Type -TypeDefinition $ownerLookupSource -Language CSharp",
4209
+ "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
4210
+ "$processIds = [int[]]@($processes | ForEach-Object { [int]$_.ProcessId })",
4211
+ "$ownedProcessIds = [MemoraOneProcessOwner]::OwnedProcessIds($processIds, $currentUserSid)",
4155
4212
  '$currentUserPids = New-Object "System.Collections.Generic.HashSet[int]"',
4156
- "foreach ($tasklistRow in $tasklistRows) {",
4157
- " if ([string]::IsNullOrWhiteSpace([string]$tasklistRow)) { continue }",
4158
- ' $task = $tasklistRow | ConvertFrom-Csv -Header "ImageName","ProcessId","SessionName","SessionNumber","MemoryUsage"',
4159
- " $taskPid = 0",
4160
- " if ($null -eq $task -or -not [int]::TryParse([string]$task.ProcessId, [ref]$taskPid) -or $taskPid -le 0) {",
4161
- ' throw "tasklist.exe returned an invalid process row."',
4162
- " }",
4163
- " $null = $currentUserPids.Add($taskPid)",
4213
+ "foreach ($ownedProcessId in $ownedProcessIds) {",
4214
+ " $null = $currentUserPids.Add([int]$ownedProcessId)",
4164
4215
  "}",
4165
4216
  "if (-not $currentUserPids.Contains([int]$PID)) {",
4166
- ' throw "tasklist.exe results did not include the running PowerShell process."',
4217
+ ' throw "Process token results did not include the running PowerShell process."',
4167
4218
  "}",
4168
- "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
4169
4219
  "foreach ($proc in $processes) {",
4170
4220
  " if ($null -eq $proc.ProcessId) { continue }",
4171
4221
  " $procId = [int]$proc.ProcessId",
@@ -4252,7 +4302,8 @@ async function listProcessCommandLineRows(deps = {}) {
4252
4302
  const { file, args } = windowsProcessListInvocation();
4253
4303
  const { stdout: stdout2 } = await execFileImpl(file, args, {
4254
4304
  maxBuffer: PROCESS_LIST_MAX_BUFFER,
4255
- timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS
4305
+ timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS,
4306
+ windowsHide: true
4256
4307
  });
4257
4308
  return parseWindowsProcessJsonLines(stdoutToString(stdout2));
4258
4309
  }
package/dist/gateway.cjs CHANGED
@@ -89,6 +89,7 @@ function formatMissingInitializeWorkspaceError(options) {
89
89
 
90
90
  // src/socketPaths.ts
91
91
  var BASE_DIR = process.env.MEMORAONE_MCP_LOCK_DIR || path2.join(os.homedir(), ".memoraone-mcp");
92
+ var WINDOWS_PIPE_PREFIX = "\\\\.\\pipe\\memoraone-";
92
93
  var HASH_SOCKET_FILENAME_RE = new RegExp(
93
94
  `^mcp-[0-9a-f]{${BINDING_SOCKET_HASH_LENGTH}}\\.sock$`,
94
95
  "i"
@@ -166,6 +167,10 @@ function getBindingSocketFilename(binding, env2 = process.env, ideTypeOverride)
166
167
  return `mcp-${hash}.sock`;
167
168
  }
168
169
  function getBindingSocketPath(binding, env2 = process.env, ideTypeOverride) {
170
+ if (process.platform === "win32") {
171
+ const filename = getBindingSocketFilename(binding, env2, ideTypeOverride);
172
+ return `${WINDOWS_PIPE_PREFIX}${filename.slice(0, -".sock".length)}`;
173
+ }
169
174
  return path2.join(BASE_DIR, getBindingSocketFilename(binding, env2, ideTypeOverride));
170
175
  }
171
176
  function ensureBaseDir() {
@@ -1103,12 +1108,18 @@ async function readLinuxDeviceId() {
1103
1108
  throw new Error("[memoraone-mcp] Unable to read Linux machine-id");
1104
1109
  }
1105
1110
  async function readWindowsDeviceId() {
1106
- const { stdout } = await execFileAsync("reg", [
1107
- "query",
1108
- "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
1109
- "/v",
1110
- "MachineGuid"
1111
- ]);
1111
+ const { stdout } = await execFileAsync(
1112
+ "reg",
1113
+ [
1114
+ "query",
1115
+ "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
1116
+ "/v",
1117
+ "MachineGuid"
1118
+ ],
1119
+ {
1120
+ windowsHide: true
1121
+ }
1122
+ );
1112
1123
  const match = stdout.match(/MachineGuid\s+REG_SZ\s+(.+)/i);
1113
1124
  if (!match?.[1]) {
1114
1125
  throw new Error("[memoraone-mcp] Unable to read Windows MachineGuid");
@@ -1887,10 +1898,11 @@ async function parseGatewayWorkspaceRoot(wsRaw) {
1887
1898
  if (trimmed.includes("\0")) {
1888
1899
  return fail("malformed_ws", "ws query parameter is malformed");
1889
1900
  }
1890
- if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)) {
1901
+ const isAbsoluteFilesystemPath = path12.isAbsolute(trimmed);
1902
+ if (!isAbsoluteFilesystemPath && /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)) {
1891
1903
  return fail("malformed_ws", "ws must be an absolute filesystem path");
1892
1904
  }
1893
- if (!path12.isAbsolute(trimmed)) {
1905
+ if (!isAbsoluteFilesystemPath) {
1894
1906
  return fail("non_absolute", "ws must be an absolute workspace root");
1895
1907
  }
1896
1908
  const workspaceRoot = path12.resolve(trimmed);
@@ -3401,35 +3413,74 @@ var WINDOWS_LIST_PROCESSES_PS = [
3401
3413
  " [Console]::Error.WriteLine([string]$_)",
3402
3414
  " exit 1",
3403
3415
  "}",
3404
- "$currentIdentity = [string][System.Security.Principal.WindowsIdentity]::GetCurrent().Name",
3405
- "if ([string]::IsNullOrWhiteSpace($currentIdentity)) {",
3406
- ' throw "Unable to determine the current Windows identity."',
3416
+ "$currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()",
3417
+ "$currentUserSid = [string]$currentIdentity.User.Value",
3418
+ "if ([string]::IsNullOrWhiteSpace($currentUserSid)) {",
3419
+ ' throw "Unable to determine the current Windows identity SID."',
3407
3420
  "}",
3408
- "$systemDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)",
3409
- "if ([string]::IsNullOrWhiteSpace($systemDirectory)) {",
3410
- ' throw "Unable to determine the Windows system directory."',
3411
- "}",
3412
- '$tasklistPath = [System.IO.Path]::Combine($systemDirectory, "tasklist.exe")',
3413
- '$tasklistArgs = @("/FI", "USERNAME eq $currentIdentity", "/FO", "CSV", "/NH")',
3414
- "$tasklistRows = @(& $tasklistPath $tasklistArgs)",
3415
- "$tasklistExitCode = $LASTEXITCODE",
3416
- "if ($tasklistExitCode -ne 0) {",
3417
- ' throw "tasklist.exe failed with exit code $tasklistExitCode."',
3421
+ "$ownerLookupSource = @'",
3422
+ "using System;",
3423
+ "using System.Collections.Generic;",
3424
+ "using System.Runtime.InteropServices;",
3425
+ "using System.Security.Principal;",
3426
+ "",
3427
+ "public static class MemoraOneProcessOwner {",
3428
+ " private const uint ProcessQueryLimitedInformation = 0x1000;",
3429
+ " private const uint TokenQuery = 0x0008;",
3430
+ " private const int TokenUser = 1;",
3431
+ "",
3432
+ ' [DllImport("kernel32.dll", SetLastError = true)]',
3433
+ " private static extern IntPtr OpenProcess(uint access, bool inheritHandle, int processId);",
3434
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
3435
+ " private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);",
3436
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
3437
+ " private static extern bool GetTokenInformation(IntPtr tokenHandle, int tokenInformationClass, IntPtr tokenInformation, int tokenInformationLength, out int returnLength);",
3438
+ ' [DllImport("kernel32.dll")]',
3439
+ " private static extern bool CloseHandle(IntPtr handle);",
3440
+ "",
3441
+ " public static int[] OwnedProcessIds(int[] processIds, string currentSid) {",
3442
+ " var expectedSid = new SecurityIdentifier(currentSid);",
3443
+ " var owned = new List<int>();",
3444
+ " foreach (int processId in processIds) {",
3445
+ " IntPtr processHandle = OpenProcess(ProcessQueryLimitedInformation, false, processId);",
3446
+ " if (processHandle == IntPtr.Zero) continue;",
3447
+ " try {",
3448
+ " IntPtr tokenHandle;",
3449
+ " if (!OpenProcessToken(processHandle, TokenQuery, out tokenHandle)) continue;",
3450
+ " try {",
3451
+ " int tokenLength;",
3452
+ " GetTokenInformation(tokenHandle, TokenUser, IntPtr.Zero, 0, out tokenLength);",
3453
+ " if (tokenLength <= 0) continue;",
3454
+ " IntPtr tokenBuffer = Marshal.AllocHGlobal(tokenLength);",
3455
+ " try {",
3456
+ " if (!GetTokenInformation(tokenHandle, TokenUser, tokenBuffer, tokenLength, out tokenLength)) continue;",
3457
+ " IntPtr sidPointer = Marshal.ReadIntPtr(tokenBuffer);",
3458
+ " if (expectedSid.Equals(new SecurityIdentifier(sidPointer))) owned.Add(processId);",
3459
+ " } finally {",
3460
+ " Marshal.FreeHGlobal(tokenBuffer);",
3461
+ " }",
3462
+ " } finally {",
3463
+ " CloseHandle(tokenHandle);",
3464
+ " }",
3465
+ " } finally {",
3466
+ " CloseHandle(processHandle);",
3467
+ " }",
3468
+ " }",
3469
+ " return owned.ToArray();",
3470
+ " }",
3418
3471
  "}",
3472
+ "'@",
3473
+ "Add-Type -TypeDefinition $ownerLookupSource -Language CSharp",
3474
+ "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
3475
+ "$processIds = [int[]]@($processes | ForEach-Object { [int]$_.ProcessId })",
3476
+ "$ownedProcessIds = [MemoraOneProcessOwner]::OwnedProcessIds($processIds, $currentUserSid)",
3419
3477
  '$currentUserPids = New-Object "System.Collections.Generic.HashSet[int]"',
3420
- "foreach ($tasklistRow in $tasklistRows) {",
3421
- " if ([string]::IsNullOrWhiteSpace([string]$tasklistRow)) { continue }",
3422
- ' $task = $tasklistRow | ConvertFrom-Csv -Header "ImageName","ProcessId","SessionName","SessionNumber","MemoryUsage"',
3423
- " $taskPid = 0",
3424
- " if ($null -eq $task -or -not [int]::TryParse([string]$task.ProcessId, [ref]$taskPid) -or $taskPid -le 0) {",
3425
- ' throw "tasklist.exe returned an invalid process row."',
3426
- " }",
3427
- " $null = $currentUserPids.Add($taskPid)",
3478
+ "foreach ($ownedProcessId in $ownedProcessIds) {",
3479
+ " $null = $currentUserPids.Add([int]$ownedProcessId)",
3428
3480
  "}",
3429
3481
  "if (-not $currentUserPids.Contains([int]$PID)) {",
3430
- ' throw "tasklist.exe results did not include the running PowerShell process."',
3482
+ ' throw "Process token results did not include the running PowerShell process."',
3431
3483
  "}",
3432
- "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
3433
3484
  "foreach ($proc in $processes) {",
3434
3485
  " if ($null -eq $proc.ProcessId) { continue }",
3435
3486
  " $procId = [int]$proc.ProcessId",
@@ -3516,7 +3567,8 @@ async function listProcessCommandLineRows(deps = {}) {
3516
3567
  const { file, args } = windowsProcessListInvocation();
3517
3568
  const { stdout: stdout2 } = await execFileImpl(file, args, {
3518
3569
  maxBuffer: PROCESS_LIST_MAX_BUFFER,
3519
- timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS
3570
+ timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS,
3571
+ windowsHide: true
3520
3572
  });
3521
3573
  return parseWindowsProcessJsonLines(stdoutToString(stdout2));
3522
3574
  }
package/dist/index.cjs CHANGED
@@ -110,6 +110,7 @@ function formatMissingInitializeWorkspaceError(options) {
110
110
 
111
111
  // src/socketPaths.ts
112
112
  var BASE_DIR = process.env.MEMORAONE_MCP_LOCK_DIR || path2.join(os.homedir(), ".memoraone-mcp");
113
+ var WINDOWS_PIPE_PREFIX = "\\\\.\\pipe\\memoraone-";
113
114
  var HASH_SOCKET_FILENAME_RE = new RegExp(
114
115
  `^mcp-[0-9a-f]{${BINDING_SOCKET_HASH_LENGTH}}\\.sock$`,
115
116
  "i"
@@ -187,6 +188,10 @@ function getBindingSocketFilename(binding, env2 = process.env, ideTypeOverride)
187
188
  return `mcp-${hash}.sock`;
188
189
  }
189
190
  function getBindingSocketPath(binding, env2 = process.env, ideTypeOverride) {
191
+ if (process.platform === "win32") {
192
+ const filename = getBindingSocketFilename(binding, env2, ideTypeOverride);
193
+ return `${WINDOWS_PIPE_PREFIX}${filename.slice(0, -".sock".length)}`;
194
+ }
190
195
  return path2.join(BASE_DIR, getBindingSocketFilename(binding, env2, ideTypeOverride));
191
196
  }
192
197
  function isHashSocketFilename(filename) {
@@ -1301,12 +1306,18 @@ async function readLinuxDeviceId() {
1301
1306
  throw new Error("[memoraone-mcp] Unable to read Linux machine-id");
1302
1307
  }
1303
1308
  async function readWindowsDeviceId() {
1304
- const { stdout } = await execFileAsync("reg", [
1305
- "query",
1306
- "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
1307
- "/v",
1308
- "MachineGuid"
1309
- ]);
1309
+ const { stdout } = await execFileAsync(
1310
+ "reg",
1311
+ [
1312
+ "query",
1313
+ "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
1314
+ "/v",
1315
+ "MachineGuid"
1316
+ ],
1317
+ {
1318
+ windowsHide: true
1319
+ }
1320
+ );
1310
1321
  const match = stdout.match(/MachineGuid\s+REG_SZ\s+(.+)/i);
1311
1322
  if (!match?.[1]) {
1312
1323
  throw new Error("[memoraone-mcp] Unable to read Windows MachineGuid");
@@ -4120,35 +4131,74 @@ var WINDOWS_LIST_PROCESSES_PS = [
4120
4131
  " [Console]::Error.WriteLine([string]$_)",
4121
4132
  " exit 1",
4122
4133
  "}",
4123
- "$currentIdentity = [string][System.Security.Principal.WindowsIdentity]::GetCurrent().Name",
4124
- "if ([string]::IsNullOrWhiteSpace($currentIdentity)) {",
4125
- ' throw "Unable to determine the current Windows identity."',
4134
+ "$currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()",
4135
+ "$currentUserSid = [string]$currentIdentity.User.Value",
4136
+ "if ([string]::IsNullOrWhiteSpace($currentUserSid)) {",
4137
+ ' throw "Unable to determine the current Windows identity SID."',
4126
4138
  "}",
4127
- "$systemDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)",
4128
- "if ([string]::IsNullOrWhiteSpace($systemDirectory)) {",
4129
- ' throw "Unable to determine the Windows system directory."',
4130
- "}",
4131
- '$tasklistPath = [System.IO.Path]::Combine($systemDirectory, "tasklist.exe")',
4132
- '$tasklistArgs = @("/FI", "USERNAME eq $currentIdentity", "/FO", "CSV", "/NH")',
4133
- "$tasklistRows = @(& $tasklistPath $tasklistArgs)",
4134
- "$tasklistExitCode = $LASTEXITCODE",
4135
- "if ($tasklistExitCode -ne 0) {",
4136
- ' throw "tasklist.exe failed with exit code $tasklistExitCode."',
4139
+ "$ownerLookupSource = @'",
4140
+ "using System;",
4141
+ "using System.Collections.Generic;",
4142
+ "using System.Runtime.InteropServices;",
4143
+ "using System.Security.Principal;",
4144
+ "",
4145
+ "public static class MemoraOneProcessOwner {",
4146
+ " private const uint ProcessQueryLimitedInformation = 0x1000;",
4147
+ " private const uint TokenQuery = 0x0008;",
4148
+ " private const int TokenUser = 1;",
4149
+ "",
4150
+ ' [DllImport("kernel32.dll", SetLastError = true)]',
4151
+ " private static extern IntPtr OpenProcess(uint access, bool inheritHandle, int processId);",
4152
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
4153
+ " private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);",
4154
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
4155
+ " private static extern bool GetTokenInformation(IntPtr tokenHandle, int tokenInformationClass, IntPtr tokenInformation, int tokenInformationLength, out int returnLength);",
4156
+ ' [DllImport("kernel32.dll")]',
4157
+ " private static extern bool CloseHandle(IntPtr handle);",
4158
+ "",
4159
+ " public static int[] OwnedProcessIds(int[] processIds, string currentSid) {",
4160
+ " var expectedSid = new SecurityIdentifier(currentSid);",
4161
+ " var owned = new List<int>();",
4162
+ " foreach (int processId in processIds) {",
4163
+ " IntPtr processHandle = OpenProcess(ProcessQueryLimitedInformation, false, processId);",
4164
+ " if (processHandle == IntPtr.Zero) continue;",
4165
+ " try {",
4166
+ " IntPtr tokenHandle;",
4167
+ " if (!OpenProcessToken(processHandle, TokenQuery, out tokenHandle)) continue;",
4168
+ " try {",
4169
+ " int tokenLength;",
4170
+ " GetTokenInformation(tokenHandle, TokenUser, IntPtr.Zero, 0, out tokenLength);",
4171
+ " if (tokenLength <= 0) continue;",
4172
+ " IntPtr tokenBuffer = Marshal.AllocHGlobal(tokenLength);",
4173
+ " try {",
4174
+ " if (!GetTokenInformation(tokenHandle, TokenUser, tokenBuffer, tokenLength, out tokenLength)) continue;",
4175
+ " IntPtr sidPointer = Marshal.ReadIntPtr(tokenBuffer);",
4176
+ " if (expectedSid.Equals(new SecurityIdentifier(sidPointer))) owned.Add(processId);",
4177
+ " } finally {",
4178
+ " Marshal.FreeHGlobal(tokenBuffer);",
4179
+ " }",
4180
+ " } finally {",
4181
+ " CloseHandle(tokenHandle);",
4182
+ " }",
4183
+ " } finally {",
4184
+ " CloseHandle(processHandle);",
4185
+ " }",
4186
+ " }",
4187
+ " return owned.ToArray();",
4188
+ " }",
4137
4189
  "}",
4190
+ "'@",
4191
+ "Add-Type -TypeDefinition $ownerLookupSource -Language CSharp",
4192
+ "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
4193
+ "$processIds = [int[]]@($processes | ForEach-Object { [int]$_.ProcessId })",
4194
+ "$ownedProcessIds = [MemoraOneProcessOwner]::OwnedProcessIds($processIds, $currentUserSid)",
4138
4195
  '$currentUserPids = New-Object "System.Collections.Generic.HashSet[int]"',
4139
- "foreach ($tasklistRow in $tasklistRows) {",
4140
- " if ([string]::IsNullOrWhiteSpace([string]$tasklistRow)) { continue }",
4141
- ' $task = $tasklistRow | ConvertFrom-Csv -Header "ImageName","ProcessId","SessionName","SessionNumber","MemoryUsage"',
4142
- " $taskPid = 0",
4143
- " if ($null -eq $task -or -not [int]::TryParse([string]$task.ProcessId, [ref]$taskPid) -or $taskPid -le 0) {",
4144
- ' throw "tasklist.exe returned an invalid process row."',
4145
- " }",
4146
- " $null = $currentUserPids.Add($taskPid)",
4196
+ "foreach ($ownedProcessId in $ownedProcessIds) {",
4197
+ " $null = $currentUserPids.Add([int]$ownedProcessId)",
4147
4198
  "}",
4148
4199
  "if (-not $currentUserPids.Contains([int]$PID)) {",
4149
- ' throw "tasklist.exe results did not include the running PowerShell process."',
4200
+ ' throw "Process token results did not include the running PowerShell process."',
4150
4201
  "}",
4151
- "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
4152
4202
  "foreach ($proc in $processes) {",
4153
4203
  " if ($null -eq $proc.ProcessId) { continue }",
4154
4204
  " $procId = [int]$proc.ProcessId",
@@ -4235,7 +4285,8 @@ async function listProcessCommandLineRows(deps = {}) {
4235
4285
  const { file, args } = windowsProcessListInvocation();
4236
4286
  const { stdout: stdout2 } = await execFileImpl(file, args, {
4237
4287
  maxBuffer: PROCESS_LIST_MAX_BUFFER,
4238
- timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS
4288
+ timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS,
4289
+ windowsHide: true
4239
4290
  });
4240
4291
  return parseWindowsProcessJsonLines(stdoutToString(stdout2));
4241
4292
  }
@@ -1000,12 +1000,18 @@ async function readLinuxDeviceId() {
1000
1000
  throw new Error("[memoraone-mcp] Unable to read Linux machine-id");
1001
1001
  }
1002
1002
  async function readWindowsDeviceId() {
1003
- const { stdout } = await execFileAsync("reg", [
1004
- "query",
1005
- "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
1006
- "/v",
1007
- "MachineGuid"
1008
- ]);
1003
+ const { stdout } = await execFileAsync(
1004
+ "reg",
1005
+ [
1006
+ "query",
1007
+ "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
1008
+ "/v",
1009
+ "MachineGuid"
1010
+ ],
1011
+ {
1012
+ windowsHide: true
1013
+ }
1014
+ );
1009
1015
  const match = stdout.match(/MachineGuid\s+REG_SZ\s+(.+)/i);
1010
1016
  if (!match?.[1]) {
1011
1017
  throw new Error("[memoraone-mcp] Unable to read Windows MachineGuid");
@@ -2310,35 +2316,74 @@ var WINDOWS_LIST_PROCESSES_PS = [
2310
2316
  " [Console]::Error.WriteLine([string]$_)",
2311
2317
  " exit 1",
2312
2318
  "}",
2313
- "$currentIdentity = [string][System.Security.Principal.WindowsIdentity]::GetCurrent().Name",
2314
- "if ([string]::IsNullOrWhiteSpace($currentIdentity)) {",
2315
- ' throw "Unable to determine the current Windows identity."',
2316
- "}",
2317
- "$systemDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)",
2318
- "if ([string]::IsNullOrWhiteSpace($systemDirectory)) {",
2319
- ' throw "Unable to determine the Windows system directory."',
2319
+ "$currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()",
2320
+ "$currentUserSid = [string]$currentIdentity.User.Value",
2321
+ "if ([string]::IsNullOrWhiteSpace($currentUserSid)) {",
2322
+ ' throw "Unable to determine the current Windows identity SID."',
2320
2323
  "}",
2321
- '$tasklistPath = [System.IO.Path]::Combine($systemDirectory, "tasklist.exe")',
2322
- '$tasklistArgs = @("/FI", "USERNAME eq $currentIdentity", "/FO", "CSV", "/NH")',
2323
- "$tasklistRows = @(& $tasklistPath $tasklistArgs)",
2324
- "$tasklistExitCode = $LASTEXITCODE",
2325
- "if ($tasklistExitCode -ne 0) {",
2326
- ' throw "tasklist.exe failed with exit code $tasklistExitCode."',
2324
+ "$ownerLookupSource = @'",
2325
+ "using System;",
2326
+ "using System.Collections.Generic;",
2327
+ "using System.Runtime.InteropServices;",
2328
+ "using System.Security.Principal;",
2329
+ "",
2330
+ "public static class MemoraOneProcessOwner {",
2331
+ " private const uint ProcessQueryLimitedInformation = 0x1000;",
2332
+ " private const uint TokenQuery = 0x0008;",
2333
+ " private const int TokenUser = 1;",
2334
+ "",
2335
+ ' [DllImport("kernel32.dll", SetLastError = true)]',
2336
+ " private static extern IntPtr OpenProcess(uint access, bool inheritHandle, int processId);",
2337
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
2338
+ " private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);",
2339
+ ' [DllImport("advapi32.dll", SetLastError = true)]',
2340
+ " private static extern bool GetTokenInformation(IntPtr tokenHandle, int tokenInformationClass, IntPtr tokenInformation, int tokenInformationLength, out int returnLength);",
2341
+ ' [DllImport("kernel32.dll")]',
2342
+ " private static extern bool CloseHandle(IntPtr handle);",
2343
+ "",
2344
+ " public static int[] OwnedProcessIds(int[] processIds, string currentSid) {",
2345
+ " var expectedSid = new SecurityIdentifier(currentSid);",
2346
+ " var owned = new List<int>();",
2347
+ " foreach (int processId in processIds) {",
2348
+ " IntPtr processHandle = OpenProcess(ProcessQueryLimitedInformation, false, processId);",
2349
+ " if (processHandle == IntPtr.Zero) continue;",
2350
+ " try {",
2351
+ " IntPtr tokenHandle;",
2352
+ " if (!OpenProcessToken(processHandle, TokenQuery, out tokenHandle)) continue;",
2353
+ " try {",
2354
+ " int tokenLength;",
2355
+ " GetTokenInformation(tokenHandle, TokenUser, IntPtr.Zero, 0, out tokenLength);",
2356
+ " if (tokenLength <= 0) continue;",
2357
+ " IntPtr tokenBuffer = Marshal.AllocHGlobal(tokenLength);",
2358
+ " try {",
2359
+ " if (!GetTokenInformation(tokenHandle, TokenUser, tokenBuffer, tokenLength, out tokenLength)) continue;",
2360
+ " IntPtr sidPointer = Marshal.ReadIntPtr(tokenBuffer);",
2361
+ " if (expectedSid.Equals(new SecurityIdentifier(sidPointer))) owned.Add(processId);",
2362
+ " } finally {",
2363
+ " Marshal.FreeHGlobal(tokenBuffer);",
2364
+ " }",
2365
+ " } finally {",
2366
+ " CloseHandle(tokenHandle);",
2367
+ " }",
2368
+ " } finally {",
2369
+ " CloseHandle(processHandle);",
2370
+ " }",
2371
+ " }",
2372
+ " return owned.ToArray();",
2373
+ " }",
2327
2374
  "}",
2375
+ "'@",
2376
+ "Add-Type -TypeDefinition $ownerLookupSource -Language CSharp",
2377
+ "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
2378
+ "$processIds = [int[]]@($processes | ForEach-Object { [int]$_.ProcessId })",
2379
+ "$ownedProcessIds = [MemoraOneProcessOwner]::OwnedProcessIds($processIds, $currentUserSid)",
2328
2380
  '$currentUserPids = New-Object "System.Collections.Generic.HashSet[int]"',
2329
- "foreach ($tasklistRow in $tasklistRows) {",
2330
- " if ([string]::IsNullOrWhiteSpace([string]$tasklistRow)) { continue }",
2331
- ' $task = $tasklistRow | ConvertFrom-Csv -Header "ImageName","ProcessId","SessionName","SessionNumber","MemoryUsage"',
2332
- " $taskPid = 0",
2333
- " if ($null -eq $task -or -not [int]::TryParse([string]$task.ProcessId, [ref]$taskPid) -or $taskPid -le 0) {",
2334
- ' throw "tasklist.exe returned an invalid process row."',
2335
- " }",
2336
- " $null = $currentUserPids.Add($taskPid)",
2381
+ "foreach ($ownedProcessId in $ownedProcessIds) {",
2382
+ " $null = $currentUserPids.Add([int]$ownedProcessId)",
2337
2383
  "}",
2338
2384
  "if (-not $currentUserPids.Contains([int]$PID)) {",
2339
- ' throw "tasklist.exe results did not include the running PowerShell process."',
2385
+ ' throw "Process token results did not include the running PowerShell process."',
2340
2386
  "}",
2341
- "$processes = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId,CommandLine)",
2342
2387
  "foreach ($proc in $processes) {",
2343
2388
  " if ($null -eq $proc.ProcessId) { continue }",
2344
2389
  " $procId = [int]$proc.ProcessId",
@@ -2425,7 +2470,8 @@ async function listProcessCommandLineRows(deps = {}) {
2425
2470
  const { file, args } = windowsProcessListInvocation();
2426
2471
  const { stdout: stdout2 } = await execFileImpl(file, args, {
2427
2472
  maxBuffer: PROCESS_LIST_MAX_BUFFER,
2428
- timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS
2473
+ timeout: WINDOWS_PROCESS_LIST_TIMEOUT_MS,
2474
+ windowsHide: true
2429
2475
  });
2430
2476
  return parseWindowsProcessJsonLines(stdoutToString(stdout2));
2431
2477
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memoraone/mcp",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "exports": {