erosolar-cli 1.7.22 → 1.7.23
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/core/responseVerifier.d.ts +59 -5
- package/dist/core/responseVerifier.d.ts.map +1 -1
- package/dist/core/responseVerifier.js +191 -232
- package/dist/core/responseVerifier.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts +7 -2
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +41 -15
- package/dist/shell/interactiveShell.js.map +1 -1
- package/package.json +1 -1
|
@@ -84,17 +84,20 @@ export declare function extractClaims(response: string): VerifiableClaim[];
|
|
|
84
84
|
*/
|
|
85
85
|
export declare function generateVerificationTest(claim: VerifiableClaim): () => Promise<ClaimVerificationResult>;
|
|
86
86
|
/**
|
|
87
|
-
* Verify all claims in an assistant response
|
|
87
|
+
* Verify all claims in an assistant response using LLM-based semantic analysis.
|
|
88
|
+
* Requires a VerificationContext with an llmVerifier function.
|
|
89
|
+
* All claim extraction and verification is done via LLM.
|
|
88
90
|
*/
|
|
89
|
-
export declare function verifyResponse(response: string, responseId?: string): Promise<VerificationReport>;
|
|
91
|
+
export declare function verifyResponse(response: string, context: VerificationContext, responseId?: string): Promise<VerificationReport>;
|
|
90
92
|
/**
|
|
91
93
|
* Format a verification report for display
|
|
92
94
|
*/
|
|
93
95
|
export declare function formatVerificationReport(report: VerificationReport): string;
|
|
94
96
|
/**
|
|
95
|
-
* Quick verification - returns true if response claims are valid
|
|
97
|
+
* Quick verification - returns true if response claims are valid.
|
|
98
|
+
* Requires a VerificationContext with llmVerifier for LLM-based semantic analysis.
|
|
96
99
|
*/
|
|
97
|
-
export declare function quickVerify(response: string): Promise<boolean>;
|
|
100
|
+
export declare function quickVerify(response: string, context: VerificationContext): Promise<boolean>;
|
|
98
101
|
/**
|
|
99
102
|
* Verification strategy types
|
|
100
103
|
*/
|
|
@@ -118,7 +121,8 @@ export declare function verifyClaimWithLLM(claim: VerifiableClaim, context: Veri
|
|
|
118
121
|
*/
|
|
119
122
|
export declare function generateExtendedVerificationTest(claim: VerifiableClaim, context: VerificationContext): () => Promise<ClaimVerificationResult>;
|
|
120
123
|
/**
|
|
121
|
-
* Comprehensive verification using
|
|
124
|
+
* Comprehensive verification using LLM-based semantic analysis.
|
|
125
|
+
* Requires an LLM verifier - all claims are verified through LLM semantic analysis.
|
|
122
126
|
*/
|
|
123
127
|
export declare function verifyResponseComprehensive(response: string, context: VerificationContext, responseId?: string): Promise<VerificationReport>;
|
|
124
128
|
/**
|
|
@@ -164,4 +168,54 @@ export declare function verifyResponseWithGeneratedTests(response: string, conte
|
|
|
164
168
|
* Hybrid verification - uses generated tests when available, falls back to predefined tests
|
|
165
169
|
*/
|
|
166
170
|
export declare function verifyResponseHybrid(response: string, context: VerificationContext, responseId?: string): Promise<VerificationReport>;
|
|
171
|
+
export interface UniversalClaim {
|
|
172
|
+
id: string;
|
|
173
|
+
statement: string;
|
|
174
|
+
category: string;
|
|
175
|
+
verifiable: boolean;
|
|
176
|
+
verificationApproach: string;
|
|
177
|
+
priority: 'critical' | 'high' | 'medium' | 'low';
|
|
178
|
+
context: Record<string, unknown>;
|
|
179
|
+
}
|
|
180
|
+
export interface UniversalVerificationResult {
|
|
181
|
+
claim: UniversalClaim;
|
|
182
|
+
verified: boolean;
|
|
183
|
+
confidence: number;
|
|
184
|
+
method: string;
|
|
185
|
+
evidence: string;
|
|
186
|
+
reasoning: string;
|
|
187
|
+
suggestedFollowUp?: string;
|
|
188
|
+
executedCode?: string;
|
|
189
|
+
rawOutput?: string;
|
|
190
|
+
timestamp: string;
|
|
191
|
+
}
|
|
192
|
+
export interface UniversalVerificationReport {
|
|
193
|
+
responseId: string;
|
|
194
|
+
originalResponse: string;
|
|
195
|
+
timestamp: string;
|
|
196
|
+
claims: UniversalClaim[];
|
|
197
|
+
results: UniversalVerificationResult[];
|
|
198
|
+
summary: {
|
|
199
|
+
totalClaims: number;
|
|
200
|
+
verifiableClaims: number;
|
|
201
|
+
verified: number;
|
|
202
|
+
failed: number;
|
|
203
|
+
inconclusive: number;
|
|
204
|
+
averageConfidence: number;
|
|
205
|
+
};
|
|
206
|
+
overallAssessment: string;
|
|
207
|
+
trustScore: number;
|
|
208
|
+
}
|
|
209
|
+
export declare function validateUniversalCode(c: string): {
|
|
210
|
+
safe: boolean;
|
|
211
|
+
reason: string;
|
|
212
|
+
};
|
|
213
|
+
export declare function extractUniversalClaims(r: string, ctx: VerificationContext): Promise<UniversalClaim[]>;
|
|
214
|
+
export declare function verifyUniversalClaim(claim: UniversalClaim, ctx: VerificationContext): Promise<UniversalVerificationResult>;
|
|
215
|
+
export declare function verifyResponseUniversal(response: string, ctx: VerificationContext, id?: string): Promise<UniversalVerificationReport>;
|
|
216
|
+
export declare function quickUniversalVerify(r: string, ctx: VerificationContext): Promise<{
|
|
217
|
+
trustScore: number;
|
|
218
|
+
summary: string;
|
|
219
|
+
}>;
|
|
220
|
+
export declare function formatUniversalReport(r: UniversalVerificationReport): string;
|
|
167
221
|
//# sourceMappingURL=responseVerifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseVerifier.d.ts","sourceRoot":"","sources":["../../src/core/responseVerifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,cAAc,GACd,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,eAAe,GACf,YAAY,GACZ,kBAAkB,GAClB,sBAAsB,GACtB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,mBAAmB,GAEnB,cAAc,GACd,kBAAkB,GAClB,gBAAgB,GAChB,aAAa,GACb,oBAAoB,GACpB,kBAAkB,GAClB,aAAa,GACb,qBAAqB,GACrB,mBAAmB,GACnB,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,MAAM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AC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,cAAc,EAAE,UAAU,GAAG,oBAAoB,GAAG,YAAY,GAAG,cAAc,CAAC;CACnF;AAkFD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAC5C,OAAO,CAAC,eAAe,EAAE,CAAC,CAgC5B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,EAAE,CA8TjE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,OAAO,CAAC,uBAAuB,CAAC,CAsWvG;AAED
|
|
1
|
+
{"version":3,"file":"responseVerifier.d.ts","sourceRoot":"","sources":["../../src/core/responseVerifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,cAAc,GACd,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,eAAe,GACf,YAAY,GACZ,kBAAkB,GAClB,sBAAsB,GACtB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,mBAAmB,GAEnB,cAAc,GACd,kBAAkB,GAClB,gBAAgB,GAChB,aAAa,GACb,oBAAoB,GACpB,kBAAkB,GAClB,aAAa,GACb,qBAAqB,GACrB,mBAAmB,GACnB,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EA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AC;IACvC,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;QACzB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AA2BD,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAGlF;AAaD,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAS3G;AAED,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAehI;AAED,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAa3I;AAED,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAMhI;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,2BAA2B,GAAG,MAAM,CAQ5E"}
|
|
@@ -764,57 +764,12 @@ export function generateVerificationTest(claim) {
|
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
766
|
/**
|
|
767
|
-
* Verify all claims in an assistant response
|
|
767
|
+
* Verify all claims in an assistant response using LLM-based semantic analysis.
|
|
768
|
+
* Requires a VerificationContext with an llmVerifier function.
|
|
769
|
+
* All claim extraction and verification is done via LLM.
|
|
768
770
|
*/
|
|
769
|
-
export async function verifyResponse(response, responseId) {
|
|
770
|
-
|
|
771
|
-
const results = [];
|
|
772
|
-
for (const claim of claims) {
|
|
773
|
-
const test = generateVerificationTest(claim);
|
|
774
|
-
try {
|
|
775
|
-
const result = await test();
|
|
776
|
-
results.push(result);
|
|
777
|
-
}
|
|
778
|
-
catch (err) {
|
|
779
|
-
results.push({
|
|
780
|
-
claim,
|
|
781
|
-
verified: false,
|
|
782
|
-
confidence: 'low',
|
|
783
|
-
evidence: 'Verification test failed to execute',
|
|
784
|
-
error: err instanceof Error ? err.message : 'Unknown error',
|
|
785
|
-
timestamp: new Date().toISOString()
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
const verified = results.filter(r => r.verified).length;
|
|
790
|
-
const failed = results.filter(r => !r.verified && r.confidence === 'high').length;
|
|
791
|
-
const inconclusive = results.filter(r => !r.verified && r.confidence !== 'high').length;
|
|
792
|
-
let overallVerdict;
|
|
793
|
-
if (failed > 0) {
|
|
794
|
-
overallVerdict = 'contradicted';
|
|
795
|
-
}
|
|
796
|
-
else if (verified === claims.length && claims.length > 0) {
|
|
797
|
-
overallVerdict = 'verified';
|
|
798
|
-
}
|
|
799
|
-
else if (verified > 0) {
|
|
800
|
-
overallVerdict = 'partially_verified';
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
overallVerdict = 'unverified';
|
|
804
|
-
}
|
|
805
|
-
return {
|
|
806
|
-
responseId: responseId || `response-${Date.now()}`,
|
|
807
|
-
timestamp: new Date().toISOString(),
|
|
808
|
-
claims,
|
|
809
|
-
results,
|
|
810
|
-
summary: {
|
|
811
|
-
total: claims.length,
|
|
812
|
-
verified,
|
|
813
|
-
failed,
|
|
814
|
-
inconclusive
|
|
815
|
-
},
|
|
816
|
-
overallVerdict
|
|
817
|
-
};
|
|
771
|
+
export async function verifyResponse(response, context, responseId) {
|
|
772
|
+
return verifyResponseComprehensive(response, context, responseId);
|
|
818
773
|
}
|
|
819
774
|
/**
|
|
820
775
|
* Format a verification report for display
|
|
@@ -854,10 +809,11 @@ export function formatVerificationReport(report) {
|
|
|
854
809
|
return lines.join('\n');
|
|
855
810
|
}
|
|
856
811
|
/**
|
|
857
|
-
* Quick verification - returns true if response claims are valid
|
|
812
|
+
* Quick verification - returns true if response claims are valid.
|
|
813
|
+
* Requires a VerificationContext with llmVerifier for LLM-based semantic analysis.
|
|
858
814
|
*/
|
|
859
|
-
export async function quickVerify(response) {
|
|
860
|
-
const report = await verifyResponse(response);
|
|
815
|
+
export async function quickVerify(response, context) {
|
|
816
|
+
const report = await verifyResponse(response, context);
|
|
861
817
|
return report.overallVerdict === 'verified' || report.overallVerdict === 'partially_verified';
|
|
862
818
|
}
|
|
863
819
|
/**
|
|
@@ -1120,203 +1076,59 @@ export function generateExtendedVerificationTest(claim, context) {
|
|
|
1120
1076
|
case 'error_fixed':
|
|
1121
1077
|
case 'feature_implemented':
|
|
1122
1078
|
case 'refactor_complete':
|
|
1123
|
-
// These require semantic verification -
|
|
1079
|
+
// These require semantic verification - LLM is required
|
|
1124
1080
|
return async () => {
|
|
1125
|
-
if (context.llmVerifier) {
|
|
1126
|
-
return
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
const resolvedPath = path.isAbsolute(relatedPath)
|
|
1133
|
-
? relatedPath
|
|
1134
|
-
: path.resolve(context.workingDirectory, relatedPath);
|
|
1135
|
-
const stats = await fs.stat(resolvedPath);
|
|
1136
|
-
const recentlyModified = (Date.now() - stats.mtimeMs) < 10 * 60 * 1000;
|
|
1137
|
-
return {
|
|
1138
|
-
...baseResult,
|
|
1139
|
-
verified: recentlyModified,
|
|
1140
|
-
confidence: 'low',
|
|
1141
|
-
evidence: recentlyModified
|
|
1142
|
-
? `Related file ${relatedPath} was recently modified`
|
|
1143
|
-
: `Related file ${relatedPath} exists but wasn't recently modified`
|
|
1144
|
-
};
|
|
1145
|
-
}
|
|
1146
|
-
catch {
|
|
1147
|
-
return {
|
|
1148
|
-
...baseResult,
|
|
1149
|
-
verified: false,
|
|
1150
|
-
confidence: 'low',
|
|
1151
|
-
evidence: 'Could not verify - no LLM available and related file not found'
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1081
|
+
if (!context.llmVerifier) {
|
|
1082
|
+
return {
|
|
1083
|
+
...baseResult,
|
|
1084
|
+
verified: false,
|
|
1085
|
+
confidence: 'low',
|
|
1086
|
+
evidence: 'Semantic verification requires LLM verifier'
|
|
1087
|
+
};
|
|
1154
1088
|
}
|
|
1155
|
-
return
|
|
1156
|
-
...baseResult,
|
|
1157
|
-
verified: false,
|
|
1158
|
-
confidence: 'low',
|
|
1159
|
-
evidence: 'Semantic verification required but no LLM verifier available'
|
|
1160
|
-
};
|
|
1089
|
+
return verifyClaimWithLLM(claim, context);
|
|
1161
1090
|
};
|
|
1162
1091
|
case 'data_transformed':
|
|
1163
|
-
return async () => {
|
|
1164
|
-
// Check if we have before/after state to compare
|
|
1165
|
-
if (context.previousState && context.currentState) {
|
|
1166
|
-
const inputKey = claim.params.input;
|
|
1167
|
-
const outputKey = claim.params.output;
|
|
1168
|
-
if (inputKey && outputKey) {
|
|
1169
|
-
const inputExists = context.previousState[inputKey] !== undefined;
|
|
1170
|
-
const outputExists = context.currentState[outputKey] !== undefined;
|
|
1171
|
-
return {
|
|
1172
|
-
...baseResult,
|
|
1173
|
-
verified: inputExists && outputExists,
|
|
1174
|
-
confidence: inputExists && outputExists ? 'medium' : 'low',
|
|
1175
|
-
evidence: `Input "${inputKey}" ${inputExists ? 'found' : 'missing'}, Output "${outputKey}" ${outputExists ? 'found' : 'missing'}`
|
|
1176
|
-
};
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
// Fall back to LLM verification
|
|
1180
|
-
if (context.llmVerifier) {
|
|
1181
|
-
return verifyClaimWithLLM(claim, context);
|
|
1182
|
-
}
|
|
1183
|
-
return {
|
|
1184
|
-
...baseResult,
|
|
1185
|
-
verified: false,
|
|
1186
|
-
confidence: 'low',
|
|
1187
|
-
evidence: 'Cannot verify data transformation without state comparison or LLM'
|
|
1188
|
-
};
|
|
1189
|
-
};
|
|
1190
1092
|
case 'database_updated':
|
|
1191
|
-
return async () => {
|
|
1192
|
-
// Can't directly verify database changes without connection info
|
|
1193
|
-
// Check if there's a command we can run
|
|
1194
|
-
const checkCommand = claim.params.checkCommand;
|
|
1195
|
-
if (checkCommand) {
|
|
1196
|
-
try {
|
|
1197
|
-
const { stdout } = await execAsync(checkCommand, {
|
|
1198
|
-
timeout: 10000,
|
|
1199
|
-
cwd: context.workingDirectory
|
|
1200
|
-
});
|
|
1201
|
-
return {
|
|
1202
|
-
...baseResult,
|
|
1203
|
-
verified: true,
|
|
1204
|
-
confidence: 'medium',
|
|
1205
|
-
evidence: `Check command output: ${stdout.slice(0, 200)}`
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
catch (err) {
|
|
1209
|
-
return {
|
|
1210
|
-
...baseResult,
|
|
1211
|
-
verified: false,
|
|
1212
|
-
confidence: 'medium',
|
|
1213
|
-
evidence: 'Database check command failed',
|
|
1214
|
-
error: err instanceof Error ? err.message : 'Unknown error'
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
// Fall back to LLM
|
|
1219
|
-
if (context.llmVerifier) {
|
|
1220
|
-
return verifyClaimWithLLM(claim, context);
|
|
1221
|
-
}
|
|
1222
|
-
return {
|
|
1223
|
-
...baseResult,
|
|
1224
|
-
verified: false,
|
|
1225
|
-
confidence: 'low',
|
|
1226
|
-
evidence: 'Cannot verify database changes without check command or LLM'
|
|
1227
|
-
};
|
|
1228
|
-
};
|
|
1229
1093
|
case 'permission_granted':
|
|
1230
|
-
return async () => {
|
|
1231
|
-
const targetPath = claim.params.path;
|
|
1232
|
-
const expectedMode = claim.params.mode;
|
|
1233
|
-
if (targetPath) {
|
|
1234
|
-
try {
|
|
1235
|
-
const resolvedPath = path.isAbsolute(targetPath)
|
|
1236
|
-
? targetPath
|
|
1237
|
-
: path.resolve(context.workingDirectory, targetPath);
|
|
1238
|
-
const stats = await fs.stat(resolvedPath);
|
|
1239
|
-
const mode = (stats.mode & 0o777).toString(8);
|
|
1240
|
-
if (expectedMode) {
|
|
1241
|
-
const matches = mode === expectedMode;
|
|
1242
|
-
return {
|
|
1243
|
-
...baseResult,
|
|
1244
|
-
verified: matches,
|
|
1245
|
-
confidence: 'high',
|
|
1246
|
-
evidence: matches
|
|
1247
|
-
? `File has expected permissions: ${mode}`
|
|
1248
|
-
: `Expected mode ${expectedMode}, got ${mode}`
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
return {
|
|
1252
|
-
...baseResult,
|
|
1253
|
-
verified: true,
|
|
1254
|
-
confidence: 'medium',
|
|
1255
|
-
evidence: `File permissions: ${mode}`
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
catch (err) {
|
|
1259
|
-
return {
|
|
1260
|
-
...baseResult,
|
|
1261
|
-
verified: false,
|
|
1262
|
-
confidence: 'high',
|
|
1263
|
-
evidence: 'Could not check file permissions',
|
|
1264
|
-
error: err instanceof Error ? err.message : 'Unknown error'
|
|
1265
|
-
};
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
// Fall back to LLM
|
|
1269
|
-
if (context.llmVerifier) {
|
|
1270
|
-
return verifyClaimWithLLM(claim, context);
|
|
1271
|
-
}
|
|
1272
|
-
return {
|
|
1273
|
-
...baseResult,
|
|
1274
|
-
verified: false,
|
|
1275
|
-
confidence: 'low',
|
|
1276
|
-
evidence: 'Cannot verify permission without file path or LLM'
|
|
1277
|
-
};
|
|
1278
|
-
};
|
|
1279
1094
|
case 'generic':
|
|
1280
1095
|
default:
|
|
1281
|
-
//
|
|
1096
|
+
// All these claim types require LLM verification
|
|
1282
1097
|
return async () => {
|
|
1283
|
-
if (context.llmVerifier) {
|
|
1284
|
-
return
|
|
1098
|
+
if (!context.llmVerifier) {
|
|
1099
|
+
return {
|
|
1100
|
+
...baseResult,
|
|
1101
|
+
verified: false,
|
|
1102
|
+
confidence: 'low',
|
|
1103
|
+
evidence: `${claim.type} verification requires LLM verifier`
|
|
1104
|
+
};
|
|
1285
1105
|
}
|
|
1286
|
-
return
|
|
1287
|
-
...baseResult,
|
|
1288
|
-
verified: false,
|
|
1289
|
-
confidence: 'low',
|
|
1290
|
-
evidence: 'Generic claim requires LLM verification which is not available'
|
|
1291
|
-
};
|
|
1106
|
+
return verifyClaimWithLLM(claim, context);
|
|
1292
1107
|
};
|
|
1293
1108
|
}
|
|
1294
1109
|
}
|
|
1295
1110
|
/**
|
|
1296
|
-
* Comprehensive verification using
|
|
1111
|
+
* Comprehensive verification using LLM-based semantic analysis.
|
|
1112
|
+
* Requires an LLM verifier - all claims are verified through LLM semantic analysis.
|
|
1297
1113
|
*/
|
|
1298
1114
|
export async function verifyResponseComprehensive(response, context, responseId) {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1115
|
+
if (!context.llmVerifier) {
|
|
1116
|
+
return {
|
|
1117
|
+
responseId: responseId || `response-${Date.now()}`,
|
|
1118
|
+
timestamp: new Date().toISOString(),
|
|
1119
|
+
claims: [],
|
|
1120
|
+
results: [],
|
|
1121
|
+
summary: { total: 0, verified: 0, failed: 0, inconclusive: 0 },
|
|
1122
|
+
overallVerdict: 'unverified'
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
// Extract ALL claims using LLM (required)
|
|
1126
|
+
const claims = await extractClaimsWithLLM(response, context.llmVerifier);
|
|
1303
1127
|
const results = [];
|
|
1304
1128
|
for (const claim of claims) {
|
|
1305
|
-
//
|
|
1306
|
-
const standardTypes = [
|
|
1307
|
-
'file_created', 'file_modified', 'file_deleted', 'code_compiles',
|
|
1308
|
-
'tests_pass', 'git_committed', 'package_published', 'command_executed',
|
|
1309
|
-
'dependency_installed', 'service_running', 'url_accessible', 'content_contains'
|
|
1310
|
-
];
|
|
1311
|
-
let test;
|
|
1312
|
-
if (standardTypes.includes(claim.type)) {
|
|
1313
|
-
test = generateVerificationTest(claim);
|
|
1314
|
-
}
|
|
1315
|
-
else {
|
|
1316
|
-
test = generateExtendedVerificationTest(claim, context);
|
|
1317
|
-
}
|
|
1129
|
+
// ALL claims are verified via LLM semantic analysis
|
|
1318
1130
|
try {
|
|
1319
|
-
const result = await
|
|
1131
|
+
const result = await verifyClaimWithLLM(claim, context);
|
|
1320
1132
|
results.push(result);
|
|
1321
1133
|
}
|
|
1322
1134
|
catch (err) {
|
|
@@ -1324,7 +1136,7 @@ export async function verifyResponseComprehensive(response, context, responseId)
|
|
|
1324
1136
|
claim,
|
|
1325
1137
|
verified: false,
|
|
1326
1138
|
confidence: 'low',
|
|
1327
|
-
evidence: '
|
|
1139
|
+
evidence: 'LLM verification failed',
|
|
1328
1140
|
error: err instanceof Error ? err.message : 'Unknown error',
|
|
1329
1141
|
timestamp: new Date().toISOString()
|
|
1330
1142
|
});
|
|
@@ -1814,4 +1626,151 @@ export async function verifyResponseHybrid(response, context, responseId) {
|
|
|
1814
1626
|
overallVerdict
|
|
1815
1627
|
};
|
|
1816
1628
|
}
|
|
1629
|
+
const UNIVERSAL_EXTRACT = `Extract ALL verifiable claims from this AI response. Include explicit claims, implicit claims, state changes, results, assertions.
|
|
1630
|
+
|
|
1631
|
+
RESPONSE:
|
|
1632
|
+
---
|
|
1633
|
+
{RESPONSE}
|
|
1634
|
+
---
|
|
1635
|
+
CONTEXT: {CONTEXT}
|
|
1636
|
+
DIR: {WORKING_DIR}
|
|
1637
|
+
|
|
1638
|
+
Return JSON array: [{"id":"c1","statement":"claim","category":"file_op|code|state|data|behavior|fact|other","verifiable":true/false,"verificationApproach":"how","priority":"critical|high|medium|low","context":{}}]
|
|
1639
|
+
Output ONLY valid JSON.`;
|
|
1640
|
+
const UNIVERSAL_GEN = `Generate verification code for: {STATEMENT}
|
|
1641
|
+
Category: {CATEGORY} | Approach: {APPROACH} | Context: {CONTEXT} | Dir: {WORKING_DIR} | Platform: {PLATFORM}
|
|
1642
|
+
|
|
1643
|
+
Use shell/javascript/python. READ-ONLY only.
|
|
1644
|
+
Return JSON: {"steps":[{"type":"shell|javascript|python","code":"code","desc":"what"}],"success":"success criteria","failure":"failure criteria","confPass":0-100,"confFail":0-100,"safe":{"ok":true/false,"why":"reason"}}
|
|
1645
|
+
Output ONLY valid JSON.`;
|
|
1646
|
+
const UNIVERSAL_ASSESS = `Assess: RESPONSE:{RESPONSE} CLAIMS:{CLAIMS} RESULTS:{RESULTS}
|
|
1647
|
+
Return JSON: {"trust":0-100,"summary":"text","concerns":[]}
|
|
1648
|
+
Output ONLY valid JSON.`;
|
|
1649
|
+
const UNSAFE = [/\brm\s/i, /rmdir/i, /sudo/i, /chmod\s*7/i, /eval\s*\(/i, /exec\s*\(/i, /child_process/i, /os\.system/i, /subprocess/i, /curl.*\|.*sh/i, /DROP\s+TABLE/i, /DELETE\s+FROM/i, /kill/i];
|
|
1650
|
+
export function validateUniversalCode(c) {
|
|
1651
|
+
for (const p of UNSAFE)
|
|
1652
|
+
if (p.test(c))
|
|
1653
|
+
return { safe: false, reason: p.source };
|
|
1654
|
+
return c.length > 5000 ? { safe: false, reason: 'too long' } : { safe: true, reason: 'ok' };
|
|
1655
|
+
}
|
|
1656
|
+
async function runUniversalStep(s, cwd) {
|
|
1657
|
+
const v = validateUniversalCode(s.code);
|
|
1658
|
+
if (!v.safe)
|
|
1659
|
+
return { ok: false, out: v.reason };
|
|
1660
|
+
try {
|
|
1661
|
+
if (s.type === 'shell') {
|
|
1662
|
+
const { stdout, stderr } = await execAsync(s.code, { cwd, timeout: 30000, maxBuffer: 5 * 1024 * 1024 });
|
|
1663
|
+
return { ok: true, out: stdout + stderr };
|
|
1664
|
+
}
|
|
1665
|
+
if (s.type === 'javascript') {
|
|
1666
|
+
const w = `(async()=>{try{const fs=require('fs').promises;const r=await(async()=>{${s.code}})();console.log(JSON.stringify({ok:1,r}))}catch(e){console.log(JSON.stringify({ok:0,e:e.message}))}})()`;
|
|
1667
|
+
const { stdout } = await execAsync(`node -e ${JSON.stringify(w)}`, { cwd, timeout: 30000 });
|
|
1668
|
+
return { ok: true, out: stdout };
|
|
1669
|
+
}
|
|
1670
|
+
if (s.type === 'python') {
|
|
1671
|
+
const { stdout, stderr } = await execAsync(`python3 -c ${JSON.stringify(s.code)}`, { cwd, timeout: 30000 });
|
|
1672
|
+
return { ok: true, out: stdout + stderr };
|
|
1673
|
+
}
|
|
1674
|
+
return { ok: false, out: 'unknown type' };
|
|
1675
|
+
}
|
|
1676
|
+
catch (e) {
|
|
1677
|
+
return { ok: false, out: e instanceof Error ? e.message : 'err' };
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
export async function extractUniversalClaims(r, ctx) {
|
|
1681
|
+
if (!ctx.llmVerifier)
|
|
1682
|
+
return extractClaims(r).map((c, i) => ({ id: `c${i}`, statement: c.description, category: c.type, verifiable: true, verificationApproach: 'runtime', priority: 'medium', context: c.params }));
|
|
1683
|
+
try {
|
|
1684
|
+
const p = UNIVERSAL_EXTRACT.replace('{RESPONSE}', r.slice(0, 8000)).replace('{CONTEXT}', ctx.conversationHistory?.slice(-3).join('\n') || '').replace('{WORKING_DIR}', ctx.workingDirectory);
|
|
1685
|
+
const res = await ctx.llmVerifier(p);
|
|
1686
|
+
const m = res.match(/\[[\s\S]*\]/);
|
|
1687
|
+
if (m)
|
|
1688
|
+
return JSON.parse(m[0]);
|
|
1689
|
+
}
|
|
1690
|
+
catch { /* fall through */ }
|
|
1691
|
+
return extractClaims(r).map((c, i) => ({ id: `c${i}`, statement: c.description, category: c.type, verifiable: true, verificationApproach: 'runtime', priority: 'medium', context: c.params }));
|
|
1692
|
+
}
|
|
1693
|
+
export async function verifyUniversalClaim(claim, ctx) {
|
|
1694
|
+
const base = { claim, timestamp: new Date().toISOString() };
|
|
1695
|
+
if (!claim.verifiable)
|
|
1696
|
+
return { ...base, verified: false, confidence: 0, method: 'skip', evidence: 'Not verifiable', reasoning: 'Cannot verify' };
|
|
1697
|
+
if (!ctx.llmVerifier)
|
|
1698
|
+
return { ...base, verified: false, confidence: 0, method: 'skip', evidence: 'No LLM', reasoning: 'Needs LLM' };
|
|
1699
|
+
try {
|
|
1700
|
+
const p = UNIVERSAL_GEN.replace('{STATEMENT}', claim.statement).replace('{CATEGORY}', claim.category).replace('{APPROACH}', claim.verificationApproach).replace('{CONTEXT}', JSON.stringify(claim.context)).replace('{WORKING_DIR}', ctx.workingDirectory).replace('{PLATFORM}', process.platform);
|
|
1701
|
+
const res = await ctx.llmVerifier(p);
|
|
1702
|
+
const m = res.match(/\{[\s\S]*\}/);
|
|
1703
|
+
if (!m)
|
|
1704
|
+
throw new Error('bad');
|
|
1705
|
+
const plan = JSON.parse(m[0]);
|
|
1706
|
+
if (!plan.safe.ok)
|
|
1707
|
+
return { ...base, verified: false, confidence: 0, method: 'blocked', evidence: plan.safe.why, reasoning: 'Unsafe' };
|
|
1708
|
+
let allOk = true, out = '', code = '';
|
|
1709
|
+
for (const s of plan.steps) {
|
|
1710
|
+
code += s.code + '\n';
|
|
1711
|
+
const r = await runUniversalStep(s, ctx.workingDirectory);
|
|
1712
|
+
out += r.out + '\n';
|
|
1713
|
+
if (!r.ok)
|
|
1714
|
+
allOk = false;
|
|
1715
|
+
}
|
|
1716
|
+
return { ...base, verified: allOk, confidence: allOk ? plan.confPass : plan.confFail, method: plan.steps.map(s => s.type).join('+'), evidence: allOk ? plan.success : plan.failure, reasoning: allOk ? 'All passed' : 'Some failed', executedCode: code, rawOutput: out.slice(0, 2000) };
|
|
1717
|
+
}
|
|
1718
|
+
catch (e) {
|
|
1719
|
+
return { ...base, verified: false, confidence: 10, method: 'error', evidence: 'Failed', reasoning: e instanceof Error ? e.message : 'err' };
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
export async function verifyResponseUniversal(response, ctx, id) {
|
|
1723
|
+
const claims = await extractUniversalClaims(response, ctx);
|
|
1724
|
+
const results = [];
|
|
1725
|
+
for (const c of claims)
|
|
1726
|
+
results.push(c.verifiable || c.priority === 'critical' || c.priority === 'high' ? await verifyUniversalClaim(c, ctx) : { claim: c, verified: false, confidence: 0, method: 'skip', evidence: 'Low priority', reasoning: 'Skipped', timestamp: new Date().toISOString() });
|
|
1727
|
+
const vClaims = claims.filter(c => c.verifiable).length;
|
|
1728
|
+
const verified = results.filter(r => r.verified).length;
|
|
1729
|
+
const failed = results.filter(r => !r.verified && r.confidence > 50).length;
|
|
1730
|
+
const inconclusive = results.filter(r => !r.verified && r.confidence <= 50 && r.method !== 'skip').length;
|
|
1731
|
+
const avgConf = results.length ? results.reduce((s, r) => s + r.confidence, 0) / results.length : 0;
|
|
1732
|
+
let assessment = '', trust = 0;
|
|
1733
|
+
if (ctx.llmVerifier)
|
|
1734
|
+
try {
|
|
1735
|
+
const p = UNIVERSAL_ASSESS.replace('{RESPONSE}', response.slice(0, 4000)).replace('{CLAIMS}', JSON.stringify(claims.slice(0, 15))).replace('{RESULTS}', JSON.stringify(results.slice(0, 15)));
|
|
1736
|
+
const r = await ctx.llmVerifier(p);
|
|
1737
|
+
const m = r.match(/\{[\s\S]*\}/);
|
|
1738
|
+
if (m) {
|
|
1739
|
+
const a = JSON.parse(m[0]);
|
|
1740
|
+
trust = a.trust;
|
|
1741
|
+
assessment = a.summary + (a.concerns?.length ? ` Concerns: ${a.concerns.join('; ')}` : '');
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
catch {
|
|
1745
|
+
trust = Math.round(avgConf * verified / Math.max(vClaims, 1));
|
|
1746
|
+
assessment = `${verified}/${vClaims} verified`;
|
|
1747
|
+
}
|
|
1748
|
+
else {
|
|
1749
|
+
trust = Math.round(avgConf * verified / Math.max(vClaims, 1));
|
|
1750
|
+
assessment = `${verified}/${vClaims} verified`;
|
|
1751
|
+
}
|
|
1752
|
+
return { responseId: id || `u-${Date.now()}`, originalResponse: response, timestamp: new Date().toISOString(), claims, results, summary: { totalClaims: claims.length, verifiableClaims: vClaims, verified, failed, inconclusive, averageConfidence: Math.round(avgConf) }, overallAssessment: assessment, trustScore: trust };
|
|
1753
|
+
}
|
|
1754
|
+
export async function quickUniversalVerify(r, ctx) {
|
|
1755
|
+
const claims = await extractUniversalClaims(r, ctx);
|
|
1756
|
+
const crit = claims.filter(c => c.verifiable && (c.priority === 'critical' || c.priority === 'high')).slice(0, 5);
|
|
1757
|
+
if (!crit.length)
|
|
1758
|
+
return { trustScore: 50, summary: 'No critical claims' };
|
|
1759
|
+
let v = 0;
|
|
1760
|
+
for (const c of crit)
|
|
1761
|
+
if ((await verifyUniversalClaim(c, ctx)).verified)
|
|
1762
|
+
v++;
|
|
1763
|
+
return { trustScore: Math.round(v / crit.length * 100), summary: `${v}/${crit.length} critical verified` };
|
|
1764
|
+
}
|
|
1765
|
+
export function formatUniversalReport(r) {
|
|
1766
|
+
const bar = '█'.repeat(Math.round(r.trustScore / 10)) + '░'.repeat(10 - Math.round(r.trustScore / 10));
|
|
1767
|
+
const icon = r.trustScore >= 80 ? '✅' : r.trustScore >= 50 ? '⚠️' : '❌';
|
|
1768
|
+
let out = `╔════════════════════════════════════════════════════════════╗\n║ UNIVERSAL VERIFICATION REPORT ║\n╚════════════════════════════════════════════════════════════╝\n\n`;
|
|
1769
|
+
out += `Trust: ${icon} ${r.trustScore}/100 [${bar}]\n${r.overallAssessment}\n\nClaims: ${r.summary.totalClaims} | ✅ ${r.summary.verified} | ❌ ${r.summary.failed} | ❓ ${r.summary.inconclusive}\n\n`;
|
|
1770
|
+
for (const x of r.results.slice(0, 8))
|
|
1771
|
+
out += `${x.verified ? '✅' : x.confidence > 50 ? '❌' : '❓'} [${x.confidence}%] ${x.claim.statement.slice(0, 55)}...\n`;
|
|
1772
|
+
if (r.results.length > 8)
|
|
1773
|
+
out += `... +${r.results.length - 8} more\n`;
|
|
1774
|
+
return out;
|
|
1775
|
+
}
|
|
1817
1776
|
//# sourceMappingURL=responseVerifier.js.map
|