je-cd 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 joke-lx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # jc — j 命令套件
2
+
3
+ > 跨平台系统快捷命令集。将 Windows batch 版 `j` 命令套件移植为纯 TypeScript 跨平台 npm CLI。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install -g jc
9
+ ```
10
+
11
+ ## 用法
12
+
13
+ ```bash
14
+ jc # 显示帮助
15
+ jc l # 列出所有组
16
+
17
+ jc claude # 启动 Claude Code
18
+ jc claude b # 跳过权限模式
19
+ jc claude r # 恢复上次会话
20
+
21
+ jc happy # 启动 Happy Claude
22
+ jc happy daemon # Happy 守护进程模式
23
+
24
+ jc w l # 列出 w 组 11 个类别
25
+ jc w l proc # 进程类命令列表
26
+ jc w p 3306 # 查 3306 端口占用
27
+ jc w pk 8080 # 一键查杀 8080 端口进程
28
+ jc w k 1234 # 按 PID 杀进程
29
+ jc w top # CPU 占用 Top20
30
+ jc w sysinfo # 系统详细信息
31
+ jc w cpu # CPU 信息
32
+ jc w disk # 磁盘卷信息
33
+ jc w ip # 网络接口信息
34
+ jc w wifi # Wi-Fi 连接信息
35
+ jc w mac # MAC 地址
36
+ jc w who # 当前用户信息
37
+ jc w ? # 命令帮助
38
+ ```
39
+
40
+ ## 分组
41
+
42
+ | 组 | 别名 | 说明 | 命令数 |
43
+ |----|------|------|--------|
44
+ | claude | c | Claude Code CLI 包装 | 4 |
45
+ | happy | hy | Happy mobile Claude 包装 | 7 |
46
+ | w | w | 系统快捷命令集 | 87 |
47
+
48
+ ## w 组 11 个类别
49
+
50
+ | 类别 | 命令数 | 说明 |
51
+ |------|--------|------|
52
+ | proc | 8 | 进程管理(端口/查杀/Top) |
53
+ | net | 15 | 网络(IP/DNS/WiFi/路由) |
54
+ | file | 13 | 文件操作(ls/cd/find/size) |
55
+ | sys | 12 | 系统信息(CPU/内存/磁盘/GPU) |
56
+ | svc | 5 | 服务管理 |
57
+ | pwr | 6 | 电源(关机/重启/锁屏/休眠) |
58
+ | reg | 4 | 注册表(仅 Windows) |
59
+ | task | 3 | 计划任务(仅 Windows) |
60
+ | tools | 14 | 系统工具(任务管理器/控制面板等) |
61
+ | user | 4 | 用户/权限 |
62
+ | wsl | 3 | WSL/Docker(仅 Windows) |
63
+
64
+ ## 跨平台
65
+
66
+ - **Windows**: 全部 98 命令完整支持
67
+ - **macOS / Linux**: 核心命令支持(~80%),注册表/WSL/WiFi密码等 Windows 特有命令会提示"此命令仅支持 Windows"
68
+
69
+ ## 构建
70
+
71
+ ```bash
72
+ npm run build # tsup 打包
73
+ npm test # Vitest 测试
74
+ ```
75
+
76
+ ## 许可证
77
+
78
+ MIT
@@ -0,0 +1,18 @@
1
+ import {
2
+ getCpuManager,
3
+ getDiskManager,
4
+ getGpuManager,
5
+ getMemoryManager,
6
+ getNetworkManager,
7
+ getOsManager,
8
+ getProcessManager
9
+ } from "./chunk-DZZGI7AU.js";
10
+ export {
11
+ getCpuManager,
12
+ getDiskManager,
13
+ getGpuManager,
14
+ getMemoryManager,
15
+ getNetworkManager,
16
+ getOsManager,
17
+ getProcessManager
18
+ };
@@ -0,0 +1,405 @@
1
+ // src/shared/system/process.ts
2
+ import si from "systeminformation";
3
+ import { execSync } from "child_process";
4
+ var WinProcessManager = class {
5
+ async getListeningPorts() {
6
+ const data = await si.networkConnections();
7
+ const listenEntries = data && data.length > 0 ? data.filter((c) => c.state === "listen") : [];
8
+ if (listenEntries.length > 0) {
9
+ return listenEntries.map((c) => ({
10
+ pid: c.pid,
11
+ name: "",
12
+ cpu: 0,
13
+ memory: 0,
14
+ port: c.localPort,
15
+ state: c.state
16
+ }));
17
+ }
18
+ if (process.platform === "win32") {
19
+ try {
20
+ const output = execSync("netstat -ano", { encoding: "utf8", timeout: 5e3 });
21
+ return output.split("\n").filter((l) => l.includes("LISTENING")).map((l) => {
22
+ const parts = l.trim().split(/\s+/);
23
+ const addr = parts[1] || "";
24
+ const port = parseInt(addr.split(":").pop() || "", 10);
25
+ const pid = parseInt(parts[parts.length - 1], 10);
26
+ return { pid: isNaN(pid) ? 0 : pid, name: "", cpu: 0, memory: 0, port: isNaN(port) ? void 0 : port, state: "listen" };
27
+ }).filter((p) => p.port !== void 0 && p.pid > 0);
28
+ } catch {
29
+ }
30
+ }
31
+ return [];
32
+ }
33
+ async getProcessByPort(port) {
34
+ let conns = await si.networkConnections();
35
+ if (!conns || conns.length === 0 || !conns.some((c) => c.state === "listen")) {
36
+ if (process.platform === "win32") {
37
+ try {
38
+ const output = execSync("netstat -ano", { encoding: "utf8", timeout: 5e3 });
39
+ conns = output.split("\n").filter((l) => l.includes("LISTENING")).map((l) => {
40
+ const parts = l.trim().split(/\s+/);
41
+ const addr = parts[1] || "";
42
+ const localPort = parseInt(addr.split(":").pop() || "", 10);
43
+ const pid = parseInt(parts[parts.length - 1], 10);
44
+ return { localPort, pid, state: "listen" };
45
+ });
46
+ } catch {
47
+ }
48
+ }
49
+ }
50
+ const matches = conns.filter((c) => c.localPort === port && c.state === "listen");
51
+ if (matches.length === 0) return [];
52
+ return Promise.all(matches.map(async (m) => {
53
+ const proc = await this.getProcessInfo(m.pid);
54
+ return { ...proc, port: m.localPort };
55
+ }));
56
+ }
57
+ async getProcessByName(name) {
58
+ const processes = await si.processes();
59
+ return processes.list.filter((p) => p.name.toLowerCase().includes(name.toLowerCase())).map((p) => ({
60
+ pid: p.pid,
61
+ name: p.name,
62
+ cpu: p.cpu,
63
+ memory: Math.round(p.mem / (1024 * 1024)),
64
+ state: p.state
65
+ }));
66
+ }
67
+ async killProcess(pid) {
68
+ try {
69
+ process.kill(pid, "SIGTERM");
70
+ } catch {
71
+ process.kill(pid, "SIGKILL");
72
+ }
73
+ }
74
+ async getTopProcesses(sort, limit) {
75
+ const processes = await si.processes();
76
+ const list = processes.list.map((p) => ({
77
+ pid: p.pid,
78
+ name: p.name,
79
+ cpu: p.cpu,
80
+ memory: Math.round(p.mem / (1024 * 1024)),
81
+ state: p.state
82
+ }));
83
+ if (sort === "cpu") {
84
+ list.sort((a, b) => b.cpu - a.cpu);
85
+ } else {
86
+ list.sort((a, b) => b.memory - a.memory);
87
+ }
88
+ return list.slice(0, limit);
89
+ }
90
+ async getProcessStats() {
91
+ const processes = await si.processes();
92
+ return {
93
+ total: processes.all,
94
+ running: processes.running || processes.all,
95
+ cpuPercent: Math.round((typeof processes.cpu === "number" ? processes.cpu : 0) * 10) / 10,
96
+ memoryGB: Math.round((typeof processes.mem === "number" ? processes.mem : 0) / (1024 * 1024 * 1024) * 10) / 10
97
+ };
98
+ }
99
+ async listProcesses(nameFilter) {
100
+ const processes = await si.processes();
101
+ let list = processes.list;
102
+ if (nameFilter) {
103
+ list = list.filter((p) => p.name.toLowerCase().includes(nameFilter.toLowerCase()));
104
+ }
105
+ return list.map((p) => ({
106
+ pid: p.pid,
107
+ name: p.name,
108
+ cpu: p.cpu,
109
+ memory: Math.round(p.mem / (1024 * 1024)),
110
+ state: p.state
111
+ }));
112
+ }
113
+ async getProcessInfo(pid) {
114
+ try {
115
+ const procs = await si.processes();
116
+ const p = procs.list.find((x) => x.pid === pid);
117
+ if (p) {
118
+ return { pid, name: p.name, cpu: p.cpu, memory: Math.round(p.mem / (1024 * 1024)) };
119
+ }
120
+ } catch {
121
+ }
122
+ return { pid, name: `PID:${pid}`, cpu: 0, memory: 0 };
123
+ }
124
+ };
125
+
126
+ // src/shared/system/network.ts
127
+ import si2 from "systeminformation";
128
+ import { execSync as execSync2 } from "child_process";
129
+ var SystemNetworkManager = class {
130
+ async getNetworkInfo() {
131
+ const [interfaces, defaultGateway] = await Promise.all([
132
+ si2.networkInterfaces(),
133
+ si2.networkGatewayDefault()
134
+ ]);
135
+ const ifaces = (interfaces || []).map((inf) => ({
136
+ name: inf.iface,
137
+ ip4: inf.ip4,
138
+ ip6: inf.ip6,
139
+ mac: inf.mac,
140
+ type: inf.type
141
+ }));
142
+ const dns = await this.getDnsServers();
143
+ return {
144
+ interfaces: ifaces,
145
+ defaultGateway: defaultGateway || "",
146
+ dnsServers: dns,
147
+ hostname: (await si2.osInfo()).hostname
148
+ };
149
+ }
150
+ async getDnsServers() {
151
+ try {
152
+ const dns = await si2.dns();
153
+ return dns.nameservers || [];
154
+ } catch {
155
+ return [];
156
+ }
157
+ }
158
+ async getWiFiInfo() {
159
+ try {
160
+ const networks = await si2.wifiConnections();
161
+ return (networks || []).map((n) => ({
162
+ ssid: n.ssid || "",
163
+ signal: n.signal || 0,
164
+ frequency: n.frequency || "",
165
+ channel: n.channel || 0,
166
+ security: n.security || ""
167
+ }));
168
+ } catch {
169
+ return [];
170
+ }
171
+ }
172
+ async getWiFiPasswords() {
173
+ if (process.platform !== "win32") {
174
+ throw new Error("\u6B64\u547D\u4EE4\u4EC5\u652F\u6301 Windows");
175
+ }
176
+ const profiles = [];
177
+ try {
178
+ const output = execSync2("netsh wlan show profiles", { encoding: "utf8" });
179
+ const lines = output.split("\n");
180
+ const ssids = [];
181
+ for (const line of lines) {
182
+ const m = line.match(/:\s*(.+)$/);
183
+ if (m) ssids.push(m[1].trim());
184
+ }
185
+ for (const ssid of ssids) {
186
+ try {
187
+ const detail = execSync2(`netsh wlan show profile "${ssid}" key=clear`, { encoding: "utf8" });
188
+ const pwMatch = detail.match(/关键内容\s*:\s*(.+)$/m) || detail.match(/Key Content\s*:\s*(.+)$/m);
189
+ profiles.push({ ssid, password: pwMatch ? pwMatch[1].trim() : "(\u65E0)" });
190
+ } catch {
191
+ }
192
+ }
193
+ } catch {
194
+ }
195
+ return profiles;
196
+ }
197
+ async ping(host) {
198
+ const flag = process.platform === "win32" ? "-n" : "-c";
199
+ try {
200
+ const start = Date.now();
201
+ execSync2(`ping ${flag} 1 ${host}`, { encoding: "utf8", timeout: 1e4 });
202
+ return { alive: true, time: Date.now() - start };
203
+ } catch {
204
+ return { alive: false, time: 0 };
205
+ }
206
+ }
207
+ async traceRoute(host) {
208
+ const cmd = process.platform === "win32" ? `tracert -d ${host}` : `traceroute -n ${host}`;
209
+ try {
210
+ const output = execSync2(cmd, { encoding: "utf8", timeout: 3e4 });
211
+ return output.split("\n").filter((l) => l.trim()).slice(1);
212
+ } catch {
213
+ return [];
214
+ }
215
+ }
216
+ async getConnections() {
217
+ const data = await si2.networkConnections();
218
+ return (data || []).map((c) => ({
219
+ localPort: c.localPort,
220
+ remotePort: c.remotePort,
221
+ state: c.state,
222
+ pid: c.pid
223
+ }));
224
+ }
225
+ async flushDns() {
226
+ if (process.platform === "win32") {
227
+ execSync2("ipconfig /flushdns", { encoding: "utf8" });
228
+ } else if (process.platform === "darwin") {
229
+ execSync2("dscacheutil -flushcache", { encoding: "utf8" });
230
+ } else {
231
+ execSync2("systemd-resolve --flush-caches || resolvectl flush-caches", { encoding: "utf8" });
232
+ }
233
+ }
234
+ async getProxySettings() {
235
+ if (process.platform === "win32") {
236
+ try {
237
+ const output = execSync2('reg query "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD', { encoding: "utf8" });
238
+ const enabled = output.includes("0x1");
239
+ let httpProxy2 = "";
240
+ let httpsProxy2 = "";
241
+ if (enabled) {
242
+ try {
243
+ const server = execSync2('reg query "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyServer /t REG_SZ', { encoding: "utf8" });
244
+ const m = server.match(/:\s*(.+)$/m);
245
+ if (m) {
246
+ httpProxy2 = m[1].trim();
247
+ httpsProxy2 = m[1].trim();
248
+ }
249
+ } catch {
250
+ }
251
+ }
252
+ return { httpProxy: httpProxy2, httpsProxy: httpsProxy2, enabled };
253
+ } catch {
254
+ return { httpProxy: "", httpsProxy: "", enabled: false };
255
+ }
256
+ }
257
+ const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || "";
258
+ const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY || "";
259
+ return { httpProxy, httpsProxy, enabled: !!(httpProxy || httpsProxy) };
260
+ }
261
+ async getMacAddresses() {
262
+ const ifs = await si2.networkInterfaces();
263
+ return (ifs || []).map((i) => ({ name: i.iface, mac: i.mac }));
264
+ }
265
+ };
266
+
267
+ // src/shared/system/cpu.ts
268
+ import si3 from "systeminformation";
269
+ var SystemCpuManager = class {
270
+ async getInfo() {
271
+ const [cpu, load] = await Promise.all([
272
+ si3.cpu(),
273
+ si3.currentLoad()
274
+ ]);
275
+ return {
276
+ manufacturer: cpu.manufacturer,
277
+ brand: cpu.brand,
278
+ physicalCores: cpu.physicalCores,
279
+ logicalCores: cpu.cores,
280
+ speedGHz: cpu.speed,
281
+ loadPercent: Math.round(load.currentLoad * 10) / 10
282
+ };
283
+ }
284
+ };
285
+
286
+ // src/shared/system/memory.ts
287
+ import si4 from "systeminformation";
288
+ var SystemMemoryManager = class {
289
+ async getInfo() {
290
+ const mem = await si4.mem();
291
+ return {
292
+ totalGB: Math.round(mem.total / (1024 * 1024 * 1024) * 10) / 10,
293
+ freeGB: Math.round(mem.free / (1024 * 1024 * 1024) * 10) / 10,
294
+ usedGB: Math.round(mem.used / (1024 * 1024 * 1024) * 10) / 10,
295
+ percentUsed: Math.round(mem.used / mem.total * 100 * 10) / 10,
296
+ swapTotalGB: Math.round(mem.swaptotal / (1024 * 1024 * 1024) * 10) / 10,
297
+ swapUsedGB: Math.round(mem.swapused / (1024 * 1024 * 1024) * 10) / 10
298
+ };
299
+ }
300
+ };
301
+
302
+ // src/shared/system/disk.ts
303
+ import si5 from "systeminformation";
304
+ var SystemDiskManager = class {
305
+ async getInfo() {
306
+ const fs = await si5.fsSize();
307
+ return fs.filter((f) => f.mount).map((f) => ({
308
+ drive: f.mount,
309
+ sizeGB: Math.round(f.size / (1024 * 1024 * 1024)),
310
+ usedGB: Math.round(f.used / (1024 * 1024 * 1024)),
311
+ freeGB: Math.round((f.size - f.used) / (1024 * 1024 * 1024)),
312
+ percentUsed: Math.round(f.use * 10) / 10,
313
+ filesystem: f.fs || ""
314
+ }));
315
+ }
316
+ async getFullInfo() {
317
+ return this.getInfo();
318
+ }
319
+ async getSize(path) {
320
+ const fs = await si5.fsSize(path);
321
+ const total = fs.reduce((acc, f) => acc + f.size, 0);
322
+ return { sizeMB: Math.round(total / (1024 * 1024)) };
323
+ }
324
+ };
325
+
326
+ // src/shared/system/gpu.ts
327
+ import si6 from "systeminformation";
328
+ var SystemGpuManager = class {
329
+ async getInfo() {
330
+ const graphics = await si6.graphics();
331
+ return (graphics.controllers || []).map((g) => ({
332
+ model: g.model,
333
+ driverVersion: g.driverVersion || "",
334
+ vramGB: Math.round((g.vram || 0) / 1024 * 10) / 10
335
+ }));
336
+ }
337
+ };
338
+
339
+ // src/shared/system/os.ts
340
+ import si7 from "systeminformation";
341
+ var SystemOsManager = class {
342
+ async getInfo() {
343
+ const [os, bios, time] = await Promise.all([
344
+ si7.osInfo(),
345
+ si7.bios(),
346
+ si7.time()
347
+ ]);
348
+ return {
349
+ hostname: os.hostname,
350
+ platform: os.platform,
351
+ distro: os.distro,
352
+ release: os.release,
353
+ kernel: os.kernel,
354
+ uptime: time.uptime,
355
+ biosVendor: bios.vendor || "",
356
+ biosVersion: bios.version || "",
357
+ biosDate: bios.releaseDate || ""
358
+ };
359
+ }
360
+ async getHostname() {
361
+ return (await si7.osInfo()).hostname;
362
+ }
363
+ async getUptime() {
364
+ const t = (await si7.time()).uptime;
365
+ const d = Math.floor(t / 86400);
366
+ const h = Math.floor(t % 86400 / 3600);
367
+ const m = Math.floor(t % 3600 / 60);
368
+ if (d > 0) return `${d}d ${h}h ${m}m`;
369
+ if (h > 0) return `${h}h ${m}m`;
370
+ return `${m}m`;
371
+ }
372
+ };
373
+
374
+ // src/shared/system/adapter.ts
375
+ function getProcessManager() {
376
+ return new WinProcessManager();
377
+ }
378
+ function getNetworkManager() {
379
+ return new SystemNetworkManager();
380
+ }
381
+ function getCpuManager() {
382
+ return new SystemCpuManager();
383
+ }
384
+ function getMemoryManager() {
385
+ return new SystemMemoryManager();
386
+ }
387
+ function getDiskManager() {
388
+ return new SystemDiskManager();
389
+ }
390
+ function getGpuManager() {
391
+ return new SystemGpuManager();
392
+ }
393
+ function getOsManager() {
394
+ return new SystemOsManager();
395
+ }
396
+
397
+ export {
398
+ getProcessManager,
399
+ getNetworkManager,
400
+ getCpuManager,
401
+ getMemoryManager,
402
+ getDiskManager,
403
+ getGpuManager,
404
+ getOsManager
405
+ };