@paths.design/caws-cli 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +295 -150
- package/dist/budget-derivation.d.ts +35 -0
- package/dist/budget-derivation.d.ts.map +1 -0
- package/dist/budget-derivation.js +204 -0
- package/dist/cicd-optimizer.d.ts +142 -0
- package/dist/cicd-optimizer.d.ts.map +1 -0
- package/dist/cicd-optimizer.js +504 -0
- package/dist/commands/burnup.d.ts +6 -0
- package/dist/commands/burnup.d.ts.map +1 -0
- package/dist/commands/burnup.js +90 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +514 -0
- package/dist/commands/provenance.d.ts +22 -0
- package/dist/commands/provenance.d.ts.map +1 -0
- package/dist/commands/provenance.js +594 -0
- package/dist/commands/tool.d.ts +13 -0
- package/dist/commands/tool.d.ts.map +1 -0
- package/dist/commands/tool.js +138 -0
- package/dist/commands/validate.d.ts +7 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +80 -0
- package/dist/config/index.d.ts +29 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +132 -0
- package/dist/error-handler.d.ts +50 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +253 -0
- package/dist/generators/working-spec.d.ts +13 -0
- package/dist/generators/working-spec.d.ts.map +1 -0
- package/dist/generators/working-spec.js +204 -0
- package/dist/index-new.d.ts +5 -0
- package/dist/index-new.d.ts.map +1 -0
- package/dist/index-new.js +317 -0
- package/dist/index.d.ts +3 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -1659
- package/dist/index.js.backup +4711 -0
- package/dist/scaffold/cursor-hooks.d.ts +7 -0
- package/dist/scaffold/cursor-hooks.d.ts.map +1 -0
- package/dist/scaffold/cursor-hooks.js +152 -0
- package/dist/scaffold/index.d.ts +20 -0
- package/dist/scaffold/index.d.ts.map +1 -0
- package/dist/scaffold/index.js +486 -0
- package/dist/test-analysis.d.ts +182 -0
- package/dist/test-analysis.d.ts.map +1 -0
- package/dist/test-analysis.js +580 -0
- package/dist/tool-interface.d.ts +236 -0
- package/dist/tool-interface.d.ts.map +1 -0
- package/dist/tool-interface.js +314 -0
- package/dist/tool-loader.d.ts +77 -0
- package/dist/tool-loader.d.ts.map +1 -0
- package/dist/tool-loader.js +298 -0
- package/dist/tool-validator.d.ts +72 -0
- package/dist/tool-validator.d.ts.map +1 -0
- package/dist/tool-validator.js +387 -0
- package/dist/utils/detection.d.ts +7 -0
- package/dist/utils/detection.d.ts.map +1 -0
- package/dist/utils/detection.js +174 -0
- package/dist/utils/finalization.d.ts +17 -0
- package/dist/utils/finalization.d.ts.map +1 -0
- package/dist/utils/finalization.js +229 -0
- package/dist/utils/project-analysis.d.ts +14 -0
- package/dist/utils/project-analysis.d.ts.map +1 -0
- package/dist/utils/project-analysis.js +105 -0
- package/dist/validation/spec-validation.d.ts +29 -0
- package/dist/validation/spec-validation.d.ts.map +1 -0
- package/dist/validation/spec-validation.js +376 -0
- package/dist/waivers-manager.d.ts +167 -0
- package/dist/waivers-manager.d.ts.map +1 -0
- package/dist/waivers-manager.js +549 -0
- package/package.json +10 -12
- package/templates/.cursor/README.md +311 -0
- package/templates/.cursor/hooks/audit.sh +55 -0
- package/templates/.cursor/hooks/block-dangerous.sh +77 -0
- package/templates/.cursor/hooks/caws-quality-check.sh +52 -0
- package/templates/.cursor/hooks/caws-scope-guard.sh +74 -0
- package/templates/.cursor/hooks/caws-tool-validation.sh +121 -0
- package/templates/.cursor/hooks/format.sh +38 -0
- package/templates/.cursor/hooks/naming-check.sh +64 -0
- package/templates/.cursor/hooks/scan-secrets.sh +46 -0
- package/templates/.cursor/hooks/scope-guard.sh +52 -0
- package/templates/.cursor/hooks/validate-spec.sh +38 -0
- package/templates/.cursor/hooks.json +59 -0
- package/templates/.github/copilot/instructions.md +311 -0
- package/templates/.idea/runConfigurations/CAWS_Evaluate.xml +5 -0
- package/templates/.idea/runConfigurations/CAWS_Validate.xml +5 -0
- package/templates/.vscode/launch.json +56 -0
- package/templates/.vscode/settings.json +93 -0
- package/templates/.windsurf/workflows/caws-guided-development.md +92 -0
- package/templates/apps/tools/caws/README.md +1 -1
- package/templates/apps/tools/caws/prompt-lint.js.backup +274 -0
- package/templates/apps/tools/caws/provenance.js.backup +73 -0
- package/templates/apps/tools/caws/schemas/working-spec.schema.json +21 -3
- package/templates/codemod/test.js +93 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Standard tool execution result
|
|
4
|
+
*/
|
|
5
|
+
export type ToolExecutionResult = {
|
|
6
|
+
/**
|
|
7
|
+
* - Whether execution succeeded
|
|
8
|
+
*/
|
|
9
|
+
success: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* - Execution duration in milliseconds
|
|
12
|
+
*/
|
|
13
|
+
duration: number;
|
|
14
|
+
/**
|
|
15
|
+
* - Tool-specific output data
|
|
16
|
+
*/
|
|
17
|
+
output: any;
|
|
18
|
+
/**
|
|
19
|
+
* - Error messages if execution failed
|
|
20
|
+
*/
|
|
21
|
+
errors: Array<string>;
|
|
22
|
+
/**
|
|
23
|
+
* - Additional execution metadata
|
|
24
|
+
*/
|
|
25
|
+
metadata: any;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Tool metadata structure
|
|
29
|
+
*/
|
|
30
|
+
export type ToolMetadata = {
|
|
31
|
+
/**
|
|
32
|
+
* - Unique tool identifier
|
|
33
|
+
*/
|
|
34
|
+
id: string;
|
|
35
|
+
/**
|
|
36
|
+
* - Human-readable tool name
|
|
37
|
+
*/
|
|
38
|
+
name: string;
|
|
39
|
+
/**
|
|
40
|
+
* - Tool version (semver)
|
|
41
|
+
*/
|
|
42
|
+
version: string;
|
|
43
|
+
/**
|
|
44
|
+
* - Tool description
|
|
45
|
+
*/
|
|
46
|
+
description: string;
|
|
47
|
+
/**
|
|
48
|
+
* - Tool capabilities (e.g., ['validation', 'security'])
|
|
49
|
+
*/
|
|
50
|
+
capabilities: Array<string>;
|
|
51
|
+
/**
|
|
52
|
+
* - Tool author
|
|
53
|
+
*/
|
|
54
|
+
author: string;
|
|
55
|
+
/**
|
|
56
|
+
* - Tool license
|
|
57
|
+
*/
|
|
58
|
+
license: string;
|
|
59
|
+
/**
|
|
60
|
+
* - Required Node.js dependencies
|
|
61
|
+
*/
|
|
62
|
+
dependencies: Array<string>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Tool execution context
|
|
66
|
+
*/
|
|
67
|
+
export type ToolExecutionContext = {
|
|
68
|
+
/**
|
|
69
|
+
* - Current working directory
|
|
70
|
+
*/
|
|
71
|
+
workingDirectory: string;
|
|
72
|
+
/**
|
|
73
|
+
* - Environment variables
|
|
74
|
+
*/
|
|
75
|
+
environment: any;
|
|
76
|
+
/**
|
|
77
|
+
* - CAWS configuration
|
|
78
|
+
*/
|
|
79
|
+
config: any;
|
|
80
|
+
/**
|
|
81
|
+
* - Current working specification
|
|
82
|
+
*/
|
|
83
|
+
workingSpec: any;
|
|
84
|
+
/**
|
|
85
|
+
* - Execution timeout in milliseconds
|
|
86
|
+
*/
|
|
87
|
+
timeout: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* @fileoverview CAWS Tool Interface - Base classes and contracts for tool implementation
|
|
91
|
+
* Defines the standard interface that all CAWS tools must implement
|
|
92
|
+
* @author @darianrosebrook
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Standard tool execution result
|
|
96
|
+
* @typedef {Object} ToolExecutionResult
|
|
97
|
+
* @property {boolean} success - Whether execution succeeded
|
|
98
|
+
* @property {number} duration - Execution duration in milliseconds
|
|
99
|
+
* @property {Object} output - Tool-specific output data
|
|
100
|
+
* @property {Array<string>} errors - Error messages if execution failed
|
|
101
|
+
* @property {Object} metadata - Additional execution metadata
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Tool metadata structure
|
|
105
|
+
* @typedef {Object} ToolMetadata
|
|
106
|
+
* @property {string} id - Unique tool identifier
|
|
107
|
+
* @property {string} name - Human-readable tool name
|
|
108
|
+
* @property {string} version - Tool version (semver)
|
|
109
|
+
* @property {string} description - Tool description
|
|
110
|
+
* @property {Array<string>} capabilities - Tool capabilities (e.g., ['validation', 'security'])
|
|
111
|
+
* @property {string} author - Tool author
|
|
112
|
+
* @property {string} license - Tool license
|
|
113
|
+
* @property {Array<string>} dependencies - Required Node.js dependencies
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Tool execution context
|
|
117
|
+
* @typedef {Object} ToolExecutionContext
|
|
118
|
+
* @property {string} workingDirectory - Current working directory
|
|
119
|
+
* @property {Object} environment - Environment variables
|
|
120
|
+
* @property {Object} config - CAWS configuration
|
|
121
|
+
* @property {Object} workingSpec - Current working specification
|
|
122
|
+
* @property {number} timeout - Execution timeout in milliseconds
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* Base Tool class - All CAWS tools should extend this class
|
|
126
|
+
*/
|
|
127
|
+
export class BaseTool {
|
|
128
|
+
metadata: ToolMetadata;
|
|
129
|
+
/**
|
|
130
|
+
* Execute the tool with given parameters
|
|
131
|
+
* @param {Object} parameters - Tool-specific execution parameters
|
|
132
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
133
|
+
* @returns {Promise<ToolExecutionResult>} Execution result
|
|
134
|
+
*/
|
|
135
|
+
execute(parameters?: any, context?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Get tool metadata
|
|
138
|
+
* @returns {ToolMetadata} Tool metadata
|
|
139
|
+
*/
|
|
140
|
+
getMetadata(): ToolMetadata;
|
|
141
|
+
/**
|
|
142
|
+
* Validate tool parameters
|
|
143
|
+
* @param {Object} _parameters - Parameters to validate
|
|
144
|
+
* @throws {Error} If parameters are invalid
|
|
145
|
+
*/
|
|
146
|
+
validateParameters(_parameters: any): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Execute tool implementation (must be overridden by subclasses)
|
|
149
|
+
* @param {Object} _parameters - Tool parameters
|
|
150
|
+
* @param {ToolExecutionContext} _context - Execution context
|
|
151
|
+
* @returns {Promise<Object>} Tool-specific result
|
|
152
|
+
*/
|
|
153
|
+
executeImpl(_parameters: any, _context: ToolExecutionContext): Promise<any>;
|
|
154
|
+
/**
|
|
155
|
+
* Normalize execution result to standard format
|
|
156
|
+
* @private
|
|
157
|
+
* @param {Object} result - Raw tool result
|
|
158
|
+
* @param {number} duration - Execution duration
|
|
159
|
+
* @returns {ToolExecutionResult} Normalized result
|
|
160
|
+
*/
|
|
161
|
+
private normalizeResult;
|
|
162
|
+
/**
|
|
163
|
+
* Create error result
|
|
164
|
+
* @private
|
|
165
|
+
* @param {Error} error - Execution error
|
|
166
|
+
* @param {number} duration - Execution duration
|
|
167
|
+
* @returns {ToolExecutionResult} Error result
|
|
168
|
+
*/
|
|
169
|
+
private createErrorResult;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Validation Tool base class - For tools that perform validation checks
|
|
173
|
+
*/
|
|
174
|
+
export class ValidationTool extends BaseTool {
|
|
175
|
+
capabilities: string[];
|
|
176
|
+
/**
|
|
177
|
+
* Execute validation
|
|
178
|
+
* @param {Object} parameters - Validation parameters
|
|
179
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
180
|
+
* @returns {Promise<ToolExecutionResult>} Validation result
|
|
181
|
+
*/
|
|
182
|
+
executeImpl(parameters: any, context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
183
|
+
/**
|
|
184
|
+
* Perform validation (must be implemented by subclasses)
|
|
185
|
+
* @param {Object} parameters - Validation parameters
|
|
186
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
187
|
+
* @returns {Promise<Object>} Validation result
|
|
188
|
+
*/
|
|
189
|
+
validate(_parameters: any, _context: any): Promise<any>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Quality Gate Tool base class - For tools that enforce quality standards
|
|
193
|
+
*/
|
|
194
|
+
export class QualityGateTool extends ValidationTool {
|
|
195
|
+
/**
|
|
196
|
+
* Get quality gate thresholds for current tier
|
|
197
|
+
* @param {number} tier - Risk tier (1-3)
|
|
198
|
+
* @returns {Object} Threshold configuration
|
|
199
|
+
*/
|
|
200
|
+
getTierThresholds(tier: number): any;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Security Tool base class - For tools that perform security checks
|
|
204
|
+
*/
|
|
205
|
+
export class SecurityTool extends ValidationTool {
|
|
206
|
+
/**
|
|
207
|
+
* Check for security violations
|
|
208
|
+
* @param {Object} target - Target to check (file, code, etc.)
|
|
209
|
+
* @returns {Promise<Array<Object>>} Array of security violations
|
|
210
|
+
*/
|
|
211
|
+
checkSecurityViolations(target: any): Promise<Array<any>>;
|
|
212
|
+
}
|
|
213
|
+
export namespace ToolUtils {
|
|
214
|
+
/**
|
|
215
|
+
* Create standardized success result
|
|
216
|
+
* @param {Object} output - Tool output
|
|
217
|
+
* @param {Object} metadata - Additional metadata
|
|
218
|
+
* @returns {ToolExecutionResult} Success result
|
|
219
|
+
*/
|
|
220
|
+
function createSuccessResult(output?: any, metadata?: any): ToolExecutionResult;
|
|
221
|
+
/**
|
|
222
|
+
* Create standardized error result
|
|
223
|
+
* @param {string} message - Error message
|
|
224
|
+
* @param {string} errorType - Error type
|
|
225
|
+
* @returns {ToolExecutionResult} Error result
|
|
226
|
+
*/
|
|
227
|
+
function createErrorResult(message: string, errorType?: string): ToolExecutionResult;
|
|
228
|
+
/**
|
|
229
|
+
* Validate required parameters
|
|
230
|
+
* @param {Object} _params - Parameters object
|
|
231
|
+
* @param {Array<string>} _required - Required parameter names
|
|
232
|
+
* @throws {Error} If required parameters are missing
|
|
233
|
+
*/
|
|
234
|
+
function validateRequired(_params: any, _required: Array<string>): void;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=tool-interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-interface.d.ts","sourceRoot":"","sources":["../src/tool-interface.js"],"names":[],"mappings":";;;;;;;;aAWc,OAAO;;;;cACP,MAAM;;;;;;;;YAEN,KAAK,CAAC,MAAM,CAAC;;;;;;;;;;;;;QAOb,MAAM;;;;UACN,MAAM;;;;aACN,MAAM;;;;iBACN,MAAM;;;;kBACN,KAAK,CAAC,MAAM,CAAC;;;;YACb,MAAM;;;;aACN,MAAM;;;;kBACN,KAAK,CAAC,MAAM,CAAC;;;;;;;;;sBAMb,MAAM;;;;;;;;;;;;;;;;aAIN,MAAM;;AApCpB;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;GAQG;AAEH;;GAEG;AACH;IAEI,uBAAkC;IAGpC;;;;;OAKG;IACH,oCAHW,oBAAoB,GAClB,OAAO,CAAC,mBAAmB,CAAC,CAmBxC;IAED;;;OAGG;IACH,eAFa,YAAY,CAIxB;IAED;;;;OAIG;IACH,8CAGC;IAED;;;;;OAKG;IACH,wCAHW,oBAAoB,GAClB,OAAO,KAAQ,CAI3B;IAED;;;;;;OAMG;IACH,wBAQC;IAED;;;;;;OAMG;IACH,0BAWC;CACF;AAED;;GAEG;AACH;IAGI,uBAAkC;IAGpC;;;;;OAKG;IACH,sCAHW,oBAAoB,GAClB,OAAO,CAAC,mBAAmB,CAAC,CAcxC;IAED;;;;;OAKG;IACH,2CAFa,OAAO,KAAQ,CAI3B;CACF;AAED;;GAEG;AACH;IAME;;;;OAIG;IACH,wBAHW,MAAM,OA6BhB;CACF;AAED;;GAEG;AACH;IAME;;;;OAIG;IACH,sCAFa,OAAO,CAAC,KAAK,KAAQ,CAAC,CAmBlC;CACF;;IAMC;;;;;OAKG;IACH,4DAFa,mBAAmB,CAU/B;IAED;;;;;OAKG;IACH,oCAJW,MAAM,cACN,MAAM,GACJ,mBAAmB,CAU/B;IAED;;;;;OAKG;IACH,mDAHW,KAAK,CAAC,MAAM,CAAC,QAQvB"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview CAWS Tool Interface - Base classes and contracts for tool implementation
|
|
5
|
+
* Defines the standard interface that all CAWS tools must implement
|
|
6
|
+
* @author @darianrosebrook
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Standard tool execution result
|
|
11
|
+
* @typedef {Object} ToolExecutionResult
|
|
12
|
+
* @property {boolean} success - Whether execution succeeded
|
|
13
|
+
* @property {number} duration - Execution duration in milliseconds
|
|
14
|
+
* @property {Object} output - Tool-specific output data
|
|
15
|
+
* @property {Array<string>} errors - Error messages if execution failed
|
|
16
|
+
* @property {Object} metadata - Additional execution metadata
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Tool metadata structure
|
|
21
|
+
* @typedef {Object} ToolMetadata
|
|
22
|
+
* @property {string} id - Unique tool identifier
|
|
23
|
+
* @property {string} name - Human-readable tool name
|
|
24
|
+
* @property {string} version - Tool version (semver)
|
|
25
|
+
* @property {string} description - Tool description
|
|
26
|
+
* @property {Array<string>} capabilities - Tool capabilities (e.g., ['validation', 'security'])
|
|
27
|
+
* @property {string} author - Tool author
|
|
28
|
+
* @property {string} license - Tool license
|
|
29
|
+
* @property {Array<string>} dependencies - Required Node.js dependencies
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Tool execution context
|
|
34
|
+
* @typedef {Object} ToolExecutionContext
|
|
35
|
+
* @property {string} workingDirectory - Current working directory
|
|
36
|
+
* @property {Object} environment - Environment variables
|
|
37
|
+
* @property {Object} config - CAWS configuration
|
|
38
|
+
* @property {Object} workingSpec - Current working specification
|
|
39
|
+
* @property {number} timeout - Execution timeout in milliseconds
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Base Tool class - All CAWS tools should extend this class
|
|
44
|
+
*/
|
|
45
|
+
class BaseTool {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.metadata = this.getMetadata();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Execute the tool with given parameters
|
|
52
|
+
* @param {Object} parameters - Tool-specific execution parameters
|
|
53
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
54
|
+
* @returns {Promise<ToolExecutionResult>} Execution result
|
|
55
|
+
*/
|
|
56
|
+
async execute(parameters = {}, context = {}) {
|
|
57
|
+
const startTime = Date.now();
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Validate parameters
|
|
61
|
+
this.validateParameters(parameters);
|
|
62
|
+
|
|
63
|
+
// Execute tool logic
|
|
64
|
+
const result = await this.executeImpl(parameters, context);
|
|
65
|
+
|
|
66
|
+
// Ensure result conforms to interface
|
|
67
|
+
const executionResult = this.normalizeResult(result, Date.now() - startTime);
|
|
68
|
+
|
|
69
|
+
return executionResult;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return this.createErrorResult(error, Date.now() - startTime);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get tool metadata
|
|
77
|
+
* @returns {ToolMetadata} Tool metadata
|
|
78
|
+
*/
|
|
79
|
+
getMetadata() {
|
|
80
|
+
throw new Error('Tool must implement getMetadata() method');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validate tool parameters
|
|
85
|
+
* @param {Object} _parameters - Parameters to validate
|
|
86
|
+
* @throws {Error} If parameters are invalid
|
|
87
|
+
*/
|
|
88
|
+
validateParameters(_parameters) {
|
|
89
|
+
// Default implementation - override in subclasses
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Execute tool implementation (must be overridden by subclasses)
|
|
95
|
+
* @param {Object} _parameters - Tool parameters
|
|
96
|
+
* @param {ToolExecutionContext} _context - Execution context
|
|
97
|
+
* @returns {Promise<Object>} Tool-specific result
|
|
98
|
+
*/
|
|
99
|
+
async executeImpl(_parameters, _context) {
|
|
100
|
+
throw new Error('Tool must implement executeImpl() method');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Normalize execution result to standard format
|
|
105
|
+
* @private
|
|
106
|
+
* @param {Object} result - Raw tool result
|
|
107
|
+
* @param {number} duration - Execution duration
|
|
108
|
+
* @returns {ToolExecutionResult} Normalized result
|
|
109
|
+
*/
|
|
110
|
+
normalizeResult(result, duration) {
|
|
111
|
+
return {
|
|
112
|
+
success: result.success !== false,
|
|
113
|
+
duration,
|
|
114
|
+
output: result.output || result,
|
|
115
|
+
errors: Array.isArray(result.errors) ? result.errors : [],
|
|
116
|
+
metadata: result.metadata || {},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create error result
|
|
122
|
+
* @private
|
|
123
|
+
* @param {Error} error - Execution error
|
|
124
|
+
* @param {number} duration - Execution duration
|
|
125
|
+
* @returns {ToolExecutionResult} Error result
|
|
126
|
+
*/
|
|
127
|
+
createErrorResult(error, duration) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
duration,
|
|
131
|
+
output: null,
|
|
132
|
+
errors: [error.message],
|
|
133
|
+
metadata: {
|
|
134
|
+
errorType: error.constructor.name,
|
|
135
|
+
stack: error.stack,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Validation Tool base class - For tools that perform validation checks
|
|
143
|
+
*/
|
|
144
|
+
class ValidationTool extends BaseTool {
|
|
145
|
+
constructor() {
|
|
146
|
+
super();
|
|
147
|
+
this.capabilities = ['validation'];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Execute validation
|
|
152
|
+
* @param {Object} parameters - Validation parameters
|
|
153
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
154
|
+
* @returns {Promise<ToolExecutionResult>} Validation result
|
|
155
|
+
*/
|
|
156
|
+
async executeImpl(parameters, context) {
|
|
157
|
+
const validationResult = await this.validate(parameters, context);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
success: validationResult.valid,
|
|
161
|
+
output: validationResult,
|
|
162
|
+
errors: validationResult.errors || [],
|
|
163
|
+
metadata: {
|
|
164
|
+
checksRun: validationResult.checks?.length || 0,
|
|
165
|
+
score: validationResult.score || 0,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Perform validation (must be implemented by subclasses)
|
|
172
|
+
* @param {Object} parameters - Validation parameters
|
|
173
|
+
* @param {ToolExecutionContext} context - Execution context
|
|
174
|
+
* @returns {Promise<Object>} Validation result
|
|
175
|
+
*/
|
|
176
|
+
async validate(_parameters, _context) {
|
|
177
|
+
throw new Error('ValidationTool must implement validate() method');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Quality Gate Tool base class - For tools that enforce quality standards
|
|
183
|
+
*/
|
|
184
|
+
class QualityGateTool extends ValidationTool {
|
|
185
|
+
constructor() {
|
|
186
|
+
super();
|
|
187
|
+
this.capabilities = ['validation', 'quality-gates'];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Get quality gate thresholds for current tier
|
|
192
|
+
* @param {number} tier - Risk tier (1-3)
|
|
193
|
+
* @returns {Object} Threshold configuration
|
|
194
|
+
*/
|
|
195
|
+
getTierThresholds(tier) {
|
|
196
|
+
const thresholds = {
|
|
197
|
+
1: {
|
|
198
|
+
// Tier 1 - Highest rigor
|
|
199
|
+
coverage: 0.9,
|
|
200
|
+
mutation: 0.7,
|
|
201
|
+
contracts: true,
|
|
202
|
+
manualReview: true,
|
|
203
|
+
},
|
|
204
|
+
2: {
|
|
205
|
+
// Tier 2 - Standard rigor
|
|
206
|
+
coverage: 0.8,
|
|
207
|
+
mutation: 0.5,
|
|
208
|
+
contracts: true,
|
|
209
|
+
manualReview: false,
|
|
210
|
+
},
|
|
211
|
+
3: {
|
|
212
|
+
// Tier 3 - Low rigor
|
|
213
|
+
coverage: 0.7,
|
|
214
|
+
mutation: 0.3,
|
|
215
|
+
contracts: false,
|
|
216
|
+
manualReview: false,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return thresholds[tier] || thresholds[2];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Security Tool base class - For tools that perform security checks
|
|
226
|
+
*/
|
|
227
|
+
class SecurityTool extends ValidationTool {
|
|
228
|
+
constructor() {
|
|
229
|
+
super();
|
|
230
|
+
this.capabilities = ['validation', 'security'];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Check for security violations
|
|
235
|
+
* @param {Object} target - Target to check (file, code, etc.)
|
|
236
|
+
* @returns {Promise<Array<Object>>} Array of security violations
|
|
237
|
+
*/
|
|
238
|
+
async checkSecurityViolations(target) {
|
|
239
|
+
const violations = [];
|
|
240
|
+
|
|
241
|
+
// Check for common security patterns
|
|
242
|
+
const patterns = [
|
|
243
|
+
{ name: 'hardcoded_secrets', pattern: /password|token|key|secret/i, severity: 'high' },
|
|
244
|
+
{ name: 'unsafe_eval', pattern: /eval\(|Function\(/, severity: 'high' },
|
|
245
|
+
{ name: 'dangerous_modules', pattern: /child_process|fs-extra/, severity: 'medium' },
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
for (const { name, pattern, severity } of patterns) {
|
|
249
|
+
if (pattern.test(target)) {
|
|
250
|
+
violations.push({ name, severity, message: `${name} pattern detected` });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return violations;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Utility functions for tool development
|
|
260
|
+
*/
|
|
261
|
+
const ToolUtils = {
|
|
262
|
+
/**
|
|
263
|
+
* Create standardized success result
|
|
264
|
+
* @param {Object} output - Tool output
|
|
265
|
+
* @param {Object} metadata - Additional metadata
|
|
266
|
+
* @returns {ToolExecutionResult} Success result
|
|
267
|
+
*/
|
|
268
|
+
createSuccessResult(output = {}, metadata = {}) {
|
|
269
|
+
return {
|
|
270
|
+
success: true,
|
|
271
|
+
duration: 0, // Will be set by BaseTool
|
|
272
|
+
output,
|
|
273
|
+
errors: [],
|
|
274
|
+
metadata,
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Create standardized error result
|
|
280
|
+
* @param {string} message - Error message
|
|
281
|
+
* @param {string} errorType - Error type
|
|
282
|
+
* @returns {ToolExecutionResult} Error result
|
|
283
|
+
*/
|
|
284
|
+
createErrorResult(message, errorType = 'ToolError') {
|
|
285
|
+
return {
|
|
286
|
+
success: false,
|
|
287
|
+
duration: 0, // Will be set by BaseTool
|
|
288
|
+
output: null,
|
|
289
|
+
errors: [message],
|
|
290
|
+
metadata: { errorType },
|
|
291
|
+
};
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Validate required parameters
|
|
296
|
+
* @param {Object} _params - Parameters object
|
|
297
|
+
* @param {Array<string>} _required - Required parameter names
|
|
298
|
+
* @throws {Error} If required parameters are missing
|
|
299
|
+
*/
|
|
300
|
+
validateRequired(_params, _required) {
|
|
301
|
+
const missing = _required.filter((key) => !_params[key]);
|
|
302
|
+
if (missing.length > 0) {
|
|
303
|
+
throw new Error(`Missing required parameters: ${missing.join(', ')}`);
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
module.exports = {
|
|
309
|
+
BaseTool,
|
|
310
|
+
ValidationTool,
|
|
311
|
+
QualityGateTool,
|
|
312
|
+
SecurityTool,
|
|
313
|
+
ToolUtils,
|
|
314
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export = ToolLoader;
|
|
3
|
+
/**
|
|
4
|
+
* Tool Loader - Discovers, validates, and loads CAWS tools dynamically
|
|
5
|
+
* @extends EventEmitter
|
|
6
|
+
*/
|
|
7
|
+
declare class ToolLoader extends EventEmitter<[never]> {
|
|
8
|
+
constructor(options?: {});
|
|
9
|
+
options: {
|
|
10
|
+
toolsDir: any;
|
|
11
|
+
cacheEnabled: boolean;
|
|
12
|
+
timeout: any;
|
|
13
|
+
maxTools: any;
|
|
14
|
+
};
|
|
15
|
+
loadedTools: Map<any, any>;
|
|
16
|
+
discoveredTools: Set<any>;
|
|
17
|
+
loadingState: string;
|
|
18
|
+
/**
|
|
19
|
+
* Discover available tools in the tools directory
|
|
20
|
+
* @returns {Promise<Array<string>>} Array of tool file paths
|
|
21
|
+
*/
|
|
22
|
+
discoverTools(): Promise<Array<string>>;
|
|
23
|
+
/**
|
|
24
|
+
* Load a specific tool module
|
|
25
|
+
* @param {string} toolPath - Path to tool file
|
|
26
|
+
* @returns {Promise<Object>} Loaded tool module
|
|
27
|
+
*/
|
|
28
|
+
loadTool(toolPath: string): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Load all discovered tools
|
|
31
|
+
* @returns {Promise<Map<string, Object>>} Map of loaded tools
|
|
32
|
+
*/
|
|
33
|
+
loadAllTools(): Promise<Map<string, any>>;
|
|
34
|
+
/**
|
|
35
|
+
* Get a loaded tool by ID
|
|
36
|
+
* @param {string} toolId - Tool identifier
|
|
37
|
+
* @returns {Object|null} Tool object or null if not found
|
|
38
|
+
*/
|
|
39
|
+
getTool(toolId: string): any | null;
|
|
40
|
+
/**
|
|
41
|
+
* Get all loaded tools
|
|
42
|
+
* @returns {Map<string, Object>} Map of loaded tools
|
|
43
|
+
*/
|
|
44
|
+
getAllTools(): Map<string, any>;
|
|
45
|
+
/**
|
|
46
|
+
* Unload a tool (remove from cache)
|
|
47
|
+
* @param {string} toolId - Tool identifier
|
|
48
|
+
* @returns {boolean} True if tool was unloaded
|
|
49
|
+
*/
|
|
50
|
+
unloadTool(toolId: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Validate tool file before loading
|
|
53
|
+
* @private
|
|
54
|
+
* @param {string} toolPath - Path to tool file
|
|
55
|
+
*/
|
|
56
|
+
private validateToolFile;
|
|
57
|
+
/**
|
|
58
|
+
* Load module with timeout protection
|
|
59
|
+
* @private
|
|
60
|
+
* @param {string} toolPath - Path to tool file
|
|
61
|
+
*/
|
|
62
|
+
private loadModuleWithTimeout;
|
|
63
|
+
/**
|
|
64
|
+
* Validate tool interface compliance
|
|
65
|
+
* @private
|
|
66
|
+
* @param {Object} toolModule - Loaded tool module
|
|
67
|
+
* @param {string} toolId - Tool identifier
|
|
68
|
+
*/
|
|
69
|
+
private validateToolInterface;
|
|
70
|
+
/**
|
|
71
|
+
* Get loader statistics
|
|
72
|
+
* @returns {Object} Statistics object
|
|
73
|
+
*/
|
|
74
|
+
getStats(): any;
|
|
75
|
+
}
|
|
76
|
+
import { EventEmitter } from "events";
|
|
77
|
+
//# sourceMappingURL=tool-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-loader.d.ts","sourceRoot":"","sources":["../src/tool-loader.js"],"names":[],"mappings":";;AAcA;;;GAGG;AACH;IACE,0BAaC;IAXC;;;;;MAMC;IAED,2BAA4B;IAC5B,0BAAgC;IAChC,qBAA0B;IAG5B;;;OAGG;IACH,iBAFa,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAkDlC;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,OAAO,KAAQ,CAmC3B;IAED;;;OAGG;IACH,gBAFa,OAAO,CAAC,GAAG,CAAC,MAAM,MAAS,CAAC,CAuBxC;IAED;;;;OAIG;IACH,gBAHW,MAAM,GACJ,MAAO,IAAI,CAIvB;IAED;;;OAGG;IACH,eAFa,GAAG,CAAC,MAAM,MAAS,CAI/B;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,OAAO,CAQnB;IAED;;;;OAIG;IACH,yBAgCC;IAED;;;;OAIG;IACH,8BAkBC;IAED;;;;;OAKG;IACH,8BAyBC;IAED;;;OAGG;IACH,gBAQC;CACF"}
|