erosolar-cli 1.5.4 → 1.5.5
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/dist/active-stack-security.d.ts +110 -0
- package/dist/active-stack-security.js +313 -0
- package/dist/active-stack-security.js.map +1 -0
- package/dist/advanced-targeting.d.ts +113 -0
- package/dist/advanced-targeting.js +252 -0
- package/dist/advanced-targeting.js.map +1 -0
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +78 -8
- package/dist/core/agent.js.map +1 -1
- package/dist/core/contextManager.d.ts.map +1 -1
- package/dist/core/contextManager.js +117 -16
- package/dist/core/contextManager.js.map +1 -1
- package/dist/intelligence/codeIntelligence.d.ts.map +1 -1
- package/dist/intelligence/codeIntelligence.js +12 -0
- package/dist/intelligence/codeIntelligence.js.map +1 -1
- package/dist/security/active-stack-security.d.ts +112 -0
- package/dist/security/active-stack-security.d.ts.map +1 -0
- package/dist/security/active-stack-security.js +296 -0
- package/dist/security/active-stack-security.js.map +1 -0
- package/dist/security/advanced-targeting.d.ts +119 -0
- package/dist/security/advanced-targeting.d.ts.map +1 -0
- package/dist/security/advanced-targeting.js +233 -0
- package/dist/security/advanced-targeting.js.map +1 -0
- package/dist/security/comprehensive-targeting.d.ts +85 -0
- package/dist/security/comprehensive-targeting.d.ts.map +1 -0
- package/dist/security/comprehensive-targeting.js +438 -0
- package/dist/security/comprehensive-targeting.js.map +1 -0
- package/dist/security/global-security-integration.d.ts +91 -0
- package/dist/security/global-security-integration.d.ts.map +1 -0
- package/dist/security/global-security-integration.js +218 -0
- package/dist/security/global-security-integration.js.map +1 -0
- package/dist/security/index.d.ts +38 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +47 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/security-integration.d.ts +74 -0
- package/dist/security/security-integration.d.ts.map +1 -0
- package/dist/security/security-integration.js +137 -0
- package/dist/security/security-integration.js.map +1 -0
- package/dist/security/strategic-operations.d.ts +100 -0
- package/dist/security/strategic-operations.d.ts.map +1 -0
- package/dist/security/strategic-operations.js +276 -0
- package/dist/security/strategic-operations.js.map +1 -0
- package/dist/security/tool-security-wrapper.d.ts +58 -0
- package/dist/security/tool-security-wrapper.d.ts.map +1 -0
- package/dist/security/tool-security-wrapper.js +156 -0
- package/dist/security/tool-security-wrapper.js.map +1 -0
- package/dist/tools/codeAnalysisTools.d.ts.map +1 -1
- package/dist/tools/codeAnalysisTools.js +23 -1
- package/dist/tools/codeAnalysisTools.js.map +1 -1
- package/dist/tools/fileTools.d.ts.map +1 -1
- package/dist/tools/fileTools.js +7 -0
- package/dist/tools/fileTools.js.map +1 -1
- package/dist/tools/grepTools.d.ts.map +1 -1
- package/dist/tools/grepTools.js +6 -0
- package/dist/tools/grepTools.js.map +1 -1
- package/dist/tools/webTools.js +9 -0
- package/dist/tools/webTools.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategic Operations Framework
|
|
3
|
+
*
|
|
4
|
+
* Provides strategic operations capabilities for comprehensive coverage
|
|
5
|
+
* of companies, countries, and global entities with proper authorization
|
|
6
|
+
* and geopolitical considerations.
|
|
7
|
+
*
|
|
8
|
+
* @license MIT
|
|
9
|
+
* @author Bo Shang
|
|
10
|
+
*/
|
|
11
|
+
import { globalSecurityIntegration } from './global-security-integration.js';
|
|
12
|
+
import { ComprehensiveTargeting } from './comprehensive-targeting.js';
|
|
13
|
+
export class StrategicOperations {
|
|
14
|
+
comprehensiveTargeting;
|
|
15
|
+
activeOperations = new Map();
|
|
16
|
+
constructor() {
|
|
17
|
+
this.comprehensiveTargeting = new ComprehensiveTargeting();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Plan a strategic operation
|
|
21
|
+
*/
|
|
22
|
+
planOperation(targetIdentifier, operationType, objectives) {
|
|
23
|
+
const target = this.comprehensiveTargeting.getStrategicEntity(targetIdentifier);
|
|
24
|
+
if (!target) {
|
|
25
|
+
console.warn(`Target ${targetIdentifier} not found in strategic entities`);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
// Validate operation authorization
|
|
29
|
+
if (!target.authorizedOperations.includes(operationType)) {
|
|
30
|
+
console.warn(`Operation ${operationType} not authorized for target ${targetIdentifier}`);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const operation = {
|
|
34
|
+
id: this.generateOperationId(),
|
|
35
|
+
target,
|
|
36
|
+
operationType: operationType,
|
|
37
|
+
objectives,
|
|
38
|
+
riskAssessment: this.assessRisks(target, operationType),
|
|
39
|
+
authorization: this.determineAuthorization(target, operationType),
|
|
40
|
+
constraints: this.determineConstraints(target, operationType)
|
|
41
|
+
};
|
|
42
|
+
this.activeOperations.set(operation.id, operation);
|
|
43
|
+
return operation;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute a strategic operation
|
|
47
|
+
*/
|
|
48
|
+
async executeOperation(operationId, parameters) {
|
|
49
|
+
const operation = this.activeOperations.get(operationId);
|
|
50
|
+
if (!operation) {
|
|
51
|
+
throw new Error(`Operation ${operationId} not found`);
|
|
52
|
+
}
|
|
53
|
+
// Validate operation with global security
|
|
54
|
+
const validation = globalSecurityIntegration.validateGlobalOperation(this.getToolForOperation(operation.operationType), parameters, {
|
|
55
|
+
type: 'external',
|
|
56
|
+
target: operation.target.identifier,
|
|
57
|
+
operation: operation.operationType
|
|
58
|
+
});
|
|
59
|
+
if (!validation.allowed) {
|
|
60
|
+
throw new Error(`Operation validation failed: ${validation.reason}`);
|
|
61
|
+
}
|
|
62
|
+
// Log strategic operation
|
|
63
|
+
this.logStrategicOperation(operation, 'execution_started', parameters);
|
|
64
|
+
// Execute the operation (simulated - actual tool execution handled by tool runtime)
|
|
65
|
+
try {
|
|
66
|
+
const toolName = this.getToolForOperation(operation.operationType);
|
|
67
|
+
const result = {
|
|
68
|
+
operationId: operation.id,
|
|
69
|
+
toolName,
|
|
70
|
+
parameters,
|
|
71
|
+
status: 'completed',
|
|
72
|
+
timestamp: new Date().toISOString()
|
|
73
|
+
};
|
|
74
|
+
this.logStrategicOperation(operation, 'execution_completed', { result });
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.logStrategicOperation(operation, 'execution_failed', { error: error instanceof Error ? error.message : String(error) });
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get strategic entities by type
|
|
84
|
+
*/
|
|
85
|
+
getStrategicEntitiesByType(type) {
|
|
86
|
+
return this.comprehensiveTargeting.getEntitiesByType(type);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get strategic entities by level
|
|
90
|
+
*/
|
|
91
|
+
getStrategicEntitiesByLevel(level) {
|
|
92
|
+
return this.comprehensiveTargeting.getEntitiesByStrategicLevel(level);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all strategic entities
|
|
96
|
+
*/
|
|
97
|
+
getAllStrategicEntities() {
|
|
98
|
+
return this.comprehensiveTargeting.getAllStrategicEntities();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate strategic operations report
|
|
102
|
+
*/
|
|
103
|
+
generateStrategicReport() {
|
|
104
|
+
const entities = this.getAllStrategicEntities();
|
|
105
|
+
const activeOps = Array.from(this.activeOperations.values());
|
|
106
|
+
const report = [
|
|
107
|
+
'🎯 Strategic Operations Report',
|
|
108
|
+
'==============================',
|
|
109
|
+
`Total Strategic Entities: ${entities.length}`,
|
|
110
|
+
`Active Operations: ${activeOps.length}`,
|
|
111
|
+
'',
|
|
112
|
+
'🏢 Technology Companies:',
|
|
113
|
+
...this.getStrategicEntitiesByType('company').map(entity => ` • ${entity.identifier} [${entity.strategicLevel}] - ${entity.geopolitical.jurisdiction}`),
|
|
114
|
+
'',
|
|
115
|
+
'🌍 Countries:',
|
|
116
|
+
...this.getStrategicEntitiesByType('country').map(entity => ` • ${entity.identifier} [${entity.strategicLevel}] - ${entity.geopolitical.alliances.join(', ')}`),
|
|
117
|
+
'',
|
|
118
|
+
'🤝 Strategic Alliances:',
|
|
119
|
+
...this.getStrategicEntitiesByType('alliance').map(entity => ` • ${entity.identifier} [${entity.strategicLevel}]`),
|
|
120
|
+
'',
|
|
121
|
+
'⚡ Critical Infrastructure:',
|
|
122
|
+
' • Global Power Grid [critical]',
|
|
123
|
+
' • Global Financial System [critical]',
|
|
124
|
+
' • Global Communications [critical]',
|
|
125
|
+
' • Global Transportation [high]',
|
|
126
|
+
' • Global Healthcare [high]',
|
|
127
|
+
'',
|
|
128
|
+
'📊 Strategic Distribution:',
|
|
129
|
+
` Critical: ${this.getStrategicEntitiesByLevel('critical').length}`,
|
|
130
|
+
` High: ${this.getStrategicEntitiesByLevel('high').length}`,
|
|
131
|
+
` Medium: ${this.getStrategicEntitiesByLevel('medium').length}`,
|
|
132
|
+
` Low: ${this.getStrategicEntitiesByLevel('low').length}`,
|
|
133
|
+
'',
|
|
134
|
+
'🔐 Security Classifications:',
|
|
135
|
+
` Public: ${entities.filter(e => e.securityClassification === 'public').length}`,
|
|
136
|
+
` Restricted: ${entities.filter(e => e.securityClassification === 'restricted').length}`,
|
|
137
|
+
` Confidential: ${entities.filter(e => e.securityClassification === 'confidential').length}`,
|
|
138
|
+
` Secret: ${entities.filter(e => e.securityClassification === 'secret').length}`
|
|
139
|
+
];
|
|
140
|
+
if (activeOps.length > 0) {
|
|
141
|
+
report.push('', '🚀 Active Operations:');
|
|
142
|
+
activeOps.forEach(op => {
|
|
143
|
+
report.push(` • ${op.id}: ${op.operationType} on ${op.target.identifier} [${op.riskAssessment.overallRisk} risk]`);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return report.join('\n');
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Assess risks for an operation
|
|
150
|
+
*/
|
|
151
|
+
assessRisks(target, _operationType) {
|
|
152
|
+
// Simplified risk assessment - in practice this would be more sophisticated
|
|
153
|
+
let geopoliticalRisk = 'low';
|
|
154
|
+
let operationalRisk = 'low';
|
|
155
|
+
let legalRisk = 'low';
|
|
156
|
+
// Geopolitical risk based on alliances and sanctions
|
|
157
|
+
if (target.geopolitical.sanctions.length > 0) {
|
|
158
|
+
geopoliticalRisk = 'high';
|
|
159
|
+
}
|
|
160
|
+
else if (target.geopolitical.alliances.includes('NATO') || target.geopolitical.alliances.includes('Five Eyes')) {
|
|
161
|
+
geopoliticalRisk = 'medium';
|
|
162
|
+
}
|
|
163
|
+
// Operational risk based on strategic level
|
|
164
|
+
if (target.strategicLevel === 'critical') {
|
|
165
|
+
operationalRisk = 'high';
|
|
166
|
+
}
|
|
167
|
+
else if (target.strategicLevel === 'high') {
|
|
168
|
+
operationalRisk = 'medium';
|
|
169
|
+
}
|
|
170
|
+
// Legal risk based on security classification
|
|
171
|
+
if (target.securityClassification === 'secret') {
|
|
172
|
+
legalRisk = 'critical';
|
|
173
|
+
}
|
|
174
|
+
else if (target.securityClassification === 'confidential') {
|
|
175
|
+
legalRisk = 'high';
|
|
176
|
+
}
|
|
177
|
+
else if (target.securityClassification === 'restricted') {
|
|
178
|
+
legalRisk = 'medium';
|
|
179
|
+
}
|
|
180
|
+
// Overall risk is the highest of the three
|
|
181
|
+
const overallRisk = [geopoliticalRisk, operationalRisk, legalRisk].reduce((highest, current) => {
|
|
182
|
+
const riskLevels = { low: 0, medium: 1, high: 2, critical: 3 };
|
|
183
|
+
return riskLevels[current] > riskLevels[highest] ? current : highest;
|
|
184
|
+
}, 'low');
|
|
185
|
+
return {
|
|
186
|
+
geopoliticalRisk,
|
|
187
|
+
operationalRisk,
|
|
188
|
+
legalRisk,
|
|
189
|
+
overallRisk
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Determine authorization requirements
|
|
194
|
+
*/
|
|
195
|
+
determineAuthorization(target, _operationType) {
|
|
196
|
+
const level = target.strategicLevel === 'critical' ? 'analysis' : 'research';
|
|
197
|
+
const approvals = ['security_team'];
|
|
198
|
+
let legalReview = false;
|
|
199
|
+
let seniorLeadership = false;
|
|
200
|
+
if (target.strategicLevel === 'critical') {
|
|
201
|
+
approvals.push('director_level');
|
|
202
|
+
legalReview = true;
|
|
203
|
+
}
|
|
204
|
+
if (target.securityClassification === 'secret' || target.securityClassification === 'confidential') {
|
|
205
|
+
approvals.push('legal_department');
|
|
206
|
+
legalReview = true;
|
|
207
|
+
}
|
|
208
|
+
if (target.strategicLevel === 'critical' && target.securityClassification === 'secret') {
|
|
209
|
+
seniorLeadership = true;
|
|
210
|
+
approvals.push('senior_leadership');
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
level,
|
|
214
|
+
approvals,
|
|
215
|
+
legalReview,
|
|
216
|
+
seniorLeadership
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Determine operational constraints
|
|
221
|
+
*/
|
|
222
|
+
determineConstraints(target, _operationType) {
|
|
223
|
+
const constraints = {
|
|
224
|
+
legalRestrictions: ['responsible_disclosure']
|
|
225
|
+
};
|
|
226
|
+
if (target.strategicLevel === 'critical') {
|
|
227
|
+
constraints.timeWindow = 'business_hours_only';
|
|
228
|
+
constraints.resourceLimits = ['monitored_execution', 'limited_scope'];
|
|
229
|
+
}
|
|
230
|
+
if (target.securityClassification === 'secret') {
|
|
231
|
+
constraints.legalRestrictions.push('classified_handling', 'need_to_know_basis');
|
|
232
|
+
constraints.ethicalConsiderations = ['national_security_implications'];
|
|
233
|
+
}
|
|
234
|
+
if (target.geopolitical.sanctions.length > 0) {
|
|
235
|
+
constraints.legalRestrictions.push('sanctions_compliance');
|
|
236
|
+
}
|
|
237
|
+
return constraints;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get appropriate tool for operation type
|
|
241
|
+
*/
|
|
242
|
+
getToolForOperation(operationType) {
|
|
243
|
+
const toolMap = {
|
|
244
|
+
'security_analysis': 'WebFetch',
|
|
245
|
+
'vulnerability_assessment': 'WebSearch',
|
|
246
|
+
'threat_intelligence': 'WebSearch',
|
|
247
|
+
'defensive_research': 'WebFetch',
|
|
248
|
+
'compliance_audit': 'WebFetch'
|
|
249
|
+
};
|
|
250
|
+
return toolMap[operationType] || 'WebSearch';
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Generate unique operation ID
|
|
254
|
+
*/
|
|
255
|
+
generateOperationId() {
|
|
256
|
+
return `STRAT-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Log strategic operation
|
|
260
|
+
*/
|
|
261
|
+
logStrategicOperation(operation, status, details) {
|
|
262
|
+
console.log(`🎯 Strategic Operation ${operation.id}: ${status}`);
|
|
263
|
+
console.log(` Target: ${operation.target.identifier}`);
|
|
264
|
+
console.log(` Type: ${operation.operationType}`);
|
|
265
|
+
console.log(` Risk: ${operation.riskAssessment.overallRisk}`);
|
|
266
|
+
if (Object.keys(details).length > 0) {
|
|
267
|
+
console.log(` Details: ${JSON.stringify(details)}`);
|
|
268
|
+
}
|
|
269
|
+
console.log('');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Global strategic operations instance
|
|
274
|
+
*/
|
|
275
|
+
export const strategicOperations = new StrategicOperations();
|
|
276
|
+
//# sourceMappingURL=strategic-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategic-operations.js","sourceRoot":"","sources":["../../src/security/strategic-operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAwB,MAAM,8BAA8B,CAAC;AAkC5F,MAAM,OAAO,mBAAmB;IACtB,sBAAsB,CAAyB;IAC/C,gBAAgB,GAAoC,IAAI,GAAG,EAAE,CAAC;IAEtE;QACE,IA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C,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC1E,CAAC;IAED;;OAEG;IACK,qBAAqB,CAAC,SAA6B,EAAE,MAAc,EAAE,OAAgC;QAC3G,OAAO,CAAC,GAAG,CAAC,0BAA0B,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,CAAC,GAAG,CAAC,cAAc,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,YAAY,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,YAAY,SAAS,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC;QAChE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Security Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps tool execution with active stack security validation.
|
|
5
|
+
* Ensures all operations are scoped to the active stack only.
|
|
6
|
+
*
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @author Bo Shang
|
|
9
|
+
*/
|
|
10
|
+
import { type SecurityValidationResult } from './active-stack-security.js';
|
|
11
|
+
export declare class ToolSecurityWrapper {
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Execute a tool with security validation
|
|
15
|
+
*/
|
|
16
|
+
executeTool(toolName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Validate tool operation based on tool type and arguments
|
|
19
|
+
*/
|
|
20
|
+
private validateToolOperation;
|
|
21
|
+
/**
|
|
22
|
+
* Validate file operations
|
|
23
|
+
*/
|
|
24
|
+
private validateFileOperation;
|
|
25
|
+
/**
|
|
26
|
+
* Validate command execution
|
|
27
|
+
*/
|
|
28
|
+
private validateCommandExecution;
|
|
29
|
+
/**
|
|
30
|
+
* Validate network operations
|
|
31
|
+
*/
|
|
32
|
+
private validateNetworkOperation;
|
|
33
|
+
/**
|
|
34
|
+
* Validate generic operations
|
|
35
|
+
*/
|
|
36
|
+
private validateGenericOperation;
|
|
37
|
+
/**
|
|
38
|
+
* Get security log
|
|
39
|
+
*/
|
|
40
|
+
getSecurityLog(): import("./active-stack-security.js").SecurityEvent[];
|
|
41
|
+
/**
|
|
42
|
+
* Clear security log
|
|
43
|
+
*/
|
|
44
|
+
clearSecurityLog(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Internal tool execution (placeholder implementation)
|
|
47
|
+
*/
|
|
48
|
+
private executeToolInternal;
|
|
49
|
+
}
|
|
50
|
+
export declare class SecurityError extends Error {
|
|
51
|
+
readonly validationResult: SecurityValidationResult;
|
|
52
|
+
constructor(message: string, validationResult: SecurityValidationResult);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a secure tool runtime wrapper
|
|
56
|
+
*/
|
|
57
|
+
export declare function createSecureToolRuntime(): ToolSecurityWrapper;
|
|
58
|
+
//# sourceMappingURL=tool-security-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-security-wrapper.d.ts","sourceRoot":"","sources":["../../src/security/tool-security-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAuB,KAAK,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEhG,qBAAa,mBAAmB;;IAK9B;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAapF;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAuB7B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAc7B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAahC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAqBhC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAmBhC;;OAEG;IACH,cAAc;IAId;;OAEG;IACH,gBAAgB;IAIhB;;OAEG;YACW,mBAAmB;CAKlC;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,gBAAgB,EAAE,wBAAwB,CAAC;gBAE/C,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,wBAAwB;CAKxE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,mBAAmB,CAE7D"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Security Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps tool execution with active stack security validation.
|
|
5
|
+
* Ensures all operations are scoped to the active stack only.
|
|
6
|
+
*
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @author Bo Shang
|
|
9
|
+
*/
|
|
10
|
+
import { activeStackSecurity } from './active-stack-security.js';
|
|
11
|
+
export class ToolSecurityWrapper {
|
|
12
|
+
constructor() {
|
|
13
|
+
// Tool runtime would be initialized here in a real implementation
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute a tool with security validation
|
|
17
|
+
*/
|
|
18
|
+
async executeTool(toolName, args) {
|
|
19
|
+
// Validate the tool operation based on tool type
|
|
20
|
+
const validation = this.validateToolOperation(toolName, args);
|
|
21
|
+
if (!validation.allowed) {
|
|
22
|
+
throw new SecurityError(`Tool execution blocked: ${validation.reason}`, validation);
|
|
23
|
+
}
|
|
24
|
+
// Execute the actual tool
|
|
25
|
+
// Note: This would need to be adapted to the actual ToolRuntime interface
|
|
26
|
+
// For now, we'll assume a simplified interface
|
|
27
|
+
return await this.executeToolInternal(toolName, args);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate tool operation based on tool type and arguments
|
|
31
|
+
*/
|
|
32
|
+
validateToolOperation(toolName, args) {
|
|
33
|
+
switch (toolName) {
|
|
34
|
+
case 'read_file':
|
|
35
|
+
case 'write_file':
|
|
36
|
+
case 'list_files':
|
|
37
|
+
case 'search_files':
|
|
38
|
+
return this.validateFileOperation(toolName, args);
|
|
39
|
+
case 'execute_bash':
|
|
40
|
+
case 'execute_bash_stream':
|
|
41
|
+
return this.validateCommandExecution(args);
|
|
42
|
+
case 'WebFetch':
|
|
43
|
+
case 'WebExtract':
|
|
44
|
+
case 'WebSearch':
|
|
45
|
+
return this.validateNetworkOperation(toolName, args);
|
|
46
|
+
default:
|
|
47
|
+
// For unknown tools, apply general security validation
|
|
48
|
+
return this.validateGenericOperation(args);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validate file operations
|
|
53
|
+
*/
|
|
54
|
+
validateFileOperation(toolName, args) {
|
|
55
|
+
const path = args['path'];
|
|
56
|
+
if (!path) {
|
|
57
|
+
return {
|
|
58
|
+
allowed: false,
|
|
59
|
+
reason: 'Missing file path',
|
|
60
|
+
severity: 'medium',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const operation = toolName === 'write_file' ? 'write' : 'read';
|
|
64
|
+
return activeStackSecurity.validateFileOperation(path, operation);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate command execution
|
|
68
|
+
*/
|
|
69
|
+
validateCommandExecution(args) {
|
|
70
|
+
const command = args['command'];
|
|
71
|
+
if (!command) {
|
|
72
|
+
return {
|
|
73
|
+
allowed: false,
|
|
74
|
+
reason: 'Missing command',
|
|
75
|
+
severity: 'medium',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return activeStackSecurity.validateCommandExecution(command);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validate network operations
|
|
82
|
+
*/
|
|
83
|
+
validateNetworkOperation(toolName, args) {
|
|
84
|
+
let target;
|
|
85
|
+
if (toolName === 'WebFetch' || toolName === 'WebExtract') {
|
|
86
|
+
target = args['url'];
|
|
87
|
+
}
|
|
88
|
+
else if (toolName === 'WebSearch') {
|
|
89
|
+
target = args['query'];
|
|
90
|
+
}
|
|
91
|
+
if (!target) {
|
|
92
|
+
return {
|
|
93
|
+
allowed: false,
|
|
94
|
+
reason: 'Missing target/query',
|
|
95
|
+
severity: 'medium',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const operation = toolName.toLowerCase().replace('web', '');
|
|
99
|
+
return activeStackSecurity.validateNetworkOperation(target, operation);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Validate generic operations
|
|
103
|
+
*/
|
|
104
|
+
validateGenericOperation(args) {
|
|
105
|
+
// Check for any file paths in arguments
|
|
106
|
+
for (const [key, value] of Object.entries(args)) {
|
|
107
|
+
if (typeof value === 'string' && value.includes('/')) {
|
|
108
|
+
const pathValidation = activeStackSecurity.validateFileOperation(value, 'read');
|
|
109
|
+
if (!pathValidation.allowed) {
|
|
110
|
+
return {
|
|
111
|
+
allowed: false,
|
|
112
|
+
reason: `Invalid file path in argument '${key}': ${pathValidation.reason}`,
|
|
113
|
+
severity: pathValidation.severity,
|
|
114
|
+
details: pathValidation.details,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { allowed: true, severity: 'low' };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get security log
|
|
123
|
+
*/
|
|
124
|
+
getSecurityLog() {
|
|
125
|
+
return activeStackSecurity.getSecurityLog();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Clear security log
|
|
129
|
+
*/
|
|
130
|
+
clearSecurityLog() {
|
|
131
|
+
activeStackSecurity.clearSecurityLog();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Internal tool execution (placeholder implementation)
|
|
135
|
+
*/
|
|
136
|
+
async executeToolInternal(toolName, args) {
|
|
137
|
+
// This would call the actual ToolRuntime method
|
|
138
|
+
// For demonstration purposes, we return a mock result
|
|
139
|
+
return { success: true, tool: toolName, args };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export class SecurityError extends Error {
|
|
143
|
+
validationResult;
|
|
144
|
+
constructor(message, validationResult) {
|
|
145
|
+
super(message);
|
|
146
|
+
this.name = 'SecurityError';
|
|
147
|
+
this.validationResult = validationResult;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Create a secure tool runtime wrapper
|
|
152
|
+
*/
|
|
153
|
+
export function createSecureToolRuntime() {
|
|
154
|
+
return new ToolSecurityWrapper();
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=tool-security-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-security-wrapper.js","sourceRoot":"","sources":["../../src/security/tool-security-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAiC,MAAM,4BAA4B,CAAC;AAEhG,MAAM,OAAO,mBAAmB;IAC9B;QACE,kEAAkE;IACpE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,QAAgB,EAAE,IAA6B;QAC/D,iDAAiD;QACjD,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACxB,MAAM,IAAI,aAAa,CAAC,2BAA2B,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;QACtF,CAAC;QAED,0BAA0B;QAC1B,0EAA0E;QAC1E,+CAA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BAC5B,OAAO;wBACL,OAAO,EAAE,KAAK;wBACd,MAAM,EAAE,kCAAkC,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE;wBAC1E,QAAQ,EAAE,cAAc,CAAC,QAAQ;wBACjC,OAAO,EAAE,cAAc,CAAC,OAAO;qBAChC,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,mBAAmB,CAAC,cAAc,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,mBAAmB,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,mBAAmB,CAAC,QAAgB,EAAE,IAA6B;QAC/E,gDAAgD;QAChD,sDAAsD;QACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjD,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtB,gBAAgB,CAA2B;IAE3D,YAAY,OAAe,EAAE,gBAA0C;QACrE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeAnalysisTools.d.ts","sourceRoot":"","sources":["../../src/tools/codeAnalysisTools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"codeAnalysisTools.d.ts","sourceRoot":"","sources":["../../src/tools/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W,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,QAAQ,GAAG,gBAAgB,GAAG,OAAO,CAAC;AAE/E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,yBAAyB,EAAE,MAAM,CAAC;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,EAAE,CAgJ5E;AAcD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CA8G3F;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,yBAAyB,CAkHvG"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
1
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
+
// Maximum file size for code analysis (2MB) to prevent memory exhaustion
|
|
5
|
+
const MAX_ANALYSIS_FILE_SIZE = 2 * 1024 * 1024;
|
|
4
6
|
export function createCodeAnalysisTools(workingDir) {
|
|
5
7
|
return [
|
|
6
8
|
{
|
|
@@ -23,6 +25,11 @@ export function createCodeAnalysisTools(workingDir) {
|
|
|
23
25
|
if (!existsSync(filePath)) {
|
|
24
26
|
return `Error: File not found: ${filePath}`;
|
|
25
27
|
}
|
|
28
|
+
// Check file size to prevent memory exhaustion
|
|
29
|
+
const stats = statSync(filePath);
|
|
30
|
+
if (stats.size > MAX_ANALYSIS_FILE_SIZE) {
|
|
31
|
+
return `Error: File too large (${(stats.size / 1024 / 1024).toFixed(1)}MB). Maximum: ${MAX_ANALYSIS_FILE_SIZE / 1024 / 1024}MB`;
|
|
32
|
+
}
|
|
26
33
|
const content = readFileSync(filePath, 'utf-8');
|
|
27
34
|
const analysis = analyzeTypeScriptFile(content, filePath);
|
|
28
35
|
return formatAnalysisResults(analysis);
|
|
@@ -52,6 +59,11 @@ export function createCodeAnalysisTools(workingDir) {
|
|
|
52
59
|
if (!existsSync(filePath)) {
|
|
53
60
|
return `Error: File not found: ${filePath}`;
|
|
54
61
|
}
|
|
62
|
+
// Check file size to prevent memory exhaustion
|
|
63
|
+
const stats = statSync(filePath);
|
|
64
|
+
if (stats.size > MAX_ANALYSIS_FILE_SIZE) {
|
|
65
|
+
return `Error: File too large (${(stats.size / 1024 / 1024).toFixed(1)}MB). Maximum: ${MAX_ANALYSIS_FILE_SIZE / 1024 / 1024}MB`;
|
|
66
|
+
}
|
|
55
67
|
const content = readFileSync(filePath, 'utf-8');
|
|
56
68
|
const analysis = analyzeTypeScriptFile(content, filePath);
|
|
57
69
|
return formatDependencies(analysis);
|
|
@@ -81,6 +93,11 @@ export function createCodeAnalysisTools(workingDir) {
|
|
|
81
93
|
if (!existsSync(filePath)) {
|
|
82
94
|
return `Error: File not found: ${filePath}`;
|
|
83
95
|
}
|
|
96
|
+
// Check file size to prevent memory exhaustion
|
|
97
|
+
const stats = statSync(filePath);
|
|
98
|
+
if (stats.size > MAX_ANALYSIS_FILE_SIZE) {
|
|
99
|
+
return `Error: File too large (${(stats.size / 1024 / 1024).toFixed(1)}MB). Maximum: ${MAX_ANALYSIS_FILE_SIZE / 1024 / 1024}MB`;
|
|
100
|
+
}
|
|
84
101
|
const content = readFileSync(filePath, 'utf-8');
|
|
85
102
|
const analysis = analyzeTypeScriptFile(content, filePath);
|
|
86
103
|
return formatComplexityMetrics(analysis);
|
|
@@ -110,6 +127,11 @@ export function createCodeAnalysisTools(workingDir) {
|
|
|
110
127
|
if (!existsSync(filePath)) {
|
|
111
128
|
return `Error: File not found: ${filePath}`;
|
|
112
129
|
}
|
|
130
|
+
// Check file size to prevent memory exhaustion
|
|
131
|
+
const stats = statSync(filePath);
|
|
132
|
+
if (stats.size > MAX_ANALYSIS_FILE_SIZE) {
|
|
133
|
+
return `Error: File too large (${(stats.size / 1024 / 1024).toFixed(1)}MB). Maximum: ${MAX_ANALYSIS_FILE_SIZE / 1024 / 1024}MB`;
|
|
134
|
+
}
|
|
113
135
|
const content = readFileSync(filePath, 'utf-8');
|
|
114
136
|
const analysis = performAdvancedAstAnalysis(content, filePath);
|
|
115
137
|
return formatAstAnalysis(analysis);
|