@mako10k/shell-server 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 +21 -0
- package/README.md +114 -0
- package/dist/backoffice/index.d.ts +2 -0
- package/dist/backoffice/index.d.ts.map +1 -0
- package/dist/backoffice/index.js +47 -0
- package/dist/backoffice/index.js.map +1 -0
- package/dist/backoffice/server.d.ts +45 -0
- package/dist/backoffice/server.d.ts.map +1 -0
- package/dist/backoffice/server.js +610 -0
- package/dist/backoffice/server.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +525 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/config-manager.d.ts +80 -0
- package/dist/core/config-manager.d.ts.map +1 -0
- package/dist/core/config-manager.js +218 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/enhanced-history-manager.d.ts +84 -0
- package/dist/core/enhanced-history-manager.d.ts.map +1 -0
- package/dist/core/enhanced-history-manager.js +319 -0
- package/dist/core/enhanced-history-manager.js.map +1 -0
- package/dist/core/file-manager.d.ts +79 -0
- package/dist/core/file-manager.d.ts.map +1 -0
- package/dist/core/file-manager.js +338 -0
- package/dist/core/file-manager.js.map +1 -0
- package/dist/core/file-storage-subscriber.d.ts +38 -0
- package/dist/core/file-storage-subscriber.d.ts.map +1 -0
- package/dist/core/file-storage-subscriber.js +132 -0
- package/dist/core/file-storage-subscriber.js.map +1 -0
- package/dist/core/monitoring-manager.d.ts +32 -0
- package/dist/core/monitoring-manager.d.ts.map +1 -0
- package/dist/core/monitoring-manager.js +296 -0
- package/dist/core/monitoring-manager.js.map +1 -0
- package/dist/core/process-manager.d.ts +105 -0
- package/dist/core/process-manager.d.ts.map +1 -0
- package/dist/core/process-manager.js +1374 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/realtime-stream-subscriber.d.ts +93 -0
- package/dist/core/realtime-stream-subscriber.d.ts.map +1 -0
- package/dist/core/realtime-stream-subscriber.js +200 -0
- package/dist/core/realtime-stream-subscriber.js.map +1 -0
- package/dist/core/remote-http-client.d.ts +15 -0
- package/dist/core/remote-http-client.d.ts.map +1 -0
- package/dist/core/remote-http-client.js +60 -0
- package/dist/core/remote-http-client.js.map +1 -0
- package/dist/core/remote-process-service.d.ts +50 -0
- package/dist/core/remote-process-service.d.ts.map +1 -0
- package/dist/core/remote-process-service.js +20 -0
- package/dist/core/remote-process-service.js.map +1 -0
- package/dist/core/server-manager.d.ts +71 -0
- package/dist/core/server-manager.d.ts.map +1 -0
- package/dist/core/server-manager.js +680 -0
- package/dist/core/server-manager.js.map +1 -0
- package/dist/core/stream-publisher.d.ts +75 -0
- package/dist/core/stream-publisher.d.ts.map +1 -0
- package/dist/core/stream-publisher.js +127 -0
- package/dist/core/stream-publisher.js.map +1 -0
- package/dist/core/streaming-pipeline-reader.d.ts +67 -0
- package/dist/core/streaming-pipeline-reader.d.ts.map +1 -0
- package/dist/core/streaming-pipeline-reader.js +191 -0
- package/dist/core/streaming-pipeline-reader.js.map +1 -0
- package/dist/core/terminal-manager.d.ts +96 -0
- package/dist/core/terminal-manager.d.ts.map +1 -0
- package/dist/core/terminal-manager.js +515 -0
- package/dist/core/terminal-manager.js.map +1 -0
- package/dist/daemon/server.d.ts +8 -0
- package/dist/daemon/server.d.ts.map +1 -0
- package/dist/daemon/server.js +416 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/uds-transport.d.ts +31 -0
- package/dist/daemon/uds-transport.d.ts.map +1 -0
- package/dist/daemon/uds-transport.js +149 -0
- package/dist/daemon/uds-transport.js.map +1 -0
- package/dist/executor/server.d.ts +20 -0
- package/dist/executor/server.d.ts.map +1 -0
- package/dist/executor/server.js +375 -0
- package/dist/executor/server.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/daemon-runtime.d.ts +4 -0
- package/dist/runtime/daemon-runtime.d.ts.map +1 -0
- package/dist/runtime/daemon-runtime.js +4 -0
- package/dist/runtime/daemon-runtime.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/tool-runtime.d.ts +52 -0
- package/dist/runtime/tool-runtime.d.ts.map +1 -0
- package/dist/runtime/tool-runtime.js +161 -0
- package/dist/runtime/tool-runtime.js.map +1 -0
- package/dist/security/chat-completion-adapter.d.ts +443 -0
- package/dist/security/chat-completion-adapter.d.ts.map +1 -0
- package/dist/security/chat-completion-adapter.js +475 -0
- package/dist/security/chat-completion-adapter.js.map +1 -0
- package/dist/security/enhanced-evaluator.d.ts +139 -0
- package/dist/security/enhanced-evaluator.d.ts.map +1 -0
- package/dist/security/enhanced-evaluator.js +1208 -0
- package/dist/security/enhanced-evaluator.js.map +1 -0
- package/dist/security/evaluator-types.d.ts +614 -0
- package/dist/security/evaluator-types.d.ts.map +1 -0
- package/dist/security/evaluator-types.js +124 -0
- package/dist/security/evaluator-types.js.map +1 -0
- package/dist/security/manager.d.ts +76 -0
- package/dist/security/manager.d.ts.map +1 -0
- package/dist/security/manager.js +445 -0
- package/dist/security/manager.js.map +1 -0
- package/dist/security/security-llm-prompt-generator.d.ts +105 -0
- package/dist/security/security-llm-prompt-generator.d.ts.map +1 -0
- package/dist/security/security-llm-prompt-generator.js +323 -0
- package/dist/security/security-llm-prompt-generator.js.map +1 -0
- package/dist/security/security-tools.d.ts +174 -0
- package/dist/security/security-tools.d.ts.map +1 -0
- package/dist/security/security-tools.js +159 -0
- package/dist/security/security-tools.js.map +1 -0
- package/dist/security/validator-criteria-manager.d.ts +47 -0
- package/dist/security/validator-criteria-manager.d.ts.map +1 -0
- package/dist/security/validator-criteria-manager.js +169 -0
- package/dist/security/validator-criteria-manager.js.map +1 -0
- package/dist/tools/shell-tools.d.ts +474 -0
- package/dist/tools/shell-tools.d.ts.map +1 -0
- package/dist/tools/shell-tools.js +861 -0
- package/dist/tools/shell-tools.js.map +1 -0
- package/dist/types/enhanced-security.d.ts +529 -0
- package/dist/types/enhanced-security.d.ts.map +1 -0
- package/dist/types/enhanced-security.js +286 -0
- package/dist/types/enhanced-security.js.map +1 -0
- package/dist/types/index.d.ts +282 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +158 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/quick-schemas.d.ts +177 -0
- package/dist/types/quick-schemas.d.ts.map +1 -0
- package/dist/types/quick-schemas.js +113 -0
- package/dist/types/quick-schemas.js.map +1 -0
- package/dist/types/response-schemas.d.ts +41 -0
- package/dist/types/response-schemas.d.ts.map +1 -0
- package/dist/types/response-schemas.js +41 -0
- package/dist/types/response-schemas.js.map +1 -0
- package/dist/types/schemas.d.ts +578 -0
- package/dist/types/schemas.d.ts.map +1 -0
- package/dist/types/schemas.js +498 -0
- package/dist/types/schemas.js.map +1 -0
- package/dist/utils/criteria-manager.d.ts +47 -0
- package/dist/utils/criteria-manager.d.ts.map +1 -0
- package/dist/utils/criteria-manager.js +228 -0
- package/dist/utils/criteria-manager.js.map +1 -0
- package/dist/utils/errors.d.ts +27 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +67 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/helpers.d.ts +85 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +400 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/json-repair.d.ts +23 -0
- package/dist/utils/json-repair.d.ts.map +1 -0
- package/dist/utils/json-repair.js +208 -0
- package/dist/utils/json-repair.js.map +1 -0
- package/dist/utils/process-utils.d.ts +31 -0
- package/dist/utils/process-utils.d.ts.map +1 -0
- package/dist/utils/process-utils.js +217 -0
- package/dist/utils/process-utils.js.map +1 -0
- package/dist/utils/server-helpers.d.ts +4 -0
- package/dist/utils/server-helpers.d.ts.map +1 -0
- package/dist/utils/server-helpers.js +10 -0
- package/dist/utils/server-helpers.js.map +1 -0
- package/dist/utils/sse.d.ts +2 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +6 -0
- package/dist/utils/sse.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ShellServerConfigSchema, DEFAULT_ENHANCED_SECURITY_CONFIG, DEFAULT_BASIC_SAFETY_RULES, } from '../types/enhanced-security.js';
|
|
5
|
+
import { getCurrentTimestamp } from '../utils/helpers.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration Manager for MCP Shell Server Enhanced Security
|
|
8
|
+
* Handles loading, saving, and validating configuration files
|
|
9
|
+
*/
|
|
10
|
+
export class ConfigManager {
|
|
11
|
+
configPath;
|
|
12
|
+
config;
|
|
13
|
+
constructor(configPath) {
|
|
14
|
+
// Default config file path: $HOME/.mcp-shell-server/config.json
|
|
15
|
+
this.configPath = configPath || this.getDefaultConfigPath();
|
|
16
|
+
this.config = this.getDefaultConfig();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get default configuration file path
|
|
20
|
+
*/
|
|
21
|
+
getDefaultConfigPath() {
|
|
22
|
+
const homeDir = process.env['HOME'] || process.env['USERPROFILE'] || '.';
|
|
23
|
+
const configDir = path.join(homeDir, '.mcp-shell-server');
|
|
24
|
+
return path.join(configDir, 'config.json');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get default configuration
|
|
28
|
+
*/
|
|
29
|
+
getDefaultConfig() {
|
|
30
|
+
return {
|
|
31
|
+
server: {
|
|
32
|
+
name: 'MCP Shell Server',
|
|
33
|
+
version: '2.2.0',
|
|
34
|
+
},
|
|
35
|
+
enhanced_security: { ...DEFAULT_ENHANCED_SECURITY_CONFIG },
|
|
36
|
+
basic_safety_rules: [...DEFAULT_BASIC_SAFETY_RULES],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Load configuration from file
|
|
41
|
+
*/
|
|
42
|
+
async loadConfig() {
|
|
43
|
+
try {
|
|
44
|
+
// Check if config file exists
|
|
45
|
+
await fs.access(this.configPath);
|
|
46
|
+
// Read file content
|
|
47
|
+
const configData = await fs.readFile(this.configPath, 'utf-8');
|
|
48
|
+
const rawConfig = JSON.parse(configData);
|
|
49
|
+
// Validate with Zod schema
|
|
50
|
+
const validatedConfig = ShellServerConfigSchema.parse(rawConfig);
|
|
51
|
+
this.config = validatedConfig;
|
|
52
|
+
return this.config;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof z.ZodError) {
|
|
56
|
+
throw new Error(`Configuration validation failed: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
// Return default config if file doesn't exist
|
|
59
|
+
if (error.code === 'ENOENT') {
|
|
60
|
+
console.warn(`Configuration file not found at ${this.configPath}, using defaults`);
|
|
61
|
+
await this.saveConfig(); // Create default config file
|
|
62
|
+
return this.config;
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Failed to load configuration: ${error}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Save configuration to file
|
|
69
|
+
*/
|
|
70
|
+
async saveConfig(config) {
|
|
71
|
+
const configToSave = config || this.config;
|
|
72
|
+
try {
|
|
73
|
+
// Validate with Zod schema
|
|
74
|
+
const validatedConfig = ShellServerConfigSchema.parse(configToSave);
|
|
75
|
+
// Create directory if it doesn't exist
|
|
76
|
+
const configDir = path.dirname(this.configPath);
|
|
77
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
78
|
+
// Save to file (formatted JSON)
|
|
79
|
+
const configJson = JSON.stringify(validatedConfig, null, 2);
|
|
80
|
+
await fs.writeFile(this.configPath, configJson, 'utf-8');
|
|
81
|
+
this.config = validatedConfig;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error instanceof z.ZodError) {
|
|
85
|
+
throw new Error(`Configuration validation failed: ${error.message}`);
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`Failed to save configuration: ${error}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get current configuration
|
|
92
|
+
*/
|
|
93
|
+
getConfig() {
|
|
94
|
+
return { ...this.config };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get enhanced security configuration
|
|
98
|
+
*/
|
|
99
|
+
getEnhancedSecurityConfig() {
|
|
100
|
+
return { ...(this.config.enhanced_security || DEFAULT_ENHANCED_SECURITY_CONFIG) };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Update enhanced security configuration
|
|
104
|
+
*/
|
|
105
|
+
async updateEnhancedSecurityConfig(updates, saveToFile = true) {
|
|
106
|
+
const currentConfig = this.getEnhancedSecurityConfig();
|
|
107
|
+
const newConfig = {
|
|
108
|
+
...currentConfig,
|
|
109
|
+
...updates,
|
|
110
|
+
safety_level_thresholds: {
|
|
111
|
+
...currentConfig.safety_level_thresholds,
|
|
112
|
+
...updates.safety_level_thresholds,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
this.config.enhanced_security = newConfig;
|
|
116
|
+
if (saveToFile) {
|
|
117
|
+
await this.saveConfig();
|
|
118
|
+
}
|
|
119
|
+
return newConfig;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get basic safety rules
|
|
123
|
+
*/
|
|
124
|
+
getBasicSafetyRules() {
|
|
125
|
+
return [...(this.config.basic_safety_rules || DEFAULT_BASIC_SAFETY_RULES)];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Update basic safety rules
|
|
129
|
+
*/
|
|
130
|
+
async updateBasicSafetyRules(rules, saveToFile = true) {
|
|
131
|
+
this.config.basic_safety_rules = [...rules];
|
|
132
|
+
if (saveToFile) {
|
|
133
|
+
await this.saveConfig();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get configuration file path
|
|
138
|
+
*/
|
|
139
|
+
getConfigPath() {
|
|
140
|
+
return this.configPath;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if configuration file exists
|
|
144
|
+
*/
|
|
145
|
+
async configExists() {
|
|
146
|
+
try {
|
|
147
|
+
await fs.access(this.configPath);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Reset configuration to defaults
|
|
156
|
+
*/
|
|
157
|
+
async resetToDefaults(saveToFile = true) {
|
|
158
|
+
this.config = this.getDefaultConfig();
|
|
159
|
+
if (saveToFile) {
|
|
160
|
+
await this.saveConfig();
|
|
161
|
+
}
|
|
162
|
+
return this.config;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create backup of current configuration
|
|
166
|
+
*/
|
|
167
|
+
async createBackup() {
|
|
168
|
+
const timestamp = getCurrentTimestamp().replace(/[:.]/g, '-');
|
|
169
|
+
const backupPath = `${this.configPath}.backup.${timestamp}`;
|
|
170
|
+
try {
|
|
171
|
+
await fs.copyFile(this.configPath, backupPath);
|
|
172
|
+
return backupPath;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
throw new Error(`Failed to create backup: ${error}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get configuration file statistics
|
|
180
|
+
*/
|
|
181
|
+
async getConfigStats() {
|
|
182
|
+
try {
|
|
183
|
+
const stats = await fs.stat(this.configPath);
|
|
184
|
+
return {
|
|
185
|
+
exists: true,
|
|
186
|
+
size: stats.size,
|
|
187
|
+
lastModified: stats.mtime,
|
|
188
|
+
path: this.configPath,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
return {
|
|
193
|
+
exists: false,
|
|
194
|
+
size: 0,
|
|
195
|
+
lastModified: null,
|
|
196
|
+
path: this.configPath,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Validate configuration object
|
|
202
|
+
*/
|
|
203
|
+
validateConfig(config) {
|
|
204
|
+
return ShellServerConfigSchema.parse(config);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Singleton instance (optional)
|
|
208
|
+
let globalConfigManager = null;
|
|
209
|
+
/**
|
|
210
|
+
* Get global configuration manager instance
|
|
211
|
+
*/
|
|
212
|
+
export function getGlobalConfigManager(configPath) {
|
|
213
|
+
if (!globalConfigManager) {
|
|
214
|
+
globalConfigManager = new ConfigManager(configPath);
|
|
215
|
+
}
|
|
216
|
+
return globalConfigManager;
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=config-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-manager.js","sourceRoot":"","sources":["../../src/core/config-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,uBAAuB,EAGvB,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,aAAa;IAChB,UAAU,CAAS;IACnB,MAAM,CAAoB;IAElC,YAAY,UAAmB;QAC7B,gEAAgE;QAChE,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACK,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C,UAAU;aACtB,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,MAAe;QAC5B,OAAO,uBAAuB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;CACF;AAED,gCAAgC;AAChC,IAAI,mBAAmB,GAAyB,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAmB;IACxD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,mBAAmB,GAAG,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CommandHistoryEntry, UserConfirmationPattern, EnhancedSecurityConfig } from '../types/enhanced-security.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced Command History Manager
|
|
4
|
+
* Manages command execution history, evaluation results, and user confirmation patterns
|
|
5
|
+
*/
|
|
6
|
+
export declare class CommandHistoryManager {
|
|
7
|
+
private historyPath;
|
|
8
|
+
private history;
|
|
9
|
+
private userPatterns;
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: EnhancedSecurityConfig, historyPath?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Get default history file path
|
|
14
|
+
*/
|
|
15
|
+
private getDefaultHistoryPath;
|
|
16
|
+
/**
|
|
17
|
+
* Load history from file
|
|
18
|
+
*/
|
|
19
|
+
loadHistory(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Save history to file
|
|
22
|
+
*/
|
|
23
|
+
saveHistory(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Add new command history entry
|
|
26
|
+
*/
|
|
27
|
+
addHistoryEntry(entry: Omit<CommandHistoryEntry, 'execution_id' | 'timestamp'>): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Update history entry (add evaluation results, etc.)
|
|
30
|
+
*/
|
|
31
|
+
updateHistoryEntry(executionId: string, updates: Partial<Omit<CommandHistoryEntry, 'execution_id' | 'timestamp'>>): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Search for similar commands in history
|
|
34
|
+
*/
|
|
35
|
+
findSimilarCommands(command: string, limit?: number): CommandHistoryEntry[];
|
|
36
|
+
/**
|
|
37
|
+
* Learn user confirmation patterns
|
|
38
|
+
*/
|
|
39
|
+
learnUserConfirmationPattern(entry: CommandHistoryEntry): void;
|
|
40
|
+
/**
|
|
41
|
+
* Predict user confirmation for a command
|
|
42
|
+
*/
|
|
43
|
+
predictUserConfirmation(command: string): {
|
|
44
|
+
likely_to_confirm: boolean;
|
|
45
|
+
confidence: number;
|
|
46
|
+
reasoning: string[];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Cleanup old history entries
|
|
50
|
+
*/
|
|
51
|
+
private cleanupOldEntries;
|
|
52
|
+
/**
|
|
53
|
+
* Get history statistics
|
|
54
|
+
*/
|
|
55
|
+
getHistoryStats(): {
|
|
56
|
+
totalEntries: number;
|
|
57
|
+
entriesWithEvaluation: number;
|
|
58
|
+
entriesWithConfirmation: number;
|
|
59
|
+
topCommands: Array<{
|
|
60
|
+
command: string;
|
|
61
|
+
count: number;
|
|
62
|
+
}>;
|
|
63
|
+
confirmationPatterns: UserConfirmationPattern[];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Search history
|
|
67
|
+
*/
|
|
68
|
+
searchHistory(query: {
|
|
69
|
+
command?: string;
|
|
70
|
+
working_directory?: string;
|
|
71
|
+
was_executed?: boolean;
|
|
72
|
+
safety_classification?: string;
|
|
73
|
+
limit?: number;
|
|
74
|
+
}): CommandHistoryEntry[];
|
|
75
|
+
/**
|
|
76
|
+
* Clear all history
|
|
77
|
+
*/
|
|
78
|
+
clearHistory(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Get history file path
|
|
81
|
+
*/
|
|
82
|
+
getHistoryPath(): string;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=enhanced-history-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhanced-history-manager.d.ts","sourceRoot":"","sources":["../../src/core/enhanced-history-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EAEnB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,+BAA+B,CAAC;AAGvC;;;GAGG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,MAAM,CAAyB;gBAE3B,MAAM,EAAE,sBAAsB,EAAE,WAAW,CAAC,EAAE,MAAM;IAMhE;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAM7B;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBlC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAwBlC;;OAEG;IACG,eAAe,CACnB,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,GAAG,WAAW,CAAC,GAC7D,OAAO,CAAC,MAAM,CAAC;IAyBlB;;OAEG;IACG,kBAAkB,CACtB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,cAAc,GAAG,WAAW,CAAC,CAAC,GACxE,OAAO,CAAC,OAAO,CAAC;IAmCnB;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,mBAAmB,EAAE;IAiBvE;;OAEG;IACH,4BAA4B,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;IAmD9D;;OAEG;IACH,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG;QACxC,iBAAiB,EAAE,OAAO,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB;IA8CD;;OAEG;YACW,iBAAiB;IAgB/B;;OAEG;IACH,eAAe,IAAI;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,qBAAqB,EAAE,MAAM,CAAC;QAC9B,uBAAuB,EAAE,MAAM,CAAC;QAChC,WAAW,EAAE,KAAK,CAAC;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACvD,oBAAoB,EAAE,uBAAuB,EAAE,CAAC;KACjD;IAsCD;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,mBAAmB,EAAE;IAyBzB;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnC;;OAEG;IACH,cAAc,IAAI,MAAM;CAGzB"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { CommandHistoryEntrySchema, } from '../types/enhanced-security.js';
|
|
4
|
+
import { getCurrentTimestamp, generateId } from '../utils/helpers.js';
|
|
5
|
+
/**
|
|
6
|
+
* Enhanced Command History Manager
|
|
7
|
+
* Manages command execution history, evaluation results, and user confirmation patterns
|
|
8
|
+
*/
|
|
9
|
+
export class CommandHistoryManager {
|
|
10
|
+
historyPath;
|
|
11
|
+
history = [];
|
|
12
|
+
userPatterns = [];
|
|
13
|
+
config;
|
|
14
|
+
constructor(config, historyPath) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
// Default history file path: $HOME/.mcp-shell-server/command-history.json
|
|
17
|
+
this.historyPath = historyPath || this.getDefaultHistoryPath();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get default history file path
|
|
21
|
+
*/
|
|
22
|
+
getDefaultHistoryPath() {
|
|
23
|
+
const homeDir = process.env['HOME'] || process.env['USERPROFILE'] || '.';
|
|
24
|
+
const configDir = path.join(homeDir, '.mcp-shell-server');
|
|
25
|
+
return path.join(configDir, 'command-history.json');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Load history from file
|
|
29
|
+
*/
|
|
30
|
+
async loadHistory() {
|
|
31
|
+
try {
|
|
32
|
+
await fs.access(this.historyPath);
|
|
33
|
+
const historyData = await fs.readFile(this.historyPath, 'utf-8');
|
|
34
|
+
const rawHistory = JSON.parse(historyData);
|
|
35
|
+
// Validate each entry
|
|
36
|
+
this.history =
|
|
37
|
+
rawHistory.entries?.map((entry) => CommandHistoryEntrySchema.parse(entry)) || [];
|
|
38
|
+
this.userPatterns = rawHistory.userPatterns || [];
|
|
39
|
+
// Cleanup old entries
|
|
40
|
+
await this.cleanupOldEntries();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code === 'ENOENT') {
|
|
44
|
+
// Start with empty history if file doesn't exist
|
|
45
|
+
this.history = [];
|
|
46
|
+
this.userPatterns = [];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw new Error(`Failed to load command history: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Save history to file
|
|
55
|
+
*/
|
|
56
|
+
async saveHistory() {
|
|
57
|
+
try {
|
|
58
|
+
const historyDir = path.dirname(this.historyPath);
|
|
59
|
+
await fs.mkdir(historyDir, { recursive: true });
|
|
60
|
+
const historyData = {
|
|
61
|
+
metadata: {
|
|
62
|
+
version: '2.2.0',
|
|
63
|
+
lastUpdated: getCurrentTimestamp(),
|
|
64
|
+
totalEntries: this.history.length,
|
|
65
|
+
retentionDays: this.config.history_retention_days,
|
|
66
|
+
maxEntries: this.config.max_history_entries,
|
|
67
|
+
},
|
|
68
|
+
entries: this.history,
|
|
69
|
+
userPatterns: this.userPatterns,
|
|
70
|
+
};
|
|
71
|
+
const historyJson = JSON.stringify(historyData, null, 2);
|
|
72
|
+
await fs.writeFile(this.historyPath, historyJson, 'utf-8');
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new Error(`Failed to save command history: ${error}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Add new command history entry
|
|
80
|
+
*/
|
|
81
|
+
async addHistoryEntry(entry) {
|
|
82
|
+
const fullEntry = {
|
|
83
|
+
...entry,
|
|
84
|
+
execution_id: generateId(),
|
|
85
|
+
timestamp: getCurrentTimestamp(),
|
|
86
|
+
};
|
|
87
|
+
// Validation
|
|
88
|
+
const validatedEntry = CommandHistoryEntrySchema.parse(fullEntry);
|
|
89
|
+
this.history.unshift(validatedEntry); // Add newest at front
|
|
90
|
+
// Remove old entries if max exceeded
|
|
91
|
+
if (this.history.length > this.config.max_history_entries) {
|
|
92
|
+
this.history = this.history.slice(0, this.config.max_history_entries);
|
|
93
|
+
}
|
|
94
|
+
// Auto-save (optional)
|
|
95
|
+
if (this.config.command_history_enhanced) {
|
|
96
|
+
await this.saveHistory();
|
|
97
|
+
}
|
|
98
|
+
return fullEntry.execution_id;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Update history entry (add evaluation results, etc.)
|
|
102
|
+
*/
|
|
103
|
+
async updateHistoryEntry(executionId, updates) {
|
|
104
|
+
const entryIndex = this.history.findIndex((entry) => entry.execution_id === executionId);
|
|
105
|
+
if (entryIndex === -1) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const currentEntry = this.history[entryIndex];
|
|
109
|
+
if (!currentEntry) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
// Update (preserve required fields)
|
|
113
|
+
const updatedEntry = {
|
|
114
|
+
...currentEntry,
|
|
115
|
+
...updates,
|
|
116
|
+
execution_id: currentEntry.execution_id,
|
|
117
|
+
command: currentEntry.command,
|
|
118
|
+
timestamp: currentEntry.timestamp,
|
|
119
|
+
working_directory: currentEntry.working_directory,
|
|
120
|
+
was_executed: currentEntry.was_executed,
|
|
121
|
+
resubmission_count: currentEntry.resubmission_count,
|
|
122
|
+
};
|
|
123
|
+
// Validation
|
|
124
|
+
this.history[entryIndex] = CommandHistoryEntrySchema.parse(updatedEntry);
|
|
125
|
+
// Auto-save
|
|
126
|
+
if (this.config.command_history_enhanced) {
|
|
127
|
+
await this.saveHistory();
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Search for similar commands in history
|
|
133
|
+
*/
|
|
134
|
+
findSimilarCommands(command, limit = 10) {
|
|
135
|
+
const normalizedCommand = command.toLowerCase().trim();
|
|
136
|
+
return this.history
|
|
137
|
+
.filter((entry) => {
|
|
138
|
+
const entryCommand = entry.command.toLowerCase().trim();
|
|
139
|
+
// Exact match, partial match, or first word match
|
|
140
|
+
return (entryCommand === normalizedCommand ||
|
|
141
|
+
entryCommand.includes(normalizedCommand) ||
|
|
142
|
+
normalizedCommand.includes(entryCommand) ||
|
|
143
|
+
entryCommand.split(' ')[0] === normalizedCommand.split(' ')[0]);
|
|
144
|
+
})
|
|
145
|
+
.slice(0, limit);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Learn user confirmation patterns
|
|
149
|
+
*/
|
|
150
|
+
learnUserConfirmationPattern(entry) {
|
|
151
|
+
if (!entry.user_confirmation_context || !this.config.enable_resubmission_learning) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const commandWords = entry.command.toLowerCase().trim().split(/\s+/);
|
|
155
|
+
const baseCommand = commandWords[0];
|
|
156
|
+
if (!baseCommand) {
|
|
157
|
+
return; // Skip if command is empty
|
|
158
|
+
}
|
|
159
|
+
// Find existing pattern
|
|
160
|
+
let pattern = this.userPatterns.find((p) => p.command_pattern === baseCommand || new RegExp(p.command_pattern).test(entry.command));
|
|
161
|
+
if (pattern) {
|
|
162
|
+
// Update existing pattern
|
|
163
|
+
const totalCount = pattern.confidence * 10; // Arbitrary weight
|
|
164
|
+
const newCount = totalCount + 1;
|
|
165
|
+
const confirmations = totalCount * pattern.confirmation_rate +
|
|
166
|
+
(entry.user_confirmation_context.user_response ? 1 : 0);
|
|
167
|
+
pattern.confirmation_rate = confirmations / newCount;
|
|
168
|
+
pattern.confidence = Math.min(1.0, newCount / 10);
|
|
169
|
+
// Add reasoning (avoid duplicates)
|
|
170
|
+
const reasoning = entry.user_confirmation_context.user_reasoning;
|
|
171
|
+
if (reasoning && !pattern.typical_reasoning.includes(reasoning)) {
|
|
172
|
+
pattern.typical_reasoning.push(reasoning);
|
|
173
|
+
// Keep maximum 5 entries
|
|
174
|
+
if (pattern.typical_reasoning.length > 5) {
|
|
175
|
+
pattern.typical_reasoning = pattern.typical_reasoning.slice(-5);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// Create new pattern
|
|
181
|
+
const newPattern = {
|
|
182
|
+
command_pattern: baseCommand,
|
|
183
|
+
confirmation_rate: entry.user_confirmation_context.user_response ? 1.0 : 0.0,
|
|
184
|
+
typical_reasoning: entry.user_confirmation_context.user_reasoning
|
|
185
|
+
? [entry.user_confirmation_context.user_reasoning]
|
|
186
|
+
: [],
|
|
187
|
+
confidence: 0.1, // Low initial confidence
|
|
188
|
+
};
|
|
189
|
+
this.userPatterns.push(newPattern);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Predict user confirmation for a command
|
|
194
|
+
*/
|
|
195
|
+
predictUserConfirmation(command) {
|
|
196
|
+
const commandWords = command.toLowerCase().trim().split(/\s+/);
|
|
197
|
+
const baseCommand = commandWords[0];
|
|
198
|
+
// Find matching patterns
|
|
199
|
+
const matchingPatterns = this.userPatterns.filter((pattern) => {
|
|
200
|
+
try {
|
|
201
|
+
return (pattern.command_pattern === baseCommand ||
|
|
202
|
+
new RegExp(pattern.command_pattern).test(command));
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return pattern.command_pattern === baseCommand;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
if (matchingPatterns.length === 0) {
|
|
209
|
+
return {
|
|
210
|
+
likely_to_confirm: false,
|
|
211
|
+
confidence: 0.0,
|
|
212
|
+
reasoning: [],
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
// Weighted average prediction
|
|
216
|
+
let totalWeight = 0;
|
|
217
|
+
let weightedConfirmationRate = 0;
|
|
218
|
+
const allReasoning = [];
|
|
219
|
+
matchingPatterns.forEach((pattern) => {
|
|
220
|
+
const weight = pattern.confidence;
|
|
221
|
+
totalWeight += weight;
|
|
222
|
+
weightedConfirmationRate += pattern.confirmation_rate * weight;
|
|
223
|
+
allReasoning.push(...pattern.typical_reasoning);
|
|
224
|
+
});
|
|
225
|
+
const avgConfirmationRate = totalWeight > 0 ? weightedConfirmationRate / totalWeight : 0;
|
|
226
|
+
const confidence = totalWeight / matchingPatterns.length;
|
|
227
|
+
return {
|
|
228
|
+
likely_to_confirm: avgConfirmationRate > 0.5,
|
|
229
|
+
confidence,
|
|
230
|
+
reasoning: [...new Set(allReasoning)], // Remove duplicates
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Cleanup old history entries
|
|
235
|
+
*/
|
|
236
|
+
async cleanupOldEntries() {
|
|
237
|
+
const cutoffDate = new Date();
|
|
238
|
+
cutoffDate.setDate(cutoffDate.getDate() - this.config.history_retention_days);
|
|
239
|
+
const initialCount = this.history.length;
|
|
240
|
+
this.history = this.history.filter((entry) => {
|
|
241
|
+
const entryDate = new Date(entry.timestamp);
|
|
242
|
+
return entryDate >= cutoffDate;
|
|
243
|
+
});
|
|
244
|
+
const removedCount = initialCount - this.history.length;
|
|
245
|
+
if (removedCount > 0) {
|
|
246
|
+
console.error(`Cleaned up ${removedCount} old command history entries`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get history statistics
|
|
251
|
+
*/
|
|
252
|
+
getHistoryStats() {
|
|
253
|
+
const commandCounts = new Map();
|
|
254
|
+
let entriesWithEvaluation = 0;
|
|
255
|
+
let entriesWithConfirmation = 0;
|
|
256
|
+
this.history.forEach((entry) => {
|
|
257
|
+
// Count commands
|
|
258
|
+
const baseCommand = entry.command.split(' ')[0];
|
|
259
|
+
if (baseCommand) {
|
|
260
|
+
commandCounts.set(baseCommand, (commandCounts.get(baseCommand) || 0) + 1);
|
|
261
|
+
}
|
|
262
|
+
// Check evaluation results
|
|
263
|
+
if (entry.llm_evaluation_result || entry.safety_classification) {
|
|
264
|
+
entriesWithEvaluation++;
|
|
265
|
+
}
|
|
266
|
+
// Check confirmations
|
|
267
|
+
if (entry.user_confirmation_context) {
|
|
268
|
+
entriesWithConfirmation++;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
// Get top commands
|
|
272
|
+
const topCommands = Array.from(commandCounts.entries())
|
|
273
|
+
.sort((a, b) => b[1] - a[1])
|
|
274
|
+
.slice(0, 10)
|
|
275
|
+
.map(([command, count]) => ({ command, count }));
|
|
276
|
+
return {
|
|
277
|
+
totalEntries: this.history.length,
|
|
278
|
+
entriesWithEvaluation,
|
|
279
|
+
entriesWithConfirmation,
|
|
280
|
+
topCommands,
|
|
281
|
+
confirmationPatterns: [...this.userPatterns],
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Search history
|
|
286
|
+
*/
|
|
287
|
+
searchHistory(query) {
|
|
288
|
+
let filtered = this.history;
|
|
289
|
+
if (query.command) {
|
|
290
|
+
const searchTerm = query.command.toLowerCase();
|
|
291
|
+
filtered = filtered.filter((entry) => entry.command.toLowerCase().includes(searchTerm));
|
|
292
|
+
}
|
|
293
|
+
if (query.working_directory) {
|
|
294
|
+
filtered = filtered.filter((entry) => entry.working_directory === query.working_directory);
|
|
295
|
+
}
|
|
296
|
+
if (query.was_executed !== undefined) {
|
|
297
|
+
filtered = filtered.filter((entry) => entry.was_executed === query.was_executed);
|
|
298
|
+
}
|
|
299
|
+
if (query.safety_classification) {
|
|
300
|
+
filtered = filtered.filter((entry) => entry.safety_classification === query.safety_classification);
|
|
301
|
+
}
|
|
302
|
+
return filtered.slice(0, query.limit || 50);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Clear all history
|
|
306
|
+
*/
|
|
307
|
+
async clearHistory() {
|
|
308
|
+
this.history = [];
|
|
309
|
+
this.userPatterns = [];
|
|
310
|
+
await this.saveHistory();
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get history file path
|
|
314
|
+
*/
|
|
315
|
+
getHistoryPath() {
|
|
316
|
+
return this.historyPath;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=enhanced-history-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhanced-history-manager.js","sourceRoot":"","sources":["../../src/core/enhanced-history-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAEL,yBAAyB,GAG1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtE;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACxB,WAAW,CAAS;IACpB,OAAO,GAA0B,EAAE,CAAC;IACpC,YAAY,GAA8B,EAAE,CAAC;IAC7C,MAAM,CAAyB;IAEvC,YAAY,MAA8B,EAAE,WAAoB;QAC9D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,0EAA0E;QAC1E,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;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