guardrail-core 1.0.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/dist/__tests__/autopilot.test.d.ts +7 -0
- package/dist/__tests__/autopilot.test.d.ts.map +1 -0
- package/dist/__tests__/autopilot.test.js +156 -0
- package/dist/__tests__/tier-config.test.d.ts +9 -0
- package/dist/__tests__/tier-config.test.d.ts.map +1 -0
- package/dist/__tests__/tier-config.test.js +230 -0
- package/dist/__tests__/utils/hash-inline.test.d.ts +2 -0
- package/dist/__tests__/utils/hash-inline.test.d.ts.map +1 -0
- package/dist/__tests__/utils/hash-inline.test.js +62 -0
- package/dist/__tests__/utils/hash.test.d.ts +3 -0
- package/dist/__tests__/utils/hash.test.d.ts.map +1 -0
- package/dist/__tests__/utils/hash.test.js +95 -0
- package/dist/__tests__/utils/simple.test.d.ts +1 -0
- package/dist/__tests__/utils/simple.test.d.ts.map +1 -0
- package/dist/__tests__/utils/simple.test.js +10 -0
- package/dist/__tests__/utils/utils-simple.test.d.ts +1 -0
- package/dist/__tests__/utils/utils-simple.test.d.ts.map +1 -0
- package/dist/__tests__/utils/utils-simple.test.js +6 -0
- package/dist/__tests__/utils/utils.test.d.ts +15 -0
- package/dist/__tests__/utils/utils.test.d.ts.map +1 -0
- package/dist/__tests__/utils/utils.test.js +172 -0
- package/dist/autopilot/autopilot-runner.d.ts +33 -0
- package/dist/autopilot/autopilot-runner.d.ts.map +1 -0
- package/dist/autopilot/autopilot-runner.js +479 -0
- package/dist/autopilot/index.d.ts +6 -0
- package/dist/autopilot/index.d.ts.map +1 -0
- package/dist/autopilot/index.js +25 -0
- package/dist/autopilot/types.d.ts +102 -0
- package/dist/autopilot/types.d.ts.map +1 -0
- package/dist/autopilot/types.js +18 -0
- package/dist/cache/index.d.ts +7 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +22 -0
- package/dist/cache/redis-cache.d.ts +145 -0
- package/dist/cache/redis-cache.d.ts.map +1 -0
- package/dist/cache/redis-cache.js +459 -0
- package/dist/ci/github-actions.d.ts +77 -0
- package/dist/ci/github-actions.d.ts.map +1 -0
- package/dist/ci/github-actions.js +277 -0
- package/dist/ci/index.d.ts +12 -0
- package/dist/ci/index.d.ts.map +1 -0
- package/dist/ci/index.js +27 -0
- package/dist/ci/pre-commit.d.ts +65 -0
- package/dist/ci/pre-commit.d.ts.map +1 -0
- package/dist/ci/pre-commit.js +286 -0
- package/dist/entitlements.d.ts +149 -0
- package/dist/entitlements.d.ts.map +1 -0
- package/dist/entitlements.js +464 -0
- package/dist/env.d.ts +113 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +204 -0
- package/dist/fix-packs/__tests__/generate-fix-packs.test.d.ts +7 -0
- package/dist/fix-packs/__tests__/generate-fix-packs.test.d.ts.map +1 -0
- package/dist/fix-packs/__tests__/generate-fix-packs.test.js +250 -0
- package/dist/fix-packs/generate-fix-packs.d.ts +15 -0
- package/dist/fix-packs/generate-fix-packs.d.ts.map +1 -0
- package/dist/fix-packs/generate-fix-packs.js +505 -0
- package/dist/fix-packs/index.d.ts +8 -0
- package/dist/fix-packs/index.d.ts.map +1 -0
- package/dist/fix-packs/index.js +23 -0
- package/dist/fix-packs/types.d.ts +113 -0
- package/dist/fix-packs/types.d.ts.map +1 -0
- package/dist/fix-packs/types.js +71 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/metrics/prometheus.d.ts +99 -0
- package/dist/metrics/prometheus.d.ts.map +1 -0
- package/dist/metrics/prometheus.js +306 -0
- package/dist/quota-ledger.d.ts +119 -0
- package/dist/quota-ledger.d.ts.map +1 -0
- package/dist/quota-ledger.js +462 -0
- package/dist/rbac/__tests__/permissions.test.d.ts +8 -0
- package/dist/rbac/__tests__/permissions.test.d.ts.map +1 -0
- package/dist/rbac/__tests__/permissions.test.js +350 -0
- package/dist/rbac/index.d.ts +9 -0
- package/dist/rbac/index.d.ts.map +1 -0
- package/dist/rbac/index.js +32 -0
- package/dist/rbac/permissions.d.ts +71 -0
- package/dist/rbac/permissions.d.ts.map +1 -0
- package/dist/rbac/permissions.js +247 -0
- package/dist/rbac/types.d.ts +69 -0
- package/dist/rbac/types.d.ts.map +1 -0
- package/dist/rbac/types.js +213 -0
- package/dist/tier-config.d.ts +203 -0
- package/dist/tier-config.d.ts.map +1 -0
- package/dist/tier-config.js +675 -0
- package/dist/types.d.ts +365 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/utils.d.ts +36 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +127 -0
- package/dist/verified-autofix/__tests__/format-validator.test.d.ts +11 -0
- package/dist/verified-autofix/__tests__/format-validator.test.d.ts.map +1 -0
- package/dist/verified-autofix/__tests__/format-validator.test.js +285 -0
- package/dist/verified-autofix/__tests__/pipeline.test.d.ts +11 -0
- package/dist/verified-autofix/__tests__/pipeline.test.d.ts.map +1 -0
- package/dist/verified-autofix/__tests__/pipeline.test.js +389 -0
- package/dist/verified-autofix/__tests__/repo-fingerprint.test.d.ts +11 -0
- package/dist/verified-autofix/__tests__/repo-fingerprint.test.d.ts.map +1 -0
- package/dist/verified-autofix/__tests__/repo-fingerprint.test.js +236 -0
- package/dist/verified-autofix/__tests__/workspace.test.d.ts +11 -0
- package/dist/verified-autofix/__tests__/workspace.test.d.ts.map +1 -0
- package/dist/verified-autofix/__tests__/workspace.test.js +314 -0
- package/dist/verified-autofix/format-validator.d.ts +101 -0
- package/dist/verified-autofix/format-validator.d.ts.map +1 -0
- package/dist/verified-autofix/format-validator.js +446 -0
- package/dist/verified-autofix/index.d.ts +14 -0
- package/dist/verified-autofix/index.d.ts.map +1 -0
- package/dist/verified-autofix/index.js +39 -0
- package/dist/verified-autofix/pipeline.d.ts +68 -0
- package/dist/verified-autofix/pipeline.d.ts.map +1 -0
- package/dist/verified-autofix/pipeline.js +330 -0
- package/dist/verified-autofix/repo-fingerprint.d.ts +56 -0
- package/dist/verified-autofix/repo-fingerprint.d.ts.map +1 -0
- package/dist/verified-autofix/repo-fingerprint.js +396 -0
- package/dist/verified-autofix/workspace.d.ts +83 -0
- package/dist/verified-autofix/workspace.d.ts.map +1 -0
- package/dist/verified-autofix/workspace.js +454 -0
- package/dist/verified-autofix.d.ts +182 -0
- package/dist/verified-autofix.d.ts.map +1 -0
- package/dist/verified-autofix.js +1021 -0
- package/dist/visualization/dependency-graph.d.ts +79 -0
- package/dist/visualization/dependency-graph.d.ts.map +1 -0
- package/dist/visualization/dependency-graph.js +399 -0
- package/dist/visualization/index.d.ts +5 -0
- package/dist/visualization/index.d.ts.map +1 -0
- package/dist/visualization/index.js +20 -0
- package/package.json +29 -0
- package/src/__tests__/autopilot.test.ts +196 -0
- package/src/__tests__/tier-config.test.ts +289 -0
- package/src/__tests__/utils/hash-inline.test.ts +76 -0
- package/src/__tests__/utils/hash.test.ts +119 -0
- package/src/__tests__/utils/simple.test.ts +10 -0
- package/src/__tests__/utils/utils-simple.test.ts +5 -0
- package/src/__tests__/utils/utils.test.ts +203 -0
- package/src/autopilot/autopilot-runner.ts +503 -0
- package/src/autopilot/index.ts +6 -0
- package/src/autopilot/types.ts +119 -0
- package/src/cache/index.ts +7 -0
- package/src/cache/redis-cache.d.ts +155 -0
- package/src/cache/redis-cache.d.ts.map +1 -0
- package/src/cache/redis-cache.ts +517 -0
- package/src/ci/github-actions.ts +335 -0
- package/src/ci/index.ts +12 -0
- package/src/ci/pre-commit.ts +338 -0
- package/src/db/usage-schema.prisma +114 -0
- package/src/entitlements.ts +570 -0
- package/src/env.d.ts +68 -0
- package/src/env.d.ts.map +1 -0
- package/src/env.ts +247 -0
- package/src/fix-packs/__tests__/generate-fix-packs.test.ts +317 -0
- package/src/fix-packs/generate-fix-packs.ts +577 -0
- package/src/fix-packs/index.ts +8 -0
- package/src/fix-packs/types.ts +206 -0
- package/src/index.d.ts +7 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +12 -0
- package/src/metrics/prometheus.d.ts +104 -0
- package/src/metrics/prometheus.d.ts.map +1 -0
- package/src/metrics/prometheus.ts +446 -0
- package/src/quota-ledger.ts +548 -0
- package/src/rbac/__tests__/permissions.test.ts +446 -0
- package/src/rbac/index.ts +46 -0
- package/src/rbac/permissions.ts +301 -0
- package/src/rbac/types.ts +298 -0
- package/src/tier-config.json +157 -0
- package/src/tier-config.ts +815 -0
- package/src/types.d.ts +365 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.ts +441 -0
- package/src/utils.d.ts +36 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.ts +140 -0
- package/src/verified-autofix/__tests__/format-validator.test.ts +335 -0
- package/src/verified-autofix/__tests__/pipeline.test.ts +419 -0
- package/src/verified-autofix/__tests__/repo-fingerprint.test.ts +241 -0
- package/src/verified-autofix/__tests__/workspace.test.ts +373 -0
- package/src/verified-autofix/format-validator.ts +517 -0
- package/src/verified-autofix/index.ts +63 -0
- package/src/verified-autofix/pipeline.ts +403 -0
- package/src/verified-autofix/repo-fingerprint.ts +459 -0
- package/src/verified-autofix/workspace.ts +531 -0
- package/src/verified-autofix.ts +1187 -0
- package/src/visualization/dependency-graph.d.ts +85 -0
- package/src/visualization/dependency-graph.d.ts.map +1 -0
- package/src/visualization/dependency-graph.ts +495 -0
- package/src/visualization/index.ts +5 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
// ==========================================
|
|
2
|
+
// PERMISSION TYPES
|
|
3
|
+
// ==========================================
|
|
4
|
+
|
|
5
|
+
export interface FilesystemPermissions {
|
|
6
|
+
allowedPaths: string[];
|
|
7
|
+
deniedPaths: string[];
|
|
8
|
+
operations: ('read' | 'write' | 'delete' | 'execute')[];
|
|
9
|
+
maxFileSize: number; // in bytes
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NetworkPermissions {
|
|
14
|
+
allowedDomains: string[];
|
|
15
|
+
deniedDomains: string[];
|
|
16
|
+
maxRequests: number; // per minute
|
|
17
|
+
allowedProtocols: ('http' | 'https' | 'ws' | 'wss')[];
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ShellPermissions {
|
|
22
|
+
allowedCommands: string[];
|
|
23
|
+
deniedCommands: string[];
|
|
24
|
+
requireConfirmation: string[]; // commands that need user approval
|
|
25
|
+
allowEnvironmentVariables: boolean;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ResourceLimits {
|
|
30
|
+
maxMemoryMB: number;
|
|
31
|
+
maxCpuPercent: number;
|
|
32
|
+
maxTokens: number;
|
|
33
|
+
maxExecutionTimeMs: number;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AgentPermissionScope {
|
|
38
|
+
filesystem: FilesystemPermissions;
|
|
39
|
+
network: NetworkPermissions;
|
|
40
|
+
shell: ShellPermissions;
|
|
41
|
+
resources: ResourceLimits;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ==========================================
|
|
45
|
+
// ACTION TYPES
|
|
46
|
+
// ==========================================
|
|
47
|
+
|
|
48
|
+
export interface FilesystemDetails {
|
|
49
|
+
operation: 'read' | 'write' | 'delete' | 'execute';
|
|
50
|
+
path: string;
|
|
51
|
+
content?: string;
|
|
52
|
+
size?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface NetworkDetails {
|
|
56
|
+
method: string;
|
|
57
|
+
url: string;
|
|
58
|
+
headers?: Record<string, string>;
|
|
59
|
+
body?: unknown;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ShellDetails {
|
|
63
|
+
command: string;
|
|
64
|
+
args: string[];
|
|
65
|
+
cwd?: string;
|
|
66
|
+
env?: Record<string, string>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type ActionDetails = FilesystemDetails | NetworkDetails | ShellDetails;
|
|
70
|
+
|
|
71
|
+
export interface ActionAttempt {
|
|
72
|
+
agentId: string;
|
|
73
|
+
taskId: string;
|
|
74
|
+
actionType: string;
|
|
75
|
+
category: 'code' | 'file' | 'network' | 'shell';
|
|
76
|
+
details: ActionDetails;
|
|
77
|
+
reasoning?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ActionDecision {
|
|
81
|
+
allowed: boolean;
|
|
82
|
+
reason: string;
|
|
83
|
+
alternativeSuggestion?: string;
|
|
84
|
+
riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
85
|
+
requiresApproval: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ==========================================
|
|
89
|
+
// EVALUATION TYPES
|
|
90
|
+
// ==========================================
|
|
91
|
+
|
|
92
|
+
export interface Evaluation {
|
|
93
|
+
passed: boolean;
|
|
94
|
+
reason: string;
|
|
95
|
+
violatedRules: string[];
|
|
96
|
+
suggestions: string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface SimpleValidationResult {
|
|
100
|
+
valid: boolean;
|
|
101
|
+
errors: string[];
|
|
102
|
+
warnings: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ==========================================
|
|
106
|
+
// CHECKPOINT TYPES
|
|
107
|
+
// ==========================================
|
|
108
|
+
|
|
109
|
+
export interface FileSnapshot {
|
|
110
|
+
path: string;
|
|
111
|
+
originalContent: string;
|
|
112
|
+
originalHash: string;
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface Checkpoint {
|
|
117
|
+
id: string;
|
|
118
|
+
agentId: string;
|
|
119
|
+
taskId: string;
|
|
120
|
+
modifiedFiles: FileSnapshot[];
|
|
121
|
+
resourcesUsed: ResourceUsage;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ResourceUsage {
|
|
126
|
+
memoryMB: number;
|
|
127
|
+
cpuPercent: number;
|
|
128
|
+
tokensUsed: number;
|
|
129
|
+
executionTimeMs: number;
|
|
130
|
+
apiCalls: number;
|
|
131
|
+
[key: string]: unknown;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface LimitCheck {
|
|
135
|
+
withinLimits: boolean;
|
|
136
|
+
violations: string[];
|
|
137
|
+
current: ResourceUsage;
|
|
138
|
+
limits: ResourceLimits;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface RollbackResult {
|
|
142
|
+
success: boolean;
|
|
143
|
+
filesRestored: number;
|
|
144
|
+
errors: string[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ==========================================
|
|
148
|
+
// INJECTION DETECTION TYPES
|
|
149
|
+
// ==========================================
|
|
150
|
+
|
|
151
|
+
export interface InjectionScanRequest {
|
|
152
|
+
content: string;
|
|
153
|
+
contentType: 'user_input' | 'code' | 'data_source';
|
|
154
|
+
context?: {
|
|
155
|
+
source: string;
|
|
156
|
+
metadata?: Record<string, unknown>;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface Detection {
|
|
161
|
+
type: string;
|
|
162
|
+
pattern: string;
|
|
163
|
+
location: {
|
|
164
|
+
start: number;
|
|
165
|
+
end: number;
|
|
166
|
+
line?: number;
|
|
167
|
+
};
|
|
168
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
169
|
+
confidence: number;
|
|
170
|
+
description: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface InjectionScanResult {
|
|
174
|
+
verdict: 'CLEAN' | 'SUSPICIOUS' | 'MALICIOUS' | 'BLOCKED';
|
|
175
|
+
confidence: number;
|
|
176
|
+
detections: Detection[];
|
|
177
|
+
sanitizedContent?: string;
|
|
178
|
+
recommendation: {
|
|
179
|
+
action: 'allow' | 'sanitize' | 'block' | 'review';
|
|
180
|
+
reason: string;
|
|
181
|
+
};
|
|
182
|
+
scanDuration: number;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface ProcessedInput {
|
|
186
|
+
original: string;
|
|
187
|
+
processed: string;
|
|
188
|
+
wasSanitized: boolean;
|
|
189
|
+
detections: Detection[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ==========================================
|
|
193
|
+
// OUTPUT VALIDATION TYPES
|
|
194
|
+
// ==========================================
|
|
195
|
+
|
|
196
|
+
export interface CodeOutput {
|
|
197
|
+
code: string;
|
|
198
|
+
language: string;
|
|
199
|
+
outputType: 'code' | 'config' | 'documentation';
|
|
200
|
+
metadata?: Record<string, unknown>;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface Context {
|
|
204
|
+
projectPath?: string;
|
|
205
|
+
existingFiles?: string[];
|
|
206
|
+
dependencies?: Record<string, string>;
|
|
207
|
+
framework?: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface StageResult {
|
|
211
|
+
stageName: string;
|
|
212
|
+
passed: boolean;
|
|
213
|
+
score: number;
|
|
214
|
+
issues: ValidationIssue[];
|
|
215
|
+
warnings: string[];
|
|
216
|
+
duration: number;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface ValidationIssue {
|
|
220
|
+
type: string;
|
|
221
|
+
severity: 'error' | 'warning' | 'info';
|
|
222
|
+
message: string;
|
|
223
|
+
location?: {
|
|
224
|
+
line: number;
|
|
225
|
+
column: number;
|
|
226
|
+
};
|
|
227
|
+
suggestion?: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface ValidationRequest {
|
|
231
|
+
output: CodeOutput;
|
|
232
|
+
context?: Context;
|
|
233
|
+
request?: string; // original user request
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface DetailedValidationResult {
|
|
237
|
+
verdict: 'ACCEPT' | 'MODIFY' | 'REJECT' | 'HUMAN_REVIEW';
|
|
238
|
+
confidence: number;
|
|
239
|
+
stages: StageResult[];
|
|
240
|
+
overallScore: number;
|
|
241
|
+
modifiedOutput?: string;
|
|
242
|
+
recommendation: string;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ==========================================
|
|
246
|
+
// HALLUCINATION DETECTION TYPES
|
|
247
|
+
// ==========================================
|
|
248
|
+
|
|
249
|
+
export interface PackageCheck {
|
|
250
|
+
exists: boolean;
|
|
251
|
+
name: string;
|
|
252
|
+
version?: string;
|
|
253
|
+
registry: string;
|
|
254
|
+
alternativeSuggestions?: string[];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface APICheck {
|
|
258
|
+
exists: boolean;
|
|
259
|
+
package: string;
|
|
260
|
+
method: string;
|
|
261
|
+
signature?: string;
|
|
262
|
+
documentation?: string;
|
|
263
|
+
alternativeSuggestions?: string[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface CodeIntent {
|
|
267
|
+
primary: string;
|
|
268
|
+
secondary: string[];
|
|
269
|
+
entities: string[]; // packages, functions, variables involved
|
|
270
|
+
operations: string[]; // what the code does
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface RequestIntent {
|
|
274
|
+
goal: string;
|
|
275
|
+
constraints: string[];
|
|
276
|
+
expectedEntities: string[];
|
|
277
|
+
expectedOperations: string[];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface IntentComparison {
|
|
281
|
+
alignmentScore: number;
|
|
282
|
+
matches: string[];
|
|
283
|
+
mismatches: string[];
|
|
284
|
+
recommendation: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ==========================================
|
|
288
|
+
// AUDIT TYPES
|
|
289
|
+
// ==========================================
|
|
290
|
+
|
|
291
|
+
export interface AuditEvent {
|
|
292
|
+
agentId: string;
|
|
293
|
+
taskId: string;
|
|
294
|
+
correlationId: string;
|
|
295
|
+
sequenceNumber: number;
|
|
296
|
+
actionType: string;
|
|
297
|
+
category: string;
|
|
298
|
+
input?: unknown;
|
|
299
|
+
output?: unknown;
|
|
300
|
+
target?: {
|
|
301
|
+
type: string;
|
|
302
|
+
path?: string;
|
|
303
|
+
url?: string;
|
|
304
|
+
};
|
|
305
|
+
reasoning: {
|
|
306
|
+
summary: string;
|
|
307
|
+
considerations: string[];
|
|
308
|
+
confidence: number;
|
|
309
|
+
};
|
|
310
|
+
status: 'SUCCESS' | 'FAILURE' | 'BLOCKED' | 'PENDING_APPROVAL' | 'ROLLED_BACK';
|
|
311
|
+
error?: {
|
|
312
|
+
message: string;
|
|
313
|
+
code: string;
|
|
314
|
+
stack?: string;
|
|
315
|
+
};
|
|
316
|
+
impact?: {
|
|
317
|
+
filesModified?: string[];
|
|
318
|
+
linesAdded?: number;
|
|
319
|
+
linesDeleted?: number;
|
|
320
|
+
};
|
|
321
|
+
diff?: {
|
|
322
|
+
before: string;
|
|
323
|
+
after: string;
|
|
324
|
+
unified: string;
|
|
325
|
+
};
|
|
326
|
+
riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
327
|
+
riskFactors: string[];
|
|
328
|
+
sensitiveData: boolean;
|
|
329
|
+
piiInvolved: boolean;
|
|
330
|
+
duration?: number;
|
|
331
|
+
timestamp: Date;
|
|
332
|
+
previousHash?: string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface Diff {
|
|
336
|
+
before: string;
|
|
337
|
+
after: string;
|
|
338
|
+
unified: string;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface CodeGenParams {
|
|
342
|
+
taskId: string;
|
|
343
|
+
agentId: string;
|
|
344
|
+
prompt: string;
|
|
345
|
+
generatedCode: string;
|
|
346
|
+
language: string;
|
|
347
|
+
reasoning: string;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface CodeModParams {
|
|
351
|
+
taskId: string;
|
|
352
|
+
agentId: string;
|
|
353
|
+
filePath: string;
|
|
354
|
+
originalCode: string;
|
|
355
|
+
modifiedCode: string;
|
|
356
|
+
reasoning: string;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface ShellParams {
|
|
360
|
+
taskId: string;
|
|
361
|
+
agentId: string;
|
|
362
|
+
command: string;
|
|
363
|
+
args: string[];
|
|
364
|
+
output: string;
|
|
365
|
+
exitCode: number;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface AuditQuery {
|
|
369
|
+
agentId?: string;
|
|
370
|
+
taskId?: string;
|
|
371
|
+
correlationId?: string;
|
|
372
|
+
startDate?: Date;
|
|
373
|
+
endDate?: Date;
|
|
374
|
+
actionType?: string;
|
|
375
|
+
status?: string;
|
|
376
|
+
riskLevel?: string;
|
|
377
|
+
limit?: number;
|
|
378
|
+
offset?: number;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface QueryResult {
|
|
382
|
+
events: AuditEvent[];
|
|
383
|
+
total: number;
|
|
384
|
+
page: number;
|
|
385
|
+
pageSize: number;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export interface Timeline {
|
|
389
|
+
taskId: string;
|
|
390
|
+
events: AuditEvent[];
|
|
391
|
+
summary: {
|
|
392
|
+
totalActions: number;
|
|
393
|
+
successfulActions: number;
|
|
394
|
+
failedActions: number;
|
|
395
|
+
blockedActions: number;
|
|
396
|
+
duration: number;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface Changes {
|
|
401
|
+
filePath: string;
|
|
402
|
+
timestamp: Date;
|
|
403
|
+
diff: Diff;
|
|
404
|
+
agent: string;
|
|
405
|
+
reasoning: string;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export interface Attribution {
|
|
409
|
+
projectId: string;
|
|
410
|
+
period: DateRange;
|
|
411
|
+
aiGenerated: {
|
|
412
|
+
lines: number;
|
|
413
|
+
files: number;
|
|
414
|
+
percentage: number;
|
|
415
|
+
};
|
|
416
|
+
humanWritten: {
|
|
417
|
+
lines: number;
|
|
418
|
+
files: number;
|
|
419
|
+
percentage: number;
|
|
420
|
+
};
|
|
421
|
+
breakdown: {
|
|
422
|
+
agent: string;
|
|
423
|
+
lines: number;
|
|
424
|
+
files: number;
|
|
425
|
+
}[];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface DateRange {
|
|
429
|
+
start: Date;
|
|
430
|
+
end: Date;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export type ReportType = 'audit' | 'compliance' | 'security' | 'attribution';
|
|
434
|
+
|
|
435
|
+
export interface Report {
|
|
436
|
+
type: ReportType;
|
|
437
|
+
period: DateRange;
|
|
438
|
+
summary: Record<string, unknown>;
|
|
439
|
+
details: unknown[];
|
|
440
|
+
generatedAt: Date;
|
|
441
|
+
}
|
package/src/utils.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a unique correlation ID for tracking related actions
|
|
3
|
+
*/
|
|
4
|
+
export declare function generateCorrelationId(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a task ID
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateTaskId(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate SHA-256 hash of content
|
|
11
|
+
*/
|
|
12
|
+
export declare function calculateHash(content: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate content entropy (randomness measure for secret detection)
|
|
15
|
+
*/
|
|
16
|
+
export declare function calculateEntropy(str: string): number;
|
|
17
|
+
/**
|
|
18
|
+
* Mask sensitive value for logging
|
|
19
|
+
*/
|
|
20
|
+
export declare function maskSensitiveValue(value: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a path is within allowed paths
|
|
23
|
+
*/
|
|
24
|
+
export declare function isPathAllowed(path: string, allowedPaths: string[], deniedPaths: string[]): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a domain is allowed
|
|
27
|
+
*/
|
|
28
|
+
export declare function isDomainAllowed(url: string, allowedDomains: string[], deniedDomains: string[]): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sanitize error message for safe logging
|
|
31
|
+
*/
|
|
32
|
+
export declare function sanitizeError(error: unknown): {
|
|
33
|
+
message: string;
|
|
34
|
+
code?: string;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqBpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EAAE,EACtB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAuBT;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,MAAM,EAAE,EACxB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CA4BT;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAQhF"}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a unique correlation ID for tracking related actions
|
|
5
|
+
*/
|
|
6
|
+
export function generateCorrelationId(): string {
|
|
7
|
+
return `corr_${Date.now()}_${crypto.randomBytes(8).toString('hex')}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generate a task ID
|
|
12
|
+
*/
|
|
13
|
+
export function generateTaskId(): string {
|
|
14
|
+
return `task_${Date.now()}_${crypto.randomBytes(8).toString('hex')}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Calculate SHA-256 hash of content
|
|
19
|
+
*/
|
|
20
|
+
export function calculateHash(content: string): string {
|
|
21
|
+
return crypto.createHash('sha256').update(content).digest('hex');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Calculate content entropy (randomness measure for secret detection)
|
|
26
|
+
*/
|
|
27
|
+
export function calculateEntropy(str: string): number {
|
|
28
|
+
const len = str.length;
|
|
29
|
+
const frequencies: Record<string, number> = {};
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < len; i++) {
|
|
32
|
+
const char = str[i];
|
|
33
|
+
if (char) {
|
|
34
|
+
frequencies[char] = (frequencies[char] || 0) + 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let entropy = 0;
|
|
39
|
+
for (const char in frequencies) {
|
|
40
|
+
const frequency = frequencies[char];
|
|
41
|
+
if (frequency !== undefined) {
|
|
42
|
+
const p = frequency / len;
|
|
43
|
+
entropy -= p * Math.log2(p);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return entropy;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Mask sensitive value for logging
|
|
52
|
+
*/
|
|
53
|
+
export function maskSensitiveValue(value: string): string {
|
|
54
|
+
if (value.length <= 8) {
|
|
55
|
+
return '***';
|
|
56
|
+
}
|
|
57
|
+
return `${value.substring(0, 4)}...${value.substring(value.length - 4)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if a path is within allowed paths
|
|
62
|
+
*/
|
|
63
|
+
export function isPathAllowed(
|
|
64
|
+
path: string,
|
|
65
|
+
allowedPaths: string[],
|
|
66
|
+
deniedPaths: string[]
|
|
67
|
+
): boolean {
|
|
68
|
+
const normalizedPath = path.replace(/\\/g, '/');
|
|
69
|
+
|
|
70
|
+
// Check denied paths first (more restrictive)
|
|
71
|
+
for (const deniedPath of deniedPaths) {
|
|
72
|
+
if (normalizedPath.startsWith(deniedPath.replace(/\\/g, '/'))) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If no allowed paths specified, allow all (except denied)
|
|
78
|
+
if (allowedPaths.length === 0) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Check allowed paths
|
|
83
|
+
for (const allowedPath of allowedPaths) {
|
|
84
|
+
if (normalizedPath.startsWith(allowedPath.replace(/\\/g, '/'))) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Check if a domain is allowed
|
|
94
|
+
*/
|
|
95
|
+
export function isDomainAllowed(
|
|
96
|
+
url: string,
|
|
97
|
+
allowedDomains: string[],
|
|
98
|
+
deniedDomains: string[]
|
|
99
|
+
): boolean {
|
|
100
|
+
try {
|
|
101
|
+
const urlObj = new URL(url);
|
|
102
|
+
const hostname = urlObj.hostname;
|
|
103
|
+
|
|
104
|
+
// Check denied domains first
|
|
105
|
+
for (const deniedDomain of deniedDomains) {
|
|
106
|
+
if (hostname === deniedDomain || hostname.endsWith(`.${deniedDomain}`)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// If no allowed domains specified, allow all (except denied)
|
|
112
|
+
if (allowedDomains.length === 0) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Check allowed domains
|
|
117
|
+
for (const allowedDomain of allowedDomains) {
|
|
118
|
+
if (hostname === allowedDomain || hostname.endsWith(`.${allowedDomain}`)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return false;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Sanitize error message for safe logging
|
|
131
|
+
*/
|
|
132
|
+
export function sanitizeError(error: unknown): { message: string; code?: string } {
|
|
133
|
+
if (error instanceof Error) {
|
|
134
|
+
return {
|
|
135
|
+
message: error.message.replace(/\/[^\s:]+/g, '[path]'),
|
|
136
|
+
code: (error as any).code,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return { message: 'Unknown error occurred' };
|
|
140
|
+
}
|