@1xops/command-center 0.4.0
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.
Potentially problematic release.
This version of @1xops/command-center might be problematic. Click here for more details.
- package/LICENSE +191 -0
- package/README.md +141 -0
- package/dist/config.js +126 -0
- package/dist/files.js +200 -0
- package/dist/index.js +66 -0
- package/dist/log.js +5 -0
- package/dist/policy.js +141 -0
- package/dist/processes.js +206 -0
- package/dist/search-worker.js +14 -0
- package/dist/search.js +339 -0
- package/dist/server.js +296 -0
- package/dist/system.js +71 -0
- package/dist/version.js +5 -0
- package/icon.png +0 -0
- package/package.json +59 -0
package/dist/system.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// list_processes: a read-only view of the operating system's processes. Fixed commands with
|
|
2
|
+
// no user input, spawned without a shell, so blockedCommands does not apply.
|
|
3
|
+
import { execFile } from 'node:child_process';
|
|
4
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
5
|
+
const run = (file, args) => new Promise((resolve, reject) => {
|
|
6
|
+
execFile(file, args, { maxBuffer: 32 * 1024 * 1024, windowsHide: true, timeout: 15_000 }, (error, stdout) => error ? reject(new Error(`${file} failed: ${error.message}`)) : resolve(stdout));
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* The name to show for a Linux process. comm (the kernel's name, cut at 15 characters) is right
|
|
10
|
+
* unless the program renamed its main thread (Node 24 calls it "MainThread"); then the program
|
|
11
|
+
* path from cmdline is used, and also when comm was cut and cmdline holds the longer name.
|
|
12
|
+
* Daemons that rewrite cmdline ("sshd: os@pts/0") keep comm.
|
|
13
|
+
*/
|
|
14
|
+
export function linuxName(comm, cmdline) {
|
|
15
|
+
const argv0 = cmdline.split('\0')[0]?.split(' ')[0] ?? '';
|
|
16
|
+
const base = argv0.split('/').pop() ?? '';
|
|
17
|
+
if (!base)
|
|
18
|
+
return comm;
|
|
19
|
+
if (comm === 'MainThread')
|
|
20
|
+
return base;
|
|
21
|
+
// comm is cut at 15 characters; only then can the full name in cmdline add anything.
|
|
22
|
+
return comm.length === 15 && base.startsWith(comm) ? base : comm;
|
|
23
|
+
}
|
|
24
|
+
/** Linux: /proc is always there (minimal images ship a busybox ps without the fields we need). */
|
|
25
|
+
async function linux() {
|
|
26
|
+
const list = [];
|
|
27
|
+
for (const entry of await readdir('/proc')) {
|
|
28
|
+
if (!/^\d+$/.test(entry))
|
|
29
|
+
continue;
|
|
30
|
+
try {
|
|
31
|
+
// status gives the parent and resident memory already in kB, whatever the kernel's page size.
|
|
32
|
+
const status = await readFile(`/proc/${entry}/status`, 'utf8');
|
|
33
|
+
const field = (key) => new RegExp(`^${key}:\\s*(.*)$`, 'm').exec(status)?.[1]?.trim() ?? '';
|
|
34
|
+
const cmdline = await readFile(`/proc/${entry}/cmdline`, 'utf8').catch(() => '');
|
|
35
|
+
list.push({
|
|
36
|
+
pid: Number(entry),
|
|
37
|
+
ppid: Number(field('PPid')),
|
|
38
|
+
name: linuxName(field('Name'), cmdline),
|
|
39
|
+
memoryKb: Number.parseInt(field('VmRSS'), 10) || 0, // kernel threads have no VmRSS
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// The process ended between readdir and read: not an error.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return list;
|
|
47
|
+
}
|
|
48
|
+
async function macos() {
|
|
49
|
+
const out = await run('/bin/ps', ['-A', '-o', 'pid=,ppid=,rss=,comm=']);
|
|
50
|
+
return out.split('\n').flatMap((line) => {
|
|
51
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.+)$/.exec(line);
|
|
52
|
+
return m ? [{ pid: Number(m[1]), ppid: Number(m[2]), memoryKb: Number(m[3]), name: (m[4] ?? '').split('/').pop() ?? '' }] : [];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function windows() {
|
|
56
|
+
// UTF-8 output, so names outside the OEM code page survive the pipe.
|
|
57
|
+
const script = '[Console]::OutputEncoding = [Text.Encoding]::UTF8; Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,Name,WorkingSetSize | ConvertTo-Json -Compress';
|
|
58
|
+
const out = await run('powershell.exe', ['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', script]);
|
|
59
|
+
const rows = JSON.parse(out);
|
|
60
|
+
return (Array.isArray(rows) ? rows : [rows]).map((r) => ({
|
|
61
|
+
pid: r.ProcessId, ppid: r.ParentProcessId, name: r.Name ?? '', memoryKb: Math.round(Number(r.WorkingSetSize ?? 0) / 1024),
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/** Processes whose name contains `filter` (case-insensitive), largest memory first, at most `limit`. */
|
|
65
|
+
export async function listProcesses(filter, limit) {
|
|
66
|
+
const all = process.platform === 'win32' ? await windows() : process.platform === 'linux' ? await linux() : await macos();
|
|
67
|
+
const needle = filter?.toLowerCase();
|
|
68
|
+
const matched = needle ? all.filter((p) => p.name.toLowerCase().includes(needle)) : all;
|
|
69
|
+
matched.sort((a, b) => b.memoryKb - a.memoryKb);
|
|
70
|
+
return { processes: matched.slice(0, limit), total: matched.length };
|
|
71
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
// One source of truth: package.json, which npm, the plugin and the registry all read.
|
|
3
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
4
|
+
export const VERSION = pkg.version;
|
|
5
|
+
export const SERVER_NAME = 'command-center';
|
package/icon.png
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@1xops/command-center",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "1xOps Command Center: an MCP server for persistent terminal sessions, processes and text-file work, with one folder and command policy for Claude and OpenAI clients",
|
|
5
|
+
"mcpName": "io.github.1xOps/command-center",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "1xOps (nnthanh101) <nnthanh101@gmail.com> (https://github.com/1xOps)",
|
|
8
|
+
"homepage": "https://github.com/1xOps/command-center-mcp/tree/develop/mcp-server",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/1xOps/command-center-mcp.git",
|
|
12
|
+
"directory": "mcp-server"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/1xOps/command-center-mcp/issues",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=24"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"command-center": "dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"icon.png"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node scripts/clean.mjs && tsc -p tsconfig.json && node scripts/make-executable.mjs",
|
|
29
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
30
|
+
"test": "npm run build && node --test --test-reporter=spec",
|
|
31
|
+
"test:coverage": "npm run build && node --test --experimental-test-coverage --test-coverage-include=dist/**",
|
|
32
|
+
"start": "node dist/index.js",
|
|
33
|
+
"verify": "node scripts/verify.mjs",
|
|
34
|
+
"supply-chain": "node scripts/supply-chain.mjs",
|
|
35
|
+
"release:rehearsal": "node scripts/release-rehearsal.mjs",
|
|
36
|
+
"prepack": "npm run build",
|
|
37
|
+
"build:mcpb": "npm run build && node scripts/build-mcpb.mjs"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"mcp",
|
|
45
|
+
"model-context-protocol",
|
|
46
|
+
"terminal",
|
|
47
|
+
"process",
|
|
48
|
+
"claude",
|
|
49
|
+
"codex"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@modelcontextprotocol/sdk": "1.32.2",
|
|
53
|
+
"zod": "4.6.7"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "24.19.2",
|
|
57
|
+
"typescript": "7.0.2"
|
|
58
|
+
}
|
|
59
|
+
}
|