@bonginkan/maria 2.1.0 → 2.1.2
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/README.md +25 -2
- package/dist/bin/maria.js +21013 -11461
- package/dist/bin/maria.js.map +1 -1
- package/dist/cli.js +20094 -10752
- package/dist/cli.js.map +1 -1
- package/dist/index.js +131662 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/services/linux-command-intelligence/command-knowledge-base.d.ts +96 -0
- package/dist/services/linux-command-intelligence/command-knowledge-base.js +597 -0
- package/dist/services/linux-command-intelligence/command-knowledge-base.js.map +1 -0
- package/dist/services/linux-command-intelligence/context-analyzer.d.ts +111 -0
- package/dist/services/linux-command-intelligence/context-analyzer.js +427 -0
- package/dist/services/linux-command-intelligence/context-analyzer.js.map +1 -0
- package/package.json +5 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { CommandCategory, RiskLevel, LinuxCommand } from './context-analyzer.js';
|
|
3
|
+
|
|
4
|
+
interface CommandDefinition {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
category: CommandCategory;
|
|
8
|
+
riskLevel: RiskLevel;
|
|
9
|
+
syntax: string;
|
|
10
|
+
commonFlags: FlagDefinition[];
|
|
11
|
+
examples: CommandExample[];
|
|
12
|
+
manPage?: string;
|
|
13
|
+
requiresSudo: boolean;
|
|
14
|
+
alternatives: string[];
|
|
15
|
+
safetyNotes: string[];
|
|
16
|
+
platform: string[];
|
|
17
|
+
}
|
|
18
|
+
interface FlagDefinition {
|
|
19
|
+
flag: string;
|
|
20
|
+
description: string;
|
|
21
|
+
argument?: string;
|
|
22
|
+
riskModifier?: number;
|
|
23
|
+
}
|
|
24
|
+
interface CommandExample {
|
|
25
|
+
command: string;
|
|
26
|
+
description: string;
|
|
27
|
+
risk: RiskLevel;
|
|
28
|
+
output?: string;
|
|
29
|
+
}
|
|
30
|
+
interface CommandSequence {
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
steps: LinuxCommand[];
|
|
34
|
+
rollback?: LinuxCommand[];
|
|
35
|
+
conditions?: ExecutionCondition[];
|
|
36
|
+
}
|
|
37
|
+
interface ExecutionCondition {
|
|
38
|
+
type: 'pre' | 'post' | 'between';
|
|
39
|
+
check: string;
|
|
40
|
+
onFail?: 'abort' | 'skip' | 'continue';
|
|
41
|
+
}
|
|
42
|
+
interface SafetyGuideline {
|
|
43
|
+
command: string;
|
|
44
|
+
guidelines: string[];
|
|
45
|
+
forbiddenPatterns: RegExp[];
|
|
46
|
+
requiresConfirmation: boolean;
|
|
47
|
+
backupRequired: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface CommandAlternative {
|
|
50
|
+
original: string;
|
|
51
|
+
alternatives: AlternativeOption[];
|
|
52
|
+
}
|
|
53
|
+
interface AlternativeOption {
|
|
54
|
+
command: string;
|
|
55
|
+
reason: string;
|
|
56
|
+
pros: string[];
|
|
57
|
+
cons: string[];
|
|
58
|
+
preferredWhen: string;
|
|
59
|
+
}
|
|
60
|
+
declare class CommandKnowledgeBase extends EventEmitter {
|
|
61
|
+
private commands;
|
|
62
|
+
private workflows;
|
|
63
|
+
private safetyGuidelines;
|
|
64
|
+
private alternatives;
|
|
65
|
+
constructor();
|
|
66
|
+
private initializeKnowledgeBase;
|
|
67
|
+
private initializeFileCommands;
|
|
68
|
+
private initializeProcessCommands;
|
|
69
|
+
private initializeNetworkCommands;
|
|
70
|
+
private initializeSystemCommands;
|
|
71
|
+
private initializeWorkflows;
|
|
72
|
+
private initializeSafetyGuidelines;
|
|
73
|
+
private initializeAlternatives;
|
|
74
|
+
private createCommand;
|
|
75
|
+
getCommand(name: string | undefined): CommandDefinition | undefined;
|
|
76
|
+
getWorkflow(name: string): CommandSequence | undefined;
|
|
77
|
+
getSafetyGuidelines(command: string): SafetyGuideline | undefined;
|
|
78
|
+
getAlternatives(command: string): CommandAlternative | undefined;
|
|
79
|
+
searchCommands(query: string): CommandDefinition[];
|
|
80
|
+
getCommandsByCategory(category: CommandCategory): CommandDefinition[];
|
|
81
|
+
getCommandsByRiskLevel(maxRisk: RiskLevel): CommandDefinition[];
|
|
82
|
+
validateCommand(commandString: string): {
|
|
83
|
+
valid: boolean;
|
|
84
|
+
risk: RiskLevel;
|
|
85
|
+
warnings: string[];
|
|
86
|
+
};
|
|
87
|
+
suggestAlternative(command: string): AlternativeOption[];
|
|
88
|
+
getAllWorkflows(): CommandSequence[];
|
|
89
|
+
exportKnowledge(): {
|
|
90
|
+
commands: CommandDefinition[];
|
|
91
|
+
workflows: CommandSequence[];
|
|
92
|
+
guidelines: SafetyGuideline[];
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { type AlternativeOption, type CommandAlternative, type CommandDefinition, type CommandExample, CommandKnowledgeBase, type CommandSequence, type ExecutionCondition, type FlagDefinition, type SafetyGuideline };
|
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var events = require('events');
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var util = require('util');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
util.promisify(child_process.exec);
|
|
10
|
+
|
|
11
|
+
// src/services/linux-command-intelligence/command-knowledge-base.ts
|
|
12
|
+
var CommandKnowledgeBase = class extends events.EventEmitter {
|
|
13
|
+
static {
|
|
14
|
+
__name(this, "CommandKnowledgeBase");
|
|
15
|
+
}
|
|
16
|
+
commands;
|
|
17
|
+
workflows;
|
|
18
|
+
safetyGuidelines;
|
|
19
|
+
alternatives;
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.commands = /* @__PURE__ */ new Map();
|
|
23
|
+
this.workflows = /* @__PURE__ */ new Map();
|
|
24
|
+
this.safetyGuidelines = /* @__PURE__ */ new Map();
|
|
25
|
+
this.alternatives = /* @__PURE__ */ new Map();
|
|
26
|
+
this.initializeKnowledgeBase();
|
|
27
|
+
}
|
|
28
|
+
initializeKnowledgeBase() {
|
|
29
|
+
this.initializeFileCommands();
|
|
30
|
+
this.initializeProcessCommands();
|
|
31
|
+
this.initializeNetworkCommands();
|
|
32
|
+
this.initializeSystemCommands();
|
|
33
|
+
this.initializeWorkflows();
|
|
34
|
+
this.initializeSafetyGuidelines();
|
|
35
|
+
this.initializeAlternatives();
|
|
36
|
+
}
|
|
37
|
+
initializeFileCommands() {
|
|
38
|
+
this.commands.set("ls", {
|
|
39
|
+
name: "ls",
|
|
40
|
+
description: "List directory contents",
|
|
41
|
+
category: "READ_ONLY" /* READ_ONLY */,
|
|
42
|
+
riskLevel: "SAFE" /* SAFE */,
|
|
43
|
+
syntax: "ls [OPTIONS] [FILE]...",
|
|
44
|
+
commonFlags: [
|
|
45
|
+
{ flag: "-l", description: "Long format listing" },
|
|
46
|
+
{ flag: "-a", description: "Show all files including hidden" },
|
|
47
|
+
{ flag: "-h", description: "Human readable sizes" },
|
|
48
|
+
{ flag: "-R", description: "Recursive listing" },
|
|
49
|
+
{ flag: "-t", description: "Sort by modification time" },
|
|
50
|
+
{ flag: "-S", description: "Sort by file size" }
|
|
51
|
+
],
|
|
52
|
+
examples: [
|
|
53
|
+
{ command: "ls -la", description: "List all files in long format", risk: "SAFE" /* SAFE */ },
|
|
54
|
+
{ command: "ls -lah /var/log", description: "List log files with sizes", risk: "SAFE" /* SAFE */ }
|
|
55
|
+
],
|
|
56
|
+
requiresSudo: false,
|
|
57
|
+
alternatives: ["dir", "find", "tree"],
|
|
58
|
+
safetyNotes: ["Safe for all operations", "No data modification"],
|
|
59
|
+
platform: ["linux", "darwin", "unix"]
|
|
60
|
+
});
|
|
61
|
+
this.commands.set("rm", {
|
|
62
|
+
name: "rm",
|
|
63
|
+
description: "Remove files or directories",
|
|
64
|
+
category: "DELETE" /* DELETE */,
|
|
65
|
+
riskLevel: "HIGH" /* HIGH */,
|
|
66
|
+
syntax: "rm [OPTIONS] FILE...",
|
|
67
|
+
commonFlags: [
|
|
68
|
+
{ flag: "-r", description: "Recursive removal", riskModifier: 2 },
|
|
69
|
+
{ flag: "-f", description: "Force removal without prompt", riskModifier: 2 },
|
|
70
|
+
{ flag: "-i", description: "Interactive mode", riskModifier: -1 },
|
|
71
|
+
{ flag: "-v", description: "Verbose output" }
|
|
72
|
+
],
|
|
73
|
+
examples: [
|
|
74
|
+
{ command: "rm file.txt", description: "Remove single file", risk: "MEDIUM" /* MEDIUM */ },
|
|
75
|
+
{ command: "rm -rf directory/", description: "Force remove directory", risk: "CRITICAL" /* CRITICAL */ }
|
|
76
|
+
],
|
|
77
|
+
requiresSudo: false,
|
|
78
|
+
alternatives: ["trash", "mv to /tmp", "unlink"],
|
|
79
|
+
safetyNotes: [
|
|
80
|
+
"IRREVERSIBLE operation",
|
|
81
|
+
"Always verify path before execution",
|
|
82
|
+
"Consider using trash instead",
|
|
83
|
+
"Never use rm -rf / or rm -rf /*"
|
|
84
|
+
],
|
|
85
|
+
platform: ["linux", "darwin", "unix"]
|
|
86
|
+
});
|
|
87
|
+
this.commands.set("find", {
|
|
88
|
+
name: "find",
|
|
89
|
+
description: "Search for files and directories",
|
|
90
|
+
category: "READ_ONLY" /* READ_ONLY */,
|
|
91
|
+
riskLevel: "SAFE" /* SAFE */,
|
|
92
|
+
syntax: "find [PATH] [OPTIONS] [EXPRESSION]",
|
|
93
|
+
commonFlags: [
|
|
94
|
+
{ flag: "-name", description: "Search by name pattern", argument: "pattern" },
|
|
95
|
+
{ flag: "-type", description: "Search by type", argument: "f|d|l" },
|
|
96
|
+
{ flag: "-size", description: "Search by size", argument: "+/-size" },
|
|
97
|
+
{ flag: "-mtime", description: "Modified time", argument: "+/-days" },
|
|
98
|
+
{ flag: "-exec", description: "Execute command on results", argument: "command", riskModifier: 3 },
|
|
99
|
+
{ flag: "-delete", description: "Delete found files", riskModifier: 5 }
|
|
100
|
+
],
|
|
101
|
+
examples: [
|
|
102
|
+
{ command: 'find . -name "*.log"', description: "Find all log files", risk: "SAFE" /* SAFE */ },
|
|
103
|
+
{ command: "find /tmp -mtime +7 -delete", description: "Delete old temp files", risk: "HIGH" /* HIGH */ }
|
|
104
|
+
],
|
|
105
|
+
requiresSudo: false,
|
|
106
|
+
alternatives: ["locate", "fd", "grep -r"],
|
|
107
|
+
safetyNotes: [
|
|
108
|
+
"Be careful with -exec and -delete flags",
|
|
109
|
+
"Test with -print first before destructive operations",
|
|
110
|
+
"Use -maxdepth to limit recursion"
|
|
111
|
+
],
|
|
112
|
+
platform: ["linux", "darwin", "unix"]
|
|
113
|
+
});
|
|
114
|
+
this.commands.set("chmod", {
|
|
115
|
+
name: "chmod",
|
|
116
|
+
description: "Change file permissions",
|
|
117
|
+
category: "WRITE" /* WRITE */,
|
|
118
|
+
riskLevel: "MEDIUM" /* MEDIUM */,
|
|
119
|
+
syntax: "chmod [OPTIONS] MODE FILE...",
|
|
120
|
+
commonFlags: [
|
|
121
|
+
{ flag: "-R", description: "Recursive change", riskModifier: 2 },
|
|
122
|
+
{ flag: "-v", description: "Verbose output" },
|
|
123
|
+
{ flag: "-c", description: "Report only changes" },
|
|
124
|
+
{ flag: "--preserve-root", description: "Fail on root", riskModifier: -2 }
|
|
125
|
+
],
|
|
126
|
+
examples: [
|
|
127
|
+
{ command: "chmod 644 file.txt", description: "Set read/write for owner, read for others", risk: "LOW" /* LOW */ },
|
|
128
|
+
{ command: "chmod +x script.sh", description: "Make file executable", risk: "MEDIUM" /* MEDIUM */ },
|
|
129
|
+
{ command: "chmod -R 777 /", description: "DANGEROUS: Open all permissions", risk: "CRITICAL" /* CRITICAL */ }
|
|
130
|
+
],
|
|
131
|
+
requiresSudo: false,
|
|
132
|
+
alternatives: ["setfacl", "chown"],
|
|
133
|
+
safetyNotes: [
|
|
134
|
+
"Incorrect permissions can break system",
|
|
135
|
+
"Never use 777 on system files",
|
|
136
|
+
"Understand octal notation before use",
|
|
137
|
+
"Can affect security if misused"
|
|
138
|
+
],
|
|
139
|
+
platform: ["linux", "darwin", "unix"]
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
initializeProcessCommands() {
|
|
143
|
+
this.commands.set("ps", {
|
|
144
|
+
name: "ps",
|
|
145
|
+
description: "Display process status",
|
|
146
|
+
category: "READ_ONLY" /* READ_ONLY */,
|
|
147
|
+
riskLevel: "SAFE" /* SAFE */,
|
|
148
|
+
syntax: "ps [OPTIONS]",
|
|
149
|
+
commonFlags: [
|
|
150
|
+
{ flag: "aux", description: "All processes with details" },
|
|
151
|
+
{ flag: "-ef", description: "Full format listing" },
|
|
152
|
+
{ flag: "-p", description: "Select by PID", argument: "pid" },
|
|
153
|
+
{ flag: "-u", description: "Select by user", argument: "user" }
|
|
154
|
+
],
|
|
155
|
+
examples: [
|
|
156
|
+
{ command: "ps aux", description: "Show all processes", risk: "SAFE" /* SAFE */ },
|
|
157
|
+
{ command: "ps -ef | grep nginx", description: "Find nginx processes", risk: "SAFE" /* SAFE */ }
|
|
158
|
+
],
|
|
159
|
+
requiresSudo: false,
|
|
160
|
+
alternatives: ["top", "htop", "pgrep"],
|
|
161
|
+
safetyNotes: ["Read-only operation", "Safe for monitoring"],
|
|
162
|
+
platform: ["linux", "darwin", "unix"]
|
|
163
|
+
});
|
|
164
|
+
this.commands.set("kill", {
|
|
165
|
+
name: "kill",
|
|
166
|
+
description: "Terminate processes",
|
|
167
|
+
category: "PROCESS" /* PROCESS */,
|
|
168
|
+
riskLevel: "HIGH" /* HIGH */,
|
|
169
|
+
syntax: "kill [OPTIONS] PID...",
|
|
170
|
+
commonFlags: [
|
|
171
|
+
{ flag: "-9", description: "Force kill (SIGKILL)", riskModifier: 2 },
|
|
172
|
+
{ flag: "-15", description: "Graceful termination (SIGTERM)" },
|
|
173
|
+
{ flag: "-l", description: "List signal names" },
|
|
174
|
+
{ flag: "-s", description: "Specify signal", argument: "signal" }
|
|
175
|
+
],
|
|
176
|
+
examples: [
|
|
177
|
+
{ command: "kill 1234", description: "Terminate process 1234", risk: "MEDIUM" /* MEDIUM */ },
|
|
178
|
+
{ command: "kill -9 1234", description: "Force kill process 1234", risk: "HIGH" /* HIGH */ }
|
|
179
|
+
],
|
|
180
|
+
requiresSudo: false,
|
|
181
|
+
alternatives: ["killall", "pkill", "systemctl stop"],
|
|
182
|
+
safetyNotes: [
|
|
183
|
+
"Can cause data loss if process is writing",
|
|
184
|
+
"Try graceful termination first",
|
|
185
|
+
"Never kill system critical processes",
|
|
186
|
+
"Verify PID before killing"
|
|
187
|
+
],
|
|
188
|
+
platform: ["linux", "darwin", "unix"]
|
|
189
|
+
});
|
|
190
|
+
this.commands.set("systemctl", {
|
|
191
|
+
name: "systemctl",
|
|
192
|
+
description: "Control systemd services",
|
|
193
|
+
category: "SYSTEM_MODIFY" /* SYSTEM_MODIFY */,
|
|
194
|
+
riskLevel: "MEDIUM" /* MEDIUM */,
|
|
195
|
+
syntax: "systemctl [OPTIONS] COMMAND [SERVICE]",
|
|
196
|
+
commonFlags: [
|
|
197
|
+
{ flag: "status", description: "Show service status" },
|
|
198
|
+
{ flag: "start", description: "Start service", riskModifier: 1 },
|
|
199
|
+
{ flag: "stop", description: "Stop service", riskModifier: 2 },
|
|
200
|
+
{ flag: "restart", description: "Restart service", riskModifier: 2 },
|
|
201
|
+
{ flag: "enable", description: "Enable at boot", riskModifier: 1 },
|
|
202
|
+
{ flag: "disable", description: "Disable at boot", riskModifier: 1 }
|
|
203
|
+
],
|
|
204
|
+
examples: [
|
|
205
|
+
{ command: "systemctl status nginx", description: "Check nginx status", risk: "SAFE" /* SAFE */ },
|
|
206
|
+
{ command: "systemctl restart mysql", description: "Restart MySQL", risk: "MEDIUM" /* MEDIUM */ }
|
|
207
|
+
],
|
|
208
|
+
requiresSudo: true,
|
|
209
|
+
alternatives: ["service", "init.d scripts", "supervisorctl"],
|
|
210
|
+
safetyNotes: [
|
|
211
|
+
"Can affect system availability",
|
|
212
|
+
"Check dependencies before stopping",
|
|
213
|
+
"Some services are critical for system operation"
|
|
214
|
+
],
|
|
215
|
+
platform: ["linux"]
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
initializeNetworkCommands() {
|
|
219
|
+
this.commands.set("netstat", {
|
|
220
|
+
name: "netstat",
|
|
221
|
+
description: "Display network connections",
|
|
222
|
+
category: "READ_ONLY" /* READ_ONLY */,
|
|
223
|
+
riskLevel: "SAFE" /* SAFE */,
|
|
224
|
+
syntax: "netstat [OPTIONS]",
|
|
225
|
+
commonFlags: [
|
|
226
|
+
{ flag: "-t", description: "TCP connections" },
|
|
227
|
+
{ flag: "-u", description: "UDP connections" },
|
|
228
|
+
{ flag: "-l", description: "Listening ports" },
|
|
229
|
+
{ flag: "-n", description: "Numerical addresses" },
|
|
230
|
+
{ flag: "-p", description: "Show process info" },
|
|
231
|
+
{ flag: "-a", description: "All connections" }
|
|
232
|
+
],
|
|
233
|
+
examples: [
|
|
234
|
+
{ command: "netstat -tuln", description: "Show listening ports", risk: "SAFE" /* SAFE */ },
|
|
235
|
+
{ command: "netstat -anp | grep :80", description: "Find process on port 80", risk: "SAFE" /* SAFE */ }
|
|
236
|
+
],
|
|
237
|
+
requiresSudo: false,
|
|
238
|
+
alternatives: ["ss", "lsof -i", "sockstat"],
|
|
239
|
+
safetyNotes: ["Read-only operation", "May require sudo for process info"],
|
|
240
|
+
platform: ["linux", "darwin", "unix"]
|
|
241
|
+
});
|
|
242
|
+
this.commands.set("iptables", {
|
|
243
|
+
name: "iptables",
|
|
244
|
+
description: "Configure Linux firewall",
|
|
245
|
+
category: "SECURITY" /* SECURITY */,
|
|
246
|
+
riskLevel: "CRITICAL" /* CRITICAL */,
|
|
247
|
+
syntax: "iptables [OPTIONS] [CHAIN] [RULE]",
|
|
248
|
+
commonFlags: [
|
|
249
|
+
{ flag: "-L", description: "List rules" },
|
|
250
|
+
{ flag: "-A", description: "Append rule", riskModifier: 3 },
|
|
251
|
+
{ flag: "-D", description: "Delete rule", riskModifier: 3 },
|
|
252
|
+
{ flag: "-F", description: "Flush all rules", riskModifier: 5 },
|
|
253
|
+
{ flag: "-P", description: "Set default policy", riskModifier: 4 }
|
|
254
|
+
],
|
|
255
|
+
examples: [
|
|
256
|
+
{ command: "iptables -L", description: "List firewall rules", risk: "SAFE" /* SAFE */ },
|
|
257
|
+
{ command: "iptables -A INPUT -p tcp --dport 22 -j ACCEPT", description: "Allow SSH", risk: "HIGH" /* HIGH */ }
|
|
258
|
+
],
|
|
259
|
+
requiresSudo: true,
|
|
260
|
+
alternatives: ["ufw", "firewalld", "nftables"],
|
|
261
|
+
safetyNotes: [
|
|
262
|
+
"Can lock you out of system",
|
|
263
|
+
"Always have backup access",
|
|
264
|
+
"Test rules before applying permanently",
|
|
265
|
+
"Incorrect rules can break networking"
|
|
266
|
+
],
|
|
267
|
+
platform: ["linux"]
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
initializeSystemCommands() {
|
|
271
|
+
this.commands.set("df", {
|
|
272
|
+
name: "df",
|
|
273
|
+
description: "Display disk space usage",
|
|
274
|
+
category: "READ_ONLY" /* READ_ONLY */,
|
|
275
|
+
riskLevel: "SAFE" /* SAFE */,
|
|
276
|
+
syntax: "df [OPTIONS] [FILE]...",
|
|
277
|
+
commonFlags: [
|
|
278
|
+
{ flag: "-h", description: "Human readable sizes" },
|
|
279
|
+
{ flag: "-T", description: "Show filesystem type" },
|
|
280
|
+
{ flag: "-i", description: "Show inode information" },
|
|
281
|
+
{ flag: "-a", description: "Include all filesystems" }
|
|
282
|
+
],
|
|
283
|
+
examples: [
|
|
284
|
+
{ command: "df -h", description: "Show disk usage in human format", risk: "SAFE" /* SAFE */ },
|
|
285
|
+
{ command: "df -hT /", description: "Show root filesystem details", risk: "SAFE" /* SAFE */ }
|
|
286
|
+
],
|
|
287
|
+
requiresSudo: false,
|
|
288
|
+
alternatives: ["du", "lsblk", "fdisk -l"],
|
|
289
|
+
safetyNotes: ["Read-only operation", "Safe for all users"],
|
|
290
|
+
platform: ["linux", "darwin", "unix"]
|
|
291
|
+
});
|
|
292
|
+
this.commands.set("mount", {
|
|
293
|
+
name: "mount",
|
|
294
|
+
description: "Mount filesystems",
|
|
295
|
+
category: "SYSTEM_MODIFY" /* SYSTEM_MODIFY */,
|
|
296
|
+
riskLevel: "HIGH" /* HIGH */,
|
|
297
|
+
syntax: "mount [OPTIONS] DEVICE MOUNTPOINT",
|
|
298
|
+
commonFlags: [
|
|
299
|
+
{ flag: "-t", description: "Filesystem type", argument: "type" },
|
|
300
|
+
{ flag: "-o", description: "Mount options", argument: "options" },
|
|
301
|
+
{ flag: "-r", description: "Read-only mount", riskModifier: -1 },
|
|
302
|
+
{ flag: "-a", description: "Mount all in fstab", riskModifier: 2 }
|
|
303
|
+
],
|
|
304
|
+
examples: [
|
|
305
|
+
{ command: "mount", description: "Show mounted filesystems", risk: "SAFE" /* SAFE */ },
|
|
306
|
+
{ command: "mount /dev/sdb1 /mnt", description: "Mount device to /mnt", risk: "HIGH" /* HIGH */ }
|
|
307
|
+
],
|
|
308
|
+
requiresSudo: true,
|
|
309
|
+
alternatives: ["umount", "findmnt", "lsblk"],
|
|
310
|
+
safetyNotes: [
|
|
311
|
+
"Can overwrite existing mount points",
|
|
312
|
+
"Verify device before mounting",
|
|
313
|
+
"Incorrect options can corrupt data",
|
|
314
|
+
"Always unmount before removal"
|
|
315
|
+
],
|
|
316
|
+
platform: ["linux", "unix"]
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
initializeWorkflows() {
|
|
320
|
+
this.workflows.set("system-health-check", {
|
|
321
|
+
name: "system-health-check",
|
|
322
|
+
description: "Comprehensive system health assessment",
|
|
323
|
+
steps: [
|
|
324
|
+
this.createCommand("uptime", [], "SAFE" /* SAFE */),
|
|
325
|
+
this.createCommand("free", ["-h"], "SAFE" /* SAFE */),
|
|
326
|
+
this.createCommand("df", ["-h"], "SAFE" /* SAFE */),
|
|
327
|
+
this.createCommand("ps", ["aux", "--sort=-pcpu", "|", "head", "-10"], "SAFE" /* SAFE */),
|
|
328
|
+
this.createCommand("netstat", ["-tuln"], "SAFE" /* SAFE */),
|
|
329
|
+
this.createCommand("systemctl", ["list-units", "--failed"], "SAFE" /* SAFE */)
|
|
330
|
+
],
|
|
331
|
+
conditions: [
|
|
332
|
+
{
|
|
333
|
+
type: "pre",
|
|
334
|
+
check: "command -v systemctl",
|
|
335
|
+
onFail: "skip"
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
});
|
|
339
|
+
this.workflows.set("disk-cleanup", {
|
|
340
|
+
name: "disk-cleanup",
|
|
341
|
+
description: "Free up disk space safely",
|
|
342
|
+
steps: [
|
|
343
|
+
this.createCommand("df", ["-h"], "SAFE" /* SAFE */),
|
|
344
|
+
this.createCommand("du", ["-sh", "/var/log/*"], "SAFE" /* SAFE */),
|
|
345
|
+
this.createCommand("find", ["/tmp", "-type", "f", "-mtime", "+7", "-size", "+10M"], "SAFE" /* SAFE */),
|
|
346
|
+
this.createCommand("journalctl", ["--vacuum-time=7d"], "MEDIUM" /* MEDIUM */),
|
|
347
|
+
this.createCommand("apt", ["autoremove", "-y"], "MEDIUM" /* MEDIUM */),
|
|
348
|
+
this.createCommand("apt", ["clean"], "LOW" /* LOW */)
|
|
349
|
+
],
|
|
350
|
+
rollback: [
|
|
351
|
+
this.createCommand("echo", ["Cleanup completed, no rollback needed"], "SAFE" /* SAFE */)
|
|
352
|
+
],
|
|
353
|
+
conditions: [
|
|
354
|
+
{
|
|
355
|
+
type: "pre",
|
|
356
|
+
check: 'test $(df / | awk "NR==2 {print $5}" | sed "s/%//") -gt 80',
|
|
357
|
+
onFail: "abort"
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
});
|
|
361
|
+
this.workflows.set("security-audit", {
|
|
362
|
+
name: "security-audit",
|
|
363
|
+
description: "Basic security assessment",
|
|
364
|
+
steps: [
|
|
365
|
+
this.createCommand("who", [], "SAFE" /* SAFE */),
|
|
366
|
+
this.createCommand("last", ["-10"], "SAFE" /* SAFE */),
|
|
367
|
+
this.createCommand("netstat", ["-tuln"], "SAFE" /* SAFE */),
|
|
368
|
+
this.createCommand("ps", ["aux", "|", "grep", "root"], "SAFE" /* SAFE */),
|
|
369
|
+
this.createCommand("find", ["/", "-perm", "-4000", "-type", "f", "2>/dev/null"], "SAFE" /* SAFE */),
|
|
370
|
+
this.createCommand("iptables", ["-L", "-n"], "SAFE" /* SAFE */)
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
initializeSafetyGuidelines() {
|
|
375
|
+
this.safetyGuidelines.set("rm", {
|
|
376
|
+
command: "rm",
|
|
377
|
+
guidelines: [
|
|
378
|
+
"Always use absolute paths when possible",
|
|
379
|
+
"Verify path with ls first",
|
|
380
|
+
"Use -i flag for interactive confirmation",
|
|
381
|
+
"Consider using trash-cli instead",
|
|
382
|
+
"Never use variables in rm commands without validation"
|
|
383
|
+
],
|
|
384
|
+
forbiddenPatterns: [
|
|
385
|
+
/rm\s+-rf\s+\/$/,
|
|
386
|
+
/rm\s+-rf\s+\/\*/,
|
|
387
|
+
/rm\s+-rf\s+~$/,
|
|
388
|
+
/rm\s+-rf\s+\$HOME$/
|
|
389
|
+
],
|
|
390
|
+
requiresConfirmation: true,
|
|
391
|
+
backupRequired: true
|
|
392
|
+
});
|
|
393
|
+
this.safetyGuidelines.set("chmod", {
|
|
394
|
+
command: "chmod",
|
|
395
|
+
guidelines: [
|
|
396
|
+
"Understand permission implications",
|
|
397
|
+
"Never use 777 on system files",
|
|
398
|
+
"Test on non-critical files first",
|
|
399
|
+
"Use symbolic notation when unsure"
|
|
400
|
+
],
|
|
401
|
+
forbiddenPatterns: [
|
|
402
|
+
/chmod\s+777\s+\//,
|
|
403
|
+
/chmod\s+-R\s+777/,
|
|
404
|
+
/chmod\s+000\s+\//
|
|
405
|
+
],
|
|
406
|
+
requiresConfirmation: true,
|
|
407
|
+
backupRequired: false
|
|
408
|
+
});
|
|
409
|
+
this.safetyGuidelines.set("dd", {
|
|
410
|
+
command: "dd",
|
|
411
|
+
guidelines: [
|
|
412
|
+
"Double-check input and output devices",
|
|
413
|
+
"Never confuse if= and of=",
|
|
414
|
+
"Use conv=sync,noerror for recovery",
|
|
415
|
+
"Always specify block size"
|
|
416
|
+
],
|
|
417
|
+
forbiddenPatterns: [
|
|
418
|
+
/dd\s+.*of=\/dev\/[sh]da$/
|
|
419
|
+
],
|
|
420
|
+
requiresConfirmation: true,
|
|
421
|
+
backupRequired: true
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
initializeAlternatives() {
|
|
425
|
+
this.alternatives.set("rm", {
|
|
426
|
+
original: "rm",
|
|
427
|
+
alternatives: [
|
|
428
|
+
{
|
|
429
|
+
command: "trash-cli",
|
|
430
|
+
reason: "Moves files to trash instead of permanent deletion",
|
|
431
|
+
pros: ["Recoverable", "Safer", "User-friendly"],
|
|
432
|
+
cons: ["Requires installation", "Uses more disk space temporarily"],
|
|
433
|
+
preferredWhen: "Working with important files or uncertain about deletion"
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
command: "mv to /tmp",
|
|
437
|
+
reason: "Move files to temp directory for later cleanup",
|
|
438
|
+
pros: ["Recoverable until reboot", "No additional tools needed"],
|
|
439
|
+
cons: ["Manual cleanup needed", "/tmp has size limits"],
|
|
440
|
+
preferredWhen: "Need temporary safety net without installing tools"
|
|
441
|
+
}
|
|
442
|
+
]
|
|
443
|
+
});
|
|
444
|
+
this.alternatives.set("netstat", {
|
|
445
|
+
original: "netstat",
|
|
446
|
+
alternatives: [
|
|
447
|
+
{
|
|
448
|
+
command: "ss",
|
|
449
|
+
reason: "Modern replacement for netstat with better performance",
|
|
450
|
+
pros: ["Faster", "More features", "Better TCP state info"],
|
|
451
|
+
cons: ["Different syntax", "Not available on older systems"],
|
|
452
|
+
preferredWhen: "Working on modern Linux systems"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
command: "lsof -i",
|
|
456
|
+
reason: "Shows network connections with process details",
|
|
457
|
+
pros: ["Detailed process info", "Cross-platform"],
|
|
458
|
+
cons: ["Slower", "More verbose output"],
|
|
459
|
+
preferredWhen: "Need detailed process and file descriptor info"
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
});
|
|
463
|
+
this.alternatives.set("ps", {
|
|
464
|
+
original: "ps",
|
|
465
|
+
alternatives: [
|
|
466
|
+
{
|
|
467
|
+
command: "top",
|
|
468
|
+
reason: "Real-time process monitoring",
|
|
469
|
+
pros: ["Live updates", "Interactive", "CPU/Memory sorting"],
|
|
470
|
+
cons: ["Not scriptable", "Terminal-based only"],
|
|
471
|
+
preferredWhen: "Interactive monitoring and troubleshooting"
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
command: "htop",
|
|
475
|
+
reason: "Enhanced interactive process viewer",
|
|
476
|
+
pros: ["Better UI", "Tree view", "Mouse support"],
|
|
477
|
+
cons: ["Requires installation", "Not scriptable"],
|
|
478
|
+
preferredWhen: "Interactive monitoring with better visualization"
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
command: "pgrep/pkill",
|
|
482
|
+
reason: "Process selection by pattern",
|
|
483
|
+
pros: ["Simple pattern matching", "Scriptable"],
|
|
484
|
+
cons: ["Limited output format", "Less detail"],
|
|
485
|
+
preferredWhen: "Finding or killing processes by name"
|
|
486
|
+
}
|
|
487
|
+
]
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
createCommand(command, args, risk) {
|
|
491
|
+
return {
|
|
492
|
+
command,
|
|
493
|
+
args,
|
|
494
|
+
flags: [],
|
|
495
|
+
sudo: false,
|
|
496
|
+
risk,
|
|
497
|
+
category: "READ_ONLY" /* READ_ONLY */,
|
|
498
|
+
description: ""
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
getCommand(name) {
|
|
502
|
+
if (!name) return void 0;
|
|
503
|
+
return this.commands.get(name);
|
|
504
|
+
}
|
|
505
|
+
getWorkflow(name) {
|
|
506
|
+
return this.workflows.get(name);
|
|
507
|
+
}
|
|
508
|
+
getSafetyGuidelines(command) {
|
|
509
|
+
return this.safetyGuidelines.get(command);
|
|
510
|
+
}
|
|
511
|
+
getAlternatives(command) {
|
|
512
|
+
return this.alternatives.get(command);
|
|
513
|
+
}
|
|
514
|
+
searchCommands(query) {
|
|
515
|
+
const results = [];
|
|
516
|
+
const lowerQuery = query.toLowerCase();
|
|
517
|
+
for (const cmd of this.commands.values()) {
|
|
518
|
+
if (cmd.name.includes(lowerQuery) || cmd.description.toLowerCase().includes(lowerQuery)) {
|
|
519
|
+
results.push(cmd);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return results;
|
|
523
|
+
}
|
|
524
|
+
getCommandsByCategory(category) {
|
|
525
|
+
return Array.from(this.commands.values()).filter(
|
|
526
|
+
(cmd) => cmd.category === category
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
getCommandsByRiskLevel(maxRisk) {
|
|
530
|
+
const riskOrder = {
|
|
531
|
+
["SAFE" /* SAFE */]: 0,
|
|
532
|
+
["LOW" /* LOW */]: 1,
|
|
533
|
+
["MEDIUM" /* MEDIUM */]: 2,
|
|
534
|
+
["HIGH" /* HIGH */]: 3,
|
|
535
|
+
["CRITICAL" /* CRITICAL */]: 4
|
|
536
|
+
};
|
|
537
|
+
const maxRiskValue = riskOrder[maxRisk];
|
|
538
|
+
return Array.from(this.commands.values()).filter(
|
|
539
|
+
(cmd) => riskOrder[cmd.riskLevel] <= maxRiskValue
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
validateCommand(commandString) {
|
|
543
|
+
const parts = commandString.split(/\s+/);
|
|
544
|
+
const cmdName = parts[0];
|
|
545
|
+
const cmd = cmdName ? this.commands.get(cmdName) : void 0;
|
|
546
|
+
if (!cmd) {
|
|
547
|
+
return {
|
|
548
|
+
valid: false,
|
|
549
|
+
risk: "SAFE" /* SAFE */,
|
|
550
|
+
warnings: [`Unknown command: ${cmdName}`]
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const warnings = [];
|
|
554
|
+
const guidelines = cmdName ? this.safetyGuidelines.get(cmdName) : void 0;
|
|
555
|
+
if (guidelines) {
|
|
556
|
+
for (const pattern of guidelines.forbiddenPatterns) {
|
|
557
|
+
if (pattern.test(commandString)) {
|
|
558
|
+
warnings.push(`DANGEROUS: This command matches forbidden pattern: ${pattern}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
let risk = cmd ? cmd.riskLevel : "SAFE" /* SAFE */;
|
|
563
|
+
for (const part of parts.slice(1)) {
|
|
564
|
+
for (const flag of cmd ? cmd.commonFlags : []) {
|
|
565
|
+
if (part === flag.flag && flag.riskModifier) {
|
|
566
|
+
const riskOrder = ["SAFE" /* SAFE */, "LOW" /* LOW */, "MEDIUM" /* MEDIUM */, "HIGH" /* HIGH */, "CRITICAL" /* CRITICAL */];
|
|
567
|
+
const currentIndex = riskOrder.indexOf(risk);
|
|
568
|
+
const newIndex = Math.min(4, Math.max(0, currentIndex + flag.riskModifier));
|
|
569
|
+
risk = riskOrder[newIndex] || "SAFE" /* SAFE */;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
valid: warnings.length === 0,
|
|
575
|
+
risk,
|
|
576
|
+
warnings
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
suggestAlternative(command) {
|
|
580
|
+
const alt = this.alternatives.get(command);
|
|
581
|
+
return alt ? alt.alternatives : [];
|
|
582
|
+
}
|
|
583
|
+
getAllWorkflows() {
|
|
584
|
+
return Array.from(this.workflows.values());
|
|
585
|
+
}
|
|
586
|
+
exportKnowledge() {
|
|
587
|
+
return {
|
|
588
|
+
commands: Array.from(this.commands.values()),
|
|
589
|
+
workflows: Array.from(this.workflows.values()),
|
|
590
|
+
guidelines: Array.from(this.safetyGuidelines.values())
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
exports.CommandKnowledgeBase = CommandKnowledgeBase;
|
|
596
|
+
//# sourceMappingURL=command-knowledge-base.js.map
|
|
597
|
+
//# sourceMappingURL=command-knowledge-base.js.map
|