@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,124 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Zod schemas for enhanced evaluator type definitions
|
|
3
|
+
export const MessageContentSchema = z.object({
|
|
4
|
+
type: z.literal('text'),
|
|
5
|
+
text: z.string()
|
|
6
|
+
});
|
|
7
|
+
export const ToolCallSchema = z.object({
|
|
8
|
+
id: z.string(),
|
|
9
|
+
type: z.literal('function'),
|
|
10
|
+
function: z.object({
|
|
11
|
+
name: z.string(),
|
|
12
|
+
arguments: z.string()
|
|
13
|
+
})
|
|
14
|
+
});
|
|
15
|
+
export const ToolChoiceSchema = z.union([
|
|
16
|
+
z.literal('auto'),
|
|
17
|
+
z.literal('none'),
|
|
18
|
+
z.object({ type: z.literal('function'), function: z.object({ name: z.string() }) }),
|
|
19
|
+
z.object({ type: z.literal('tool'), name: z.string() })
|
|
20
|
+
]);
|
|
21
|
+
export const CreateMessageRequestSchema = z.object({
|
|
22
|
+
messages: z.array(z.object({
|
|
23
|
+
role: z.enum(['user', 'assistant', 'tool']),
|
|
24
|
+
content: MessageContentSchema,
|
|
25
|
+
tool_call_id: z.string().optional()
|
|
26
|
+
})),
|
|
27
|
+
maxTokens: z.number().optional(),
|
|
28
|
+
temperature: z.number().optional(),
|
|
29
|
+
systemPrompt: z.string().optional(),
|
|
30
|
+
includeContext: z.enum(['none', 'thisServer', 'allServers']).optional(),
|
|
31
|
+
stopSequences: z.array(z.string()).optional(),
|
|
32
|
+
metadata: z.record(z.unknown()).optional(),
|
|
33
|
+
modelPreferences: z.record(z.unknown()).optional(),
|
|
34
|
+
tools: z.array(z.object({
|
|
35
|
+
type: z.literal('function'),
|
|
36
|
+
function: z.object({
|
|
37
|
+
name: z.string(),
|
|
38
|
+
description: z.string(),
|
|
39
|
+
parameters: z.record(z.unknown())
|
|
40
|
+
})
|
|
41
|
+
})).optional(),
|
|
42
|
+
tool_choice: ToolChoiceSchema.optional()
|
|
43
|
+
});
|
|
44
|
+
export const CreateMessageResponseSchema = z.object({
|
|
45
|
+
content: MessageContentSchema,
|
|
46
|
+
model: z.string().optional(),
|
|
47
|
+
stopReason: z.string().optional(),
|
|
48
|
+
tool_calls: z.array(z.object({
|
|
49
|
+
id: z.string(),
|
|
50
|
+
type: z.literal('function'),
|
|
51
|
+
function: z.object({
|
|
52
|
+
name: z.string(),
|
|
53
|
+
arguments: z.string()
|
|
54
|
+
})
|
|
55
|
+
})).optional()
|
|
56
|
+
});
|
|
57
|
+
export const ElicitationPropertySchema = z.object({
|
|
58
|
+
type: z.string(),
|
|
59
|
+
title: z.string().optional(),
|
|
60
|
+
description: z.string().optional(),
|
|
61
|
+
minimum: z.number().optional(),
|
|
62
|
+
maximum: z.number().optional(),
|
|
63
|
+
enum: z.array(z.string()).optional()
|
|
64
|
+
}).catchall(z.unknown());
|
|
65
|
+
export const ElicitationSchemaSchema = z.object({
|
|
66
|
+
type: z.literal('object'),
|
|
67
|
+
properties: z.record(ElicitationPropertySchema),
|
|
68
|
+
required: z.array(z.string()).optional()
|
|
69
|
+
});
|
|
70
|
+
export const ElicitationResponseSchema = z.object({
|
|
71
|
+
action: z.enum(['accept', 'decline', 'cancel']),
|
|
72
|
+
content: z.record(z.unknown()).optional()
|
|
73
|
+
});
|
|
74
|
+
export const RequiresAdditionalContextSchema = z.object({
|
|
75
|
+
command_history_depth: z.number(),
|
|
76
|
+
execution_results_count: z.number(),
|
|
77
|
+
user_intent_search_keywords: z.array(z.string()).nullable(),
|
|
78
|
+
user_intent_question: z.string().nullable(),
|
|
79
|
+
assistant_request_message: z.string().nullable().optional()
|
|
80
|
+
});
|
|
81
|
+
export const LLMEvaluationResultSchema = z.object({
|
|
82
|
+
evaluation_result: z.enum(['allow', 'deny', 'add_more_history', 'user_confirm', 'ai_assistant_confirm']),
|
|
83
|
+
reasoning: z.string(),
|
|
84
|
+
command_history_depth: z.number().optional(),
|
|
85
|
+
execution_results_count: z.number().optional(),
|
|
86
|
+
user_intent_search_keywords: z.array(z.string()).optional(),
|
|
87
|
+
confirmation_question: z.string().optional(),
|
|
88
|
+
assistant_request_message: z.string().optional(),
|
|
89
|
+
suggested_alternatives: z.array(z.string()).optional(),
|
|
90
|
+
requires_additional_context: RequiresAdditionalContextSchema.optional(),
|
|
91
|
+
next_steps: z.array(z.string()).optional()
|
|
92
|
+
});
|
|
93
|
+
export const UserIntentDataSchema = z.object({
|
|
94
|
+
intent: z.string(),
|
|
95
|
+
justification: z.string(),
|
|
96
|
+
timestamp: z.string(),
|
|
97
|
+
confidence_level: z.enum(['low', 'medium', 'high']),
|
|
98
|
+
elicitation_id: z.string()
|
|
99
|
+
});
|
|
100
|
+
export const NextActionSchema = z.object({
|
|
101
|
+
instruction: z.string(),
|
|
102
|
+
method: z.string(),
|
|
103
|
+
expected_outcome: z.string(),
|
|
104
|
+
executable_commands: z.array(z.string()).optional()
|
|
105
|
+
});
|
|
106
|
+
export const SafetyEvaluationSchema = z.object({
|
|
107
|
+
evaluation_result: z.enum(['allow', 'deny', 'add_more_history', 'user_confirm', 'ai_assistant_confirm']),
|
|
108
|
+
basic_classification: z.string(),
|
|
109
|
+
reasoning: z.string(),
|
|
110
|
+
requires_confirmation: z.boolean(),
|
|
111
|
+
suggested_alternatives: z.array(z.string()),
|
|
112
|
+
llm_evaluation_used: z.boolean(),
|
|
113
|
+
user_confirmation_required: z.boolean().optional(),
|
|
114
|
+
user_response: z.record(z.unknown()).optional(),
|
|
115
|
+
confirmation_message: z.string().optional(),
|
|
116
|
+
elicitation_response: ElicitationResponseSchema.nullable().optional(),
|
|
117
|
+
next_action: NextActionSchema.optional(),
|
|
118
|
+
next_steps: z.array(z.string()).optional()
|
|
119
|
+
});
|
|
120
|
+
export const MCPServerRequestSchema = z.object({
|
|
121
|
+
method: z.string(),
|
|
122
|
+
params: z.record(z.unknown()).optional()
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=evaluator-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator-types.js","sourceRoot":"","sources":["../../src/security/evaluator-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,sDAAsD;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC;IACtC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;IACnF,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC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,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,sBAAsB,CAAC,CAAC;IACxG,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,qBAAqB,EAAE,CAAC,CAAC,OAAO,EAAE;IAClC,sBAAsB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC3C,mBAAmB,EAAE,CAAC,CAAC,OAAO,EAAE;IAChC,0BAA0B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAClD,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC/C,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3C,oBAAoB,EAAE,yBAAyB,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACrE,WAAW,EAAE,gBAAgB,CAAC,QAAQ,EAAE;IACxC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SecurityRestrictions } from '../types/index.js';
|
|
2
|
+
import { EnhancedSecurityConfig, CommandClassification, BasicSafetyRule } from '../types/enhanced-security.js';
|
|
3
|
+
import { type CreateMessageCallback } from './chat-completion-adapter.js';
|
|
4
|
+
import type { ElicitationHandler } from './evaluator-types.js';
|
|
5
|
+
import { CommandHistoryManager } from '../core/enhanced-history-manager.js';
|
|
6
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
import type { SafetyEvaluationResult } from '../types/index.js';
|
|
8
|
+
export declare class SecurityManager {
|
|
9
|
+
private restrictions;
|
|
10
|
+
private enhancedConfig;
|
|
11
|
+
private basicSafetyRules;
|
|
12
|
+
private enhancedEvaluator?;
|
|
13
|
+
private historyManager?;
|
|
14
|
+
constructor(config?: EnhancedSecurityConfig);
|
|
15
|
+
private setDefaultRestrictions;
|
|
16
|
+
/**
|
|
17
|
+
* Load enhanced security configuration from environment variables
|
|
18
|
+
*/
|
|
19
|
+
private loadEnhancedConfigFromEnv;
|
|
20
|
+
setRestrictions(restrictions: Partial<SecurityRestrictions>): SecurityRestrictions;
|
|
21
|
+
getRestrictions(): SecurityRestrictions | null;
|
|
22
|
+
validateCommand(command: string): void;
|
|
23
|
+
validatePath(path: string): void;
|
|
24
|
+
validateExecutionTime(timeoutSeconds: number): void;
|
|
25
|
+
validateMemoryUsage(memoryMb: number): void;
|
|
26
|
+
validateNetworkAccess(): void;
|
|
27
|
+
auditCommand(command: string, workingDirectory?: string): void;
|
|
28
|
+
private isCommandAllowed;
|
|
29
|
+
/**
|
|
30
|
+
* Update enhanced security configuration
|
|
31
|
+
*/
|
|
32
|
+
setEnhancedConfig(config: Partial<EnhancedSecurityConfig>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get current enhanced security configuration
|
|
35
|
+
*/
|
|
36
|
+
getEnhancedConfig(): EnhancedSecurityConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Update basic safety rules
|
|
39
|
+
*/
|
|
40
|
+
setBasicSafetyRules(rules: BasicSafetyRule[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get current basic safety rules
|
|
43
|
+
*/
|
|
44
|
+
getBasicSafetyRules(): BasicSafetyRule[];
|
|
45
|
+
/**
|
|
46
|
+
* Check if enhanced security mode is enabled
|
|
47
|
+
*/
|
|
48
|
+
isEnhancedModeEnabled(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if LLM evaluation is enabled
|
|
51
|
+
*/
|
|
52
|
+
isLLMEvaluationEnabled(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if command history enhancement is enabled
|
|
55
|
+
*/
|
|
56
|
+
isCommandHistoryEnhanced(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Detailed command safety analysis with reasoning
|
|
59
|
+
*/
|
|
60
|
+
analyzeCommandSafety(command: string): {
|
|
61
|
+
classification: CommandClassification;
|
|
62
|
+
reasoning: string;
|
|
63
|
+
safety_level?: number;
|
|
64
|
+
matched_rule?: string;
|
|
65
|
+
dangerous_patterns?: string[];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Initialize Enhanced Safety Evaluator
|
|
69
|
+
*/
|
|
70
|
+
initializeEnhancedEvaluator(historyManager: CommandHistoryManager, server?: Server, createMessage?: CreateMessageCallback, elicitationHandler?: ElicitationHandler): void;
|
|
71
|
+
/**
|
|
72
|
+
* Perform comprehensive safety evaluation using enhanced evaluator
|
|
73
|
+
*/
|
|
74
|
+
evaluateCommandSafetyByEnhancedEvaluator(command: string, workingDirectory: string, comment?: string, forceUserConfirm?: boolean): Promise<SafetyEvaluationResult>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/security/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAgB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EACL,sBAAsB,EAGtB,qBAAqB,EACrB,eAAe,EAChB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAsC,KAAK,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AA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OAEG;IACH,qBAAqB,IAAI,OAAO;IAMhC;;OAEG;IACH,sBAAsB,IAAI,OAAO;IAIjC;;OAEG;IACH,wBAAwB,IAAI,OAAO;IAInC;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG;QACrC,cAAc,EAAE,qBAAqB,CAAC;QACtC,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC/B;IA6CD;;OAEG;IACH,2BAA2B,CACzB,cAAc,EAAE,qBAAqB,EACrC,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,qBAAqB,EACrC,kBAAkB,CAAC,EAAE,kBAAkB,GACtC,IAAI;IAiCP;;OAEG;IACG,wCAAwC,CAC5C,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,EAChB,gBAAgB,CAAC,EAAE,OAAO,GACzB,OAAO,CAAC,sBAAsB,CAAC;CAkBnC"}
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { DEFAULT_ENHANCED_SECURITY_CONFIG, DEFAULT_BASIC_SAFETY_RULES, } from '../types/enhanced-security.js';
|
|
2
|
+
import { SecurityError } from '../utils/errors.js';
|
|
3
|
+
import { isValidPath, generateId, getCurrentTimestamp } from '../utils/helpers.js';
|
|
4
|
+
import { EnhancedSafetyEvaluator } from './enhanced-evaluator.js';
|
|
5
|
+
import { createMessageCallbackFromMCPServer } from './chat-completion-adapter.js';
|
|
6
|
+
export class SecurityManager {
|
|
7
|
+
restrictions = null;
|
|
8
|
+
enhancedConfig;
|
|
9
|
+
basicSafetyRules;
|
|
10
|
+
enhancedEvaluator;
|
|
11
|
+
historyManager;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.enhancedConfig = config ? { ...config } : { ...DEFAULT_ENHANCED_SECURITY_CONFIG };
|
|
14
|
+
this.basicSafetyRules = [...DEFAULT_BASIC_SAFETY_RULES];
|
|
15
|
+
// Load Enhanced Security configuration from environment variables
|
|
16
|
+
this.loadEnhancedConfigFromEnv();
|
|
17
|
+
// Set default security restrictions
|
|
18
|
+
this.setDefaultRestrictions();
|
|
19
|
+
}
|
|
20
|
+
setDefaultRestrictions() {
|
|
21
|
+
// Get default settings from environment variables
|
|
22
|
+
const defaultMode = process.env['MCP_SHELL_SECURITY_MODE'] || 'permissive';
|
|
23
|
+
const defaultExecutionTime = parseInt(process.env['MCP_SHELL_MAX_EXECUTION_TIME'] || '300');
|
|
24
|
+
const defaultMemoryMb = parseInt(process.env['MCP_SHELL_MAX_MEMORY_MB'] || '1024');
|
|
25
|
+
const defaultNetworkEnabled = process.env['MCP_SHELL_ENABLE_NETWORK'] !== 'false';
|
|
26
|
+
// Automatic configuration for Enhanced Mode
|
|
27
|
+
if (defaultMode === 'enhanced' || defaultMode === 'enhanced-fast') {
|
|
28
|
+
this.enhancedConfig.enhanced_mode_enabled = true;
|
|
29
|
+
this.enhancedConfig.llm_evaluation_enabled = true;
|
|
30
|
+
// For enhanced-fast, enable safe command skipping
|
|
31
|
+
this.enhancedConfig.enable_pattern_filtering = defaultMode === 'enhanced-fast';
|
|
32
|
+
}
|
|
33
|
+
this.restrictions = {
|
|
34
|
+
restriction_id: generateId(),
|
|
35
|
+
security_mode: defaultMode,
|
|
36
|
+
max_execution_time: defaultExecutionTime, // 5 minutes
|
|
37
|
+
max_memory_mb: defaultMemoryMb, // 1GB
|
|
38
|
+
enable_network: defaultNetworkEnabled,
|
|
39
|
+
active: true,
|
|
40
|
+
configured_at: getCurrentTimestamp(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Load enhanced security configuration from environment variables
|
|
45
|
+
*/
|
|
46
|
+
loadEnhancedConfigFromEnv() {
|
|
47
|
+
// Enhanced mode (backward compatibility)
|
|
48
|
+
if (process.env['MCP_SHELL_ENHANCED_MODE'] === 'true') {
|
|
49
|
+
this.enhancedConfig.enhanced_mode_enabled = true;
|
|
50
|
+
}
|
|
51
|
+
else if (process.env['MCP_SHELL_ENHANCED_MODE'] === 'false') {
|
|
52
|
+
this.enhancedConfig.enhanced_mode_enabled = false;
|
|
53
|
+
}
|
|
54
|
+
// LLM evaluation (backward compatibility)
|
|
55
|
+
if (process.env['MCP_SHELL_LLM_EVALUATION'] === 'true') {
|
|
56
|
+
this.enhancedConfig.llm_evaluation_enabled = true;
|
|
57
|
+
}
|
|
58
|
+
else if (process.env['MCP_SHELL_LLM_EVALUATION'] === 'false') {
|
|
59
|
+
this.enhancedConfig.llm_evaluation_enabled = false;
|
|
60
|
+
}
|
|
61
|
+
// Safe command skip (new simplified naming)
|
|
62
|
+
if (process.env['MCP_SHELL_SKIP_SAFE_COMMANDS'] === 'true') {
|
|
63
|
+
this.enhancedConfig.enable_pattern_filtering = true;
|
|
64
|
+
}
|
|
65
|
+
// Pattern matching pre-filtering (backward compatibility)
|
|
66
|
+
if (process.env['MCP_SHELL_ENABLE_PATTERN_FILTERING'] === 'true') {
|
|
67
|
+
this.enhancedConfig.enable_pattern_filtering = true;
|
|
68
|
+
}
|
|
69
|
+
// Other enhanced security settings
|
|
70
|
+
if (process.env['MCP_SHELL_ELICITATION'] === 'true') {
|
|
71
|
+
this.enhancedConfig.elicitation_enabled = true;
|
|
72
|
+
}
|
|
73
|
+
if (process.env['MCP_SHELL_BASIC_SAFE_CLASSIFICATION'] === 'false') {
|
|
74
|
+
this.enhancedConfig.basic_safe_classification = false;
|
|
75
|
+
}
|
|
76
|
+
// LLM provider settings
|
|
77
|
+
if (process.env['MCP_SHELL_LLM_PROVIDER']) {
|
|
78
|
+
this.enhancedConfig.llm_provider = process.env['MCP_SHELL_LLM_PROVIDER'];
|
|
79
|
+
}
|
|
80
|
+
if (process.env['MCP_SHELL_LLM_MODEL']) {
|
|
81
|
+
this.enhancedConfig.llm_model = process.env['MCP_SHELL_LLM_MODEL'];
|
|
82
|
+
}
|
|
83
|
+
if (process.env['MCP_SHELL_LLM_API_KEY']) {
|
|
84
|
+
this.enhancedConfig.llm_api_key = process.env['MCP_SHELL_LLM_API_KEY'];
|
|
85
|
+
}
|
|
86
|
+
if (process.env['MCP_SHELL_LLM_TIMEOUT']) {
|
|
87
|
+
const timeout = parseInt(process.env['MCP_SHELL_LLM_TIMEOUT']);
|
|
88
|
+
if (!isNaN(timeout) && timeout > 0 && timeout <= 60) {
|
|
89
|
+
this.enhancedConfig.llm_timeout_seconds = timeout;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
setRestrictions(restrictions) {
|
|
94
|
+
const newRestrictions = {
|
|
95
|
+
restriction_id: generateId(),
|
|
96
|
+
security_mode: restrictions.security_mode || this.restrictions?.security_mode || 'permissive',
|
|
97
|
+
max_execution_time: restrictions.max_execution_time || this.restrictions?.max_execution_time || 300,
|
|
98
|
+
max_memory_mb: restrictions.max_memory_mb || this.restrictions?.max_memory_mb || 1024,
|
|
99
|
+
enable_network: restrictions.enable_network ?? this.restrictions?.enable_network ?? true,
|
|
100
|
+
active: true,
|
|
101
|
+
configured_at: getCurrentTimestamp(),
|
|
102
|
+
};
|
|
103
|
+
// customモードの場合のみ、詳細設定を適用
|
|
104
|
+
if (newRestrictions.security_mode === 'custom') {
|
|
105
|
+
if (restrictions.allowed_commands) {
|
|
106
|
+
newRestrictions.allowed_commands = restrictions.allowed_commands;
|
|
107
|
+
}
|
|
108
|
+
else if (this.restrictions?.allowed_commands) {
|
|
109
|
+
newRestrictions.allowed_commands = this.restrictions.allowed_commands;
|
|
110
|
+
}
|
|
111
|
+
if (restrictions.blocked_commands) {
|
|
112
|
+
newRestrictions.blocked_commands = restrictions.blocked_commands;
|
|
113
|
+
}
|
|
114
|
+
else if (this.restrictions?.blocked_commands) {
|
|
115
|
+
newRestrictions.blocked_commands = this.restrictions.blocked_commands;
|
|
116
|
+
}
|
|
117
|
+
if (restrictions.allowed_directories) {
|
|
118
|
+
newRestrictions.allowed_directories = restrictions.allowed_directories;
|
|
119
|
+
}
|
|
120
|
+
else if (this.restrictions?.allowed_directories) {
|
|
121
|
+
newRestrictions.allowed_directories = this.restrictions.allowed_directories;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.restrictions = newRestrictions;
|
|
125
|
+
return newRestrictions;
|
|
126
|
+
}
|
|
127
|
+
getRestrictions() {
|
|
128
|
+
return this.restrictions;
|
|
129
|
+
}
|
|
130
|
+
validateCommand(command) {
|
|
131
|
+
if (!this.restrictions?.active) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
switch (this.restrictions.security_mode) {
|
|
135
|
+
case 'permissive':
|
|
136
|
+
// permissive mode: legacy dangerous pattern blocking removed.
|
|
137
|
+
// Intentionally no blocking here; rely on evaluator & downstream validation.
|
|
138
|
+
break;
|
|
139
|
+
case 'moderate':
|
|
140
|
+
// moderate mode: legacy dangerous pattern blocking removed.
|
|
141
|
+
// (Could add lightweight heuristics here in future if needed.)
|
|
142
|
+
break;
|
|
143
|
+
case 'enhanced':
|
|
144
|
+
case 'enhanced-fast':
|
|
145
|
+
// enhanced mode: Enhanced Safety Evaluator performs all validation
|
|
146
|
+
// No pattern checks at validateCommand stage
|
|
147
|
+
// All validation is delegated to Enhanced Safety Evaluator
|
|
148
|
+
// Legacy pattern matching detection is completely skipped
|
|
149
|
+
break;
|
|
150
|
+
case 'restrictive':
|
|
151
|
+
// restrictive mode: only allow read-only and information retrieval commands
|
|
152
|
+
const restrictiveAllowedCommands = [
|
|
153
|
+
// File/directory operations (read-only)
|
|
154
|
+
'ls',
|
|
155
|
+
'cat',
|
|
156
|
+
'less',
|
|
157
|
+
'more',
|
|
158
|
+
'head',
|
|
159
|
+
'tail',
|
|
160
|
+
'file',
|
|
161
|
+
'stat',
|
|
162
|
+
'find',
|
|
163
|
+
'locate',
|
|
164
|
+
// Text processing
|
|
165
|
+
'grep',
|
|
166
|
+
'awk',
|
|
167
|
+
'sed',
|
|
168
|
+
'sort',
|
|
169
|
+
'uniq',
|
|
170
|
+
'wc',
|
|
171
|
+
'cut',
|
|
172
|
+
'tr',
|
|
173
|
+
'column',
|
|
174
|
+
// System information
|
|
175
|
+
'pwd',
|
|
176
|
+
'whoami',
|
|
177
|
+
'id',
|
|
178
|
+
'date',
|
|
179
|
+
'uptime',
|
|
180
|
+
'uname',
|
|
181
|
+
'hostname',
|
|
182
|
+
'ps',
|
|
183
|
+
'top',
|
|
184
|
+
'df',
|
|
185
|
+
'du',
|
|
186
|
+
'free',
|
|
187
|
+
'lscpu',
|
|
188
|
+
'lsblk',
|
|
189
|
+
'lsusb',
|
|
190
|
+
'lspci',
|
|
191
|
+
// Network (read-only)
|
|
192
|
+
'ping',
|
|
193
|
+
'nslookup',
|
|
194
|
+
'dig',
|
|
195
|
+
'host',
|
|
196
|
+
'netstat',
|
|
197
|
+
'ss',
|
|
198
|
+
'lsof',
|
|
199
|
+
// Basic commands
|
|
200
|
+
'echo',
|
|
201
|
+
'printf',
|
|
202
|
+
'which',
|
|
203
|
+
'type',
|
|
204
|
+
'command',
|
|
205
|
+
'history',
|
|
206
|
+
'env',
|
|
207
|
+
'printenv',
|
|
208
|
+
// Archive (read-only)
|
|
209
|
+
'tar',
|
|
210
|
+
'zip',
|
|
211
|
+
'unzip',
|
|
212
|
+
'gzip',
|
|
213
|
+
'gunzip',
|
|
214
|
+
'zcat',
|
|
215
|
+
];
|
|
216
|
+
if (!this.isCommandAllowed(command, restrictiveAllowedCommands, [])) {
|
|
217
|
+
throw new SecurityError(`Command '${command}' is not allowed in restrictive mode`, {
|
|
218
|
+
command,
|
|
219
|
+
allowedCommands: restrictiveAllowedCommands,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
case 'custom':
|
|
224
|
+
// custom mode: use detailed settings
|
|
225
|
+
if (!this.isCommandAllowed(command, this.restrictions.allowed_commands, this.restrictions.blocked_commands)) {
|
|
226
|
+
throw new SecurityError(`Command '${command}' is not allowed by security policy`, {
|
|
227
|
+
command,
|
|
228
|
+
allowedCommands: this.restrictions.allowed_commands,
|
|
229
|
+
blockedCommands: this.restrictions.blocked_commands,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
validatePath(path) {
|
|
236
|
+
if (!this.restrictions?.active) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!isValidPath(path, this.restrictions.allowed_directories)) {
|
|
240
|
+
throw new SecurityError(`Path '${path}' is not accessible`, {
|
|
241
|
+
path,
|
|
242
|
+
allowedDirectories: this.restrictions.allowed_directories,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
validateExecutionTime(timeoutSeconds) {
|
|
247
|
+
if (!this.restrictions?.active) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (this.restrictions.max_execution_time &&
|
|
251
|
+
timeoutSeconds > this.restrictions.max_execution_time) {
|
|
252
|
+
throw new SecurityError(`Execution time ${timeoutSeconds}s exceeds maximum allowed ${this.restrictions.max_execution_time}s`, {
|
|
253
|
+
requestedTime: timeoutSeconds,
|
|
254
|
+
maxAllowedTime: this.restrictions.max_execution_time,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
validateMemoryUsage(memoryMb) {
|
|
259
|
+
if (!this.restrictions?.active) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (this.restrictions.max_memory_mb && memoryMb > this.restrictions.max_memory_mb) {
|
|
263
|
+
throw new SecurityError(`Memory usage ${memoryMb}MB exceeds maximum allowed ${this.restrictions.max_memory_mb}MB`, {
|
|
264
|
+
requestedMemory: memoryMb,
|
|
265
|
+
maxAllowedMemory: this.restrictions.max_memory_mb,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
validateNetworkAccess() {
|
|
270
|
+
if (!this.restrictions?.active) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!this.restrictions.enable_network) {
|
|
274
|
+
throw new SecurityError('Network access is disabled by security policy');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// Legacy detectDangerousPatterns removed (Phase-out); rely on LLM & basic safety rules.
|
|
278
|
+
auditCommand(command, workingDirectory) {
|
|
279
|
+
// Enhanced Security Modeの場合は従来の危険パターン検出をスキップ
|
|
280
|
+
// Enhanced Safety Evaluator performs all validation
|
|
281
|
+
if (this.restrictions?.security_mode === 'enhanced' ||
|
|
282
|
+
this.restrictions?.security_mode === 'enhanced-fast') {
|
|
283
|
+
// Rely only on Enhanced Safety Evaluator
|
|
284
|
+
this.validateCommand(command);
|
|
285
|
+
if (workingDirectory) {
|
|
286
|
+
this.validatePath(workingDirectory);
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
// Legacy dangerous pattern blocking removed. Proceed to command/path validation.
|
|
291
|
+
// Additional security checks
|
|
292
|
+
this.validateCommand(command);
|
|
293
|
+
if (workingDirectory) {
|
|
294
|
+
this.validatePath(workingDirectory);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
isCommandAllowed(command, allowedCommands, blockedCommands) {
|
|
298
|
+
// Extract the first word (actual command name) from the command
|
|
299
|
+
const cmdName = command.trim().split(/\s+/)[0];
|
|
300
|
+
// Block if cmdName is empty
|
|
301
|
+
if (!cmdName) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
// Check blocked commands
|
|
305
|
+
if (blockedCommands && blockedCommands.length > 0) {
|
|
306
|
+
if (blockedCommands.some((blocked) => cmdName === blocked || cmdName.startsWith(blocked))) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Check allowed commands
|
|
311
|
+
if (allowedCommands && allowedCommands.length > 0) {
|
|
312
|
+
return allowedCommands.some((allowed) => cmdName === allowed || cmdName.startsWith(allowed));
|
|
313
|
+
}
|
|
314
|
+
// Allow if allowedCommands is not specified (only blockedCommands check)
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
// Enhanced Security Configuration Methods
|
|
318
|
+
/**
|
|
319
|
+
* Update enhanced security configuration
|
|
320
|
+
*/
|
|
321
|
+
setEnhancedConfig(config) {
|
|
322
|
+
this.enhancedConfig = { ...this.enhancedConfig, ...config };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get current enhanced security configuration
|
|
326
|
+
*/
|
|
327
|
+
getEnhancedConfig() {
|
|
328
|
+
return { ...this.enhancedConfig };
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Update basic safety rules
|
|
332
|
+
*/
|
|
333
|
+
setBasicSafetyRules(rules) {
|
|
334
|
+
this.basicSafetyRules = [...rules];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get current basic safety rules
|
|
338
|
+
*/
|
|
339
|
+
getBasicSafetyRules() {
|
|
340
|
+
return [...this.basicSafetyRules];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Check if enhanced security mode is enabled
|
|
344
|
+
*/
|
|
345
|
+
isEnhancedModeEnabled() {
|
|
346
|
+
const enabled = this.enhancedConfig.enhanced_mode_enabled;
|
|
347
|
+
console.error('isEnhancedModeEnabled() called:', enabled);
|
|
348
|
+
return enabled;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Check if LLM evaluation is enabled
|
|
352
|
+
*/
|
|
353
|
+
isLLMEvaluationEnabled() {
|
|
354
|
+
return this.enhancedConfig.llm_evaluation_enabled;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Check if command history enhancement is enabled
|
|
358
|
+
*/
|
|
359
|
+
isCommandHistoryEnhanced() {
|
|
360
|
+
return this.enhancedConfig.command_history_enhanced;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Detailed command safety analysis with reasoning
|
|
364
|
+
*/
|
|
365
|
+
analyzeCommandSafety(command) {
|
|
366
|
+
const trimmedCommand = command.trim();
|
|
367
|
+
if (!this.enhancedConfig.basic_safe_classification) {
|
|
368
|
+
return {
|
|
369
|
+
classification: 'llm_required',
|
|
370
|
+
reasoning: 'Basic safety classification is disabled',
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (!trimmedCommand) {
|
|
374
|
+
return {
|
|
375
|
+
classification: 'basic_safe',
|
|
376
|
+
reasoning: 'Empty command',
|
|
377
|
+
safety_level: 1,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
// (Legacy dangerous pattern shortcut removed – allow classification to fall through to rules/LLM.)
|
|
381
|
+
// Check basic safety rules
|
|
382
|
+
for (const rule of this.basicSafetyRules) {
|
|
383
|
+
try {
|
|
384
|
+
const regex = new RegExp(rule.pattern);
|
|
385
|
+
if (regex.test(trimmedCommand)) {
|
|
386
|
+
return {
|
|
387
|
+
classification: rule.safety_level <= 3 ? 'basic_safe' : 'llm_required',
|
|
388
|
+
reasoning: rule.reasoning,
|
|
389
|
+
safety_level: rule.safety_level,
|
|
390
|
+
matched_rule: rule.pattern,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
catch (e) {
|
|
395
|
+
// Skip invalid regex patterns
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
classification: 'llm_required',
|
|
401
|
+
reasoning: 'No matching safety rule found - requires LLM evaluation',
|
|
402
|
+
safety_level: 4,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Initialize Enhanced Safety Evaluator
|
|
407
|
+
*/
|
|
408
|
+
initializeEnhancedEvaluator(historyManager, server, createMessage, elicitationHandler) {
|
|
409
|
+
if (!this.enhancedConfig.enhanced_mode_enabled) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
this.historyManager = historyManager;
|
|
413
|
+
if (!createMessage) {
|
|
414
|
+
if (!server) {
|
|
415
|
+
throw new Error('Enhanced security mode requires an LLM provider but no server or LanguageModel adapter was provided.');
|
|
416
|
+
}
|
|
417
|
+
createMessage = createMessageCallbackFromMCPServer(server);
|
|
418
|
+
}
|
|
419
|
+
if (!server && !elicitationHandler) {
|
|
420
|
+
this.setEnhancedConfig({ elicitation_enabled: false });
|
|
421
|
+
}
|
|
422
|
+
this.enhancedEvaluator = new EnhancedSafetyEvaluator(this, historyManager, createMessage, server, elicitationHandler);
|
|
423
|
+
if (server) {
|
|
424
|
+
this.enhancedEvaluator.setMCPServer(server);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Perform comprehensive safety evaluation using enhanced evaluator
|
|
429
|
+
*/
|
|
430
|
+
async evaluateCommandSafetyByEnhancedEvaluator(command, workingDirectory, comment, forceUserConfirm) {
|
|
431
|
+
if (!this.enhancedConfig.enhanced_mode_enabled) {
|
|
432
|
+
throw new Error('Enhanced mode is not enabled');
|
|
433
|
+
}
|
|
434
|
+
if (!this.enhancedEvaluator) {
|
|
435
|
+
throw new Error('Enhanced evaluator not initialized');
|
|
436
|
+
}
|
|
437
|
+
// Get recent command history for context
|
|
438
|
+
const history = this.historyManager ? this.historyManager.searchHistory({ limit: 10 }) : [];
|
|
439
|
+
console.error(`[DEBUG] Enhanced Evaluator - Command: ${command}`);
|
|
440
|
+
console.error(`[DEBUG] Enhanced Evaluator - History entries: ${history.length}`);
|
|
441
|
+
console.error(`[DEBUG] Enhanced Evaluator - History commands: ${history.map((h) => h.command).join(', ')}`);
|
|
442
|
+
return await this.enhancedEvaluator.evaluateCommandSafety(command, workingDirectory, history, comment, forceUserConfirm);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
//# sourceMappingURL=manager.js.map
|