@probelabs/visor 0.1.145 → 0.1.146

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.
Files changed (57) hide show
  1. package/dist/index.js +4 -4
  2. package/dist/output/traces/{run-2026-02-26T07-47-34-788Z.ndjson → run-2026-02-26T07-50-40-741Z.ndjson} +84 -84
  3. package/dist/{traces/run-2026-02-26T07-48-25-935Z.ndjson → output/traces/run-2026-02-26T07-51-32-586Z.ndjson} +1092 -1092
  4. package/dist/sdk/{check-provider-registry-TG5G2TF3.mjs → check-provider-registry-TSAMMJ7Q.mjs} +5 -5
  5. package/dist/sdk/{check-provider-registry-HFPKHYTG.mjs → check-provider-registry-WSFL2SVQ.mjs} +5 -5
  6. package/dist/sdk/{chunk-5FXGIBJQ.mjs → chunk-4SYQL5UQ.mjs} +14 -14
  7. package/dist/sdk/{chunk-GZMQPC6D.mjs → chunk-74YJMONB.mjs} +14 -14
  8. package/dist/sdk/{chunk-XHIXKNUF.mjs → chunk-LSCWRTSY.mjs} +2 -2
  9. package/dist/sdk/{chunk-K3M5YVEU.mjs → chunk-LVOWWALU.mjs} +3 -3
  10. package/dist/sdk/{chunk-6XPTQBXL.mjs → chunk-Y4DBNDLQ.mjs} +2 -2
  11. package/dist/sdk/{chunk-6XPTQBXL.mjs.map → chunk-Y4DBNDLQ.mjs.map} +1 -1
  12. package/dist/sdk/{failure-condition-evaluator-2BJHKTMX.mjs → failure-condition-evaluator-SMOVMMES.mjs} +3 -3
  13. package/dist/sdk/{github-frontend-ICKRZ4VV.mjs → github-frontend-4L5YDHM4.mjs} +3 -3
  14. package/dist/sdk/{host-BYIV4QJ3.mjs → host-GYZ7XCLI.mjs} +2 -2
  15. package/dist/sdk/{routing-3XDRYU3Z.mjs → routing-CQDKRPTO.mjs} +4 -4
  16. package/dist/sdk/{schedule-tool-handler-BTLEDYAI.mjs → schedule-tool-handler-4YUM6Z5F.mjs} +5 -5
  17. package/dist/sdk/{schedule-tool-handler-R7PNPWWK.mjs → schedule-tool-handler-62K3NGH6.mjs} +5 -5
  18. package/dist/sdk/sdk.js +1 -1
  19. package/dist/sdk/sdk.js.map +1 -1
  20. package/dist/sdk/sdk.mjs +4 -4
  21. package/dist/sdk/{trace-helpers-OZTZBK6T.mjs → trace-helpers-AWCFW5KG.mjs} +2 -2
  22. package/dist/sdk/{workflow-check-provider-3IIKJFM4.mjs → workflow-check-provider-3N7HDIN6.mjs} +5 -5
  23. package/dist/sdk/{workflow-check-provider-RARO4N5E.mjs → workflow-check-provider-XC7E5OFH.mjs} +5 -5
  24. package/dist/traces/{run-2026-02-26T07-47-34-788Z.ndjson → run-2026-02-26T07-50-40-741Z.ndjson} +84 -84
  25. package/dist/{output/traces/run-2026-02-26T07-48-25-935Z.ndjson → traces/run-2026-02-26T07-51-32-586Z.ndjson} +1092 -1092
  26. package/package.json +1 -1
  27. package/dist/sdk/chunk-L6ABOJVL.mjs +0 -739
  28. package/dist/sdk/chunk-O7WE6HCA.mjs +0 -443
  29. package/dist/sdk/chunk-O7WE6HCA.mjs.map +0 -1
  30. package/dist/sdk/chunk-PES5G5RR.mjs +0 -1502
  31. package/dist/sdk/chunk-PES5G5RR.mjs.map +0 -1
  32. package/dist/sdk/chunk-XHIXKNUF.mjs.map +0 -1
  33. package/dist/sdk/failure-condition-evaluator-V3EJGD55.mjs +0 -17
  34. package/dist/sdk/github-frontend-PSGUGYHT.mjs +0 -1356
  35. package/dist/sdk/github-frontend-PSGUGYHT.mjs.map +0 -1
  36. package/dist/sdk/host-CVJ3VG5Y.mjs +0 -63
  37. package/dist/sdk/host-CVJ3VG5Y.mjs.map +0 -1
  38. package/dist/sdk/routing-AJNUTCH7.mjs +0 -25
  39. package/dist/sdk/trace-helpers-VUUP6ILH.mjs +0 -25
  40. package/dist/sdk/trace-helpers-VUUP6ILH.mjs.map +0 -1
  41. package/dist/sdk/workflow-check-provider-3IIKJFM4.mjs.map +0 -1
  42. package/dist/sdk/workflow-check-provider-RARO4N5E.mjs.map +0 -1
  43. /package/dist/sdk/{check-provider-registry-HFPKHYTG.mjs.map → check-provider-registry-TSAMMJ7Q.mjs.map} +0 -0
  44. /package/dist/sdk/{check-provider-registry-TG5G2TF3.mjs.map → check-provider-registry-WSFL2SVQ.mjs.map} +0 -0
  45. /package/dist/sdk/{chunk-5FXGIBJQ.mjs.map → chunk-4SYQL5UQ.mjs.map} +0 -0
  46. /package/dist/sdk/{chunk-GZMQPC6D.mjs.map → chunk-74YJMONB.mjs.map} +0 -0
  47. /package/dist/sdk/{chunk-L6ABOJVL.mjs.map → chunk-LSCWRTSY.mjs.map} +0 -0
  48. /package/dist/sdk/{chunk-K3M5YVEU.mjs.map → chunk-LVOWWALU.mjs.map} +0 -0
  49. /package/dist/sdk/{failure-condition-evaluator-2BJHKTMX.mjs.map → failure-condition-evaluator-SMOVMMES.mjs.map} +0 -0
  50. /package/dist/sdk/{github-frontend-ICKRZ4VV.mjs.map → github-frontend-4L5YDHM4.mjs.map} +0 -0
  51. /package/dist/sdk/{host-BYIV4QJ3.mjs.map → host-GYZ7XCLI.mjs.map} +0 -0
  52. /package/dist/sdk/{failure-condition-evaluator-V3EJGD55.mjs.map → routing-CQDKRPTO.mjs.map} +0 -0
  53. /package/dist/sdk/{routing-3XDRYU3Z.mjs.map → schedule-tool-handler-4YUM6Z5F.mjs.map} +0 -0
  54. /package/dist/sdk/{routing-AJNUTCH7.mjs.map → schedule-tool-handler-62K3NGH6.mjs.map} +0 -0
  55. /package/dist/sdk/{schedule-tool-handler-BTLEDYAI.mjs.map → trace-helpers-AWCFW5KG.mjs.map} +0 -0
  56. /package/dist/sdk/{schedule-tool-handler-R7PNPWWK.mjs.map → workflow-check-provider-3N7HDIN6.mjs.map} +0 -0
  57. /package/dist/sdk/{trace-helpers-OZTZBK6T.mjs.map → workflow-check-provider-XC7E5OFH.mjs.map} +0 -0
@@ -1,739 +0,0 @@
1
- import {
2
- addEvent,
3
- fallback_ndjson_exports,
4
- init_fallback_ndjson,
5
- init_trace_helpers
6
- } from "./chunk-6XPTQBXL.mjs";
7
- import {
8
- addFailIfTriggered,
9
- init_metrics
10
- } from "./chunk-JL7JXCET.mjs";
11
- import {
12
- createPermissionHelpers,
13
- detectLocalMode,
14
- init_author_permissions
15
- } from "./chunk-25IC7KXZ.mjs";
16
- import {
17
- createSecureSandbox,
18
- init_sandbox
19
- } from "./chunk-LW3INISN.mjs";
20
- import {
21
- MemoryStore,
22
- init_memory_store
23
- } from "./chunk-VPC3QSPW.mjs";
24
- import {
25
- init_logger,
26
- logger_exports
27
- } from "./chunk-SZXICFQ3.mjs";
28
- import {
29
- __esm,
30
- __export,
31
- __toCommonJS
32
- } from "./chunk-J7LXIPZS.mjs";
33
-
34
- // src/failure-condition-evaluator.ts
35
- var failure_condition_evaluator_exports = {};
36
- __export(failure_condition_evaluator_exports, {
37
- FailureConditionEvaluator: () => FailureConditionEvaluator
38
- });
39
- var FailureConditionEvaluator;
40
- var init_failure_condition_evaluator = __esm({
41
- "src/failure-condition-evaluator.ts"() {
42
- init_trace_helpers();
43
- init_metrics();
44
- init_sandbox();
45
- init_author_permissions();
46
- init_memory_store();
47
- FailureConditionEvaluator = class _FailureConditionEvaluator {
48
- sandbox;
49
- constructor() {
50
- }
51
- /**
52
- * Create a secure sandbox with whitelisted functions and globals
53
- */
54
- createSecureSandbox() {
55
- return createSecureSandbox();
56
- }
57
- /**
58
- * Evaluate simple fail_if condition
59
- */
60
- async evaluateSimpleCondition(checkName, checkSchema, checkGroup, reviewSummary, expression, previousOutputs, authorAssociation) {
61
- const context = this.buildEvaluationContext(
62
- checkName,
63
- checkSchema,
64
- checkGroup,
65
- reviewSummary,
66
- previousOutputs,
67
- authorAssociation
68
- );
69
- try {
70
- try {
71
- const isObj = context.output && typeof context.output === "object";
72
- const keys = isObj ? Object.keys(context.output).join(",") : typeof context.output;
73
- let errorVal = void 0;
74
- if (isObj && context.output.error !== void 0)
75
- errorVal = context.output.error;
76
- (init_logger(), __toCommonJS(logger_exports)).logger.debug(
77
- ` fail_if: evaluating '${expression}' with output keys=${keys} error=${String(errorVal)}`
78
- );
79
- } catch {
80
- }
81
- const res = this.evaluateExpression(expression, context);
82
- if (res === true) {
83
- try {
84
- addEvent("fail_if.triggered", {
85
- check: checkName,
86
- scope: "check",
87
- name: `${checkName}_fail_if`,
88
- expression,
89
- severity: "error"
90
- });
91
- } catch {
92
- }
93
- try {
94
- const { emitNdjsonSpanWithEvents } = (init_fallback_ndjson(), __toCommonJS(fallback_ndjson_exports));
95
- emitNdjsonSpanWithEvents(
96
- "visor.fail_if",
97
- { check: checkName, scope: "check", name: `${checkName}_fail_if` },
98
- [
99
- {
100
- name: "fail_if.triggered",
101
- attrs: {
102
- check: checkName,
103
- scope: "check",
104
- name: `${checkName}_fail_if`,
105
- expression,
106
- severity: "error"
107
- }
108
- }
109
- ]
110
- );
111
- } catch {
112
- }
113
- }
114
- return res;
115
- } catch (error) {
116
- console.warn(`Failed to evaluate fail_if expression: ${error}`);
117
- return false;
118
- }
119
- }
120
- /**
121
- * Determine if the event is related to pull requests
122
- */
123
- determineIfPullRequest(eventType) {
124
- if (!eventType) return false;
125
- const prEvents = ["pr_opened", "pr_updated", "pr_closed", "pull_request"];
126
- return prEvents.includes(eventType) || eventType.startsWith("pr_");
127
- }
128
- /**
129
- * Determine if the event is related to issues
130
- */
131
- determineIfIssue(eventType) {
132
- if (!eventType) return false;
133
- const issueEvents = ["issue_opened", "issue_comment", "issues"];
134
- return issueEvents.includes(eventType) || eventType.startsWith("issue_");
135
- }
136
- /**
137
- * Evaluate if condition to determine whether a check should run
138
- */
139
- async evaluateIfCondition(checkName, expression, contextData) {
140
- const context = {
141
- // Check metadata
142
- checkName,
143
- // Git context
144
- branch: contextData?.branch || "unknown",
145
- baseBranch: contextData?.baseBranch || "main",
146
- filesChanged: contextData?.filesChanged || [],
147
- filesCount: contextData?.filesChanged?.length || 0,
148
- // GitHub event context
149
- event: {
150
- event_name: contextData?.event || "manual",
151
- action: void 0,
152
- // Would be populated from actual GitHub context
153
- repository: void 0
154
- // Would be populated from actual GitHub context
155
- },
156
- // Environment variables
157
- env: contextData?.environment || {},
158
- // Previous check results (unwrap output field like templates do)
159
- outputs: contextData?.previousResults ? (() => {
160
- const outputs = {};
161
- for (const [checkName2, result] of contextData.previousResults) {
162
- const summary = result;
163
- outputs[checkName2] = summary.output !== void 0 ? summary.output : summary;
164
- }
165
- return outputs;
166
- })() : {},
167
- // Workflow inputs (for workflows)
168
- inputs: contextData?.workflowInputs || {},
169
- // Output property: use provided output for guarantee evaluation, or empty for if conditions
170
- output: contextData?.output !== void 0 && contextData.output !== null && typeof contextData.output === "object" ? contextData.output : { issues: [] },
171
- // Author association (used by permission helpers)
172
- authorAssociation: contextData?.authorAssociation,
173
- // Utility metadata
174
- metadata: {
175
- checkName,
176
- schema: "",
177
- group: "",
178
- criticalIssues: 0,
179
- errorIssues: 0,
180
- warningIssues: 0,
181
- infoIssues: 0,
182
- totalIssues: 0,
183
- hasChanges: (contextData?.filesChanged?.length || 0) > 0,
184
- branch: contextData?.branch || "unknown",
185
- event: contextData?.event || "manual"
186
- },
187
- // Conversation context (for TUI/CLI/Slack)
188
- conversation: contextData?.conversation
189
- };
190
- try {
191
- const res = this.evaluateExpression(expression, context);
192
- try {
193
- if (process.env.VISOR_DEBUG === "true") {
194
- const outputKeys = Object.keys(context.outputs || {});
195
- console.error(
196
- `[if-eval] check=${checkName} expr="${expression}" result=${String(res)} outputKeys=[${outputKeys.join(",")}]`
197
- );
198
- }
199
- } catch {
200
- }
201
- return res;
202
- } catch (error) {
203
- console.warn(`Failed to evaluate if expression for check '${checkName}': ${error}`);
204
- return false;
205
- }
206
- }
207
- /**
208
- * Evaluate all failure conditions for a check result
209
- */
210
- async evaluateConditions(checkName, checkSchema, checkGroup, reviewSummary, globalConditions, checkConditions, previousOutputs, authorAssociation) {
211
- const context = this.buildEvaluationContext(
212
- checkName,
213
- checkSchema,
214
- checkGroup,
215
- reviewSummary,
216
- previousOutputs,
217
- authorAssociation
218
- );
219
- const results = [];
220
- if (globalConditions) {
221
- const globalResults = await this.evaluateConditionSet(globalConditions, context, "global");
222
- results.push(...globalResults);
223
- }
224
- if (checkConditions) {
225
- const checkResults = await this.evaluateConditionSet(checkConditions, context, "check");
226
- const overriddenConditions = new Set(Object.keys(checkConditions));
227
- const filteredResults = results.filter(
228
- (result) => !overriddenConditions.has(result.conditionName)
229
- );
230
- results.length = 0;
231
- results.push(...filteredResults, ...checkResults);
232
- }
233
- return results;
234
- }
235
- /**
236
- * Evaluate a set of failure conditions
237
- */
238
- async evaluateConditionSet(conditions, context, source) {
239
- const results = [];
240
- for (const [conditionName, condition] of Object.entries(conditions)) {
241
- try {
242
- addEvent("fail_if.evaluated", {
243
- check: context.checkName,
244
- scope: source,
245
- name: conditionName,
246
- expression: this.extractExpression(condition)
247
- });
248
- } catch {
249
- }
250
- try {
251
- const { emitNdjsonSpanWithEvents } = (init_fallback_ndjson(), __toCommonJS(fallback_ndjson_exports));
252
- emitNdjsonSpanWithEvents(
253
- "visor.fail_if",
254
- { check: context.checkName || "unknown", scope: source, name: conditionName },
255
- [
256
- {
257
- name: "fail_if.evaluated",
258
- attrs: {
259
- check: context.checkName,
260
- scope: source,
261
- name: conditionName,
262
- expression: this.extractExpression(condition)
263
- }
264
- }
265
- ]
266
- );
267
- } catch {
268
- }
269
- try {
270
- const result = await this.evaluateSingleCondition(conditionName, condition, context);
271
- results.push(result);
272
- if (result.failed) {
273
- try {
274
- addEvent("fail_if.triggered", {
275
- check: context.checkName,
276
- scope: source,
277
- name: conditionName,
278
- expression: result.expression,
279
- severity: result.severity,
280
- halt_execution: result.haltExecution
281
- });
282
- } catch {
283
- }
284
- try {
285
- addFailIfTriggered(context.checkName || "unknown", source);
286
- } catch {
287
- }
288
- }
289
- } catch (error) {
290
- results.push({
291
- conditionName,
292
- failed: false,
293
- expression: this.extractExpression(condition),
294
- severity: "error",
295
- haltExecution: false,
296
- error: `Failed to evaluate ${source} condition '${conditionName}': ${error instanceof Error ? error.message : String(error)}`
297
- });
298
- }
299
- }
300
- return results;
301
- }
302
- /**
303
- * Evaluate a single failure condition
304
- */
305
- async evaluateSingleCondition(conditionName, condition, context) {
306
- const expression = this.extractExpression(condition);
307
- const config = this.extractConditionConfig(condition);
308
- try {
309
- const failed = this.evaluateExpression(expression, context);
310
- return {
311
- conditionName,
312
- failed,
313
- expression,
314
- message: config.message,
315
- severity: config.severity || "error",
316
- haltExecution: config.halt_execution || false
317
- };
318
- } catch (error) {
319
- throw new Error(
320
- `Expression evaluation error: ${error instanceof Error ? error.message : String(error)}`
321
- );
322
- }
323
- }
324
- /**
325
- * Secure expression evaluation using SandboxJS
326
- * Supports the same GitHub Actions-style functions as the previous implementation
327
- */
328
- evaluateExpression(condition, context) {
329
- try {
330
- const normalize = (expr) => {
331
- const trimmed = expr.trim();
332
- if (!/[\n;]/.test(trimmed)) return trimmed;
333
- const parts = trimmed.split(/[\n;]+/).map((s) => s.trim()).filter((s) => s.length > 0 && !s.startsWith("//"));
334
- if (parts.length === 0) return "true";
335
- const lastRaw = parts.pop();
336
- const last = lastRaw.replace(/^return\s+/i, "").trim();
337
- if (parts.length === 0) return last;
338
- return `(${parts.join(", ")}, ${last})`;
339
- };
340
- const contains = (searchString, searchValue) => String(searchString).toLowerCase().includes(String(searchValue).toLowerCase());
341
- const startsWith = (searchString, searchValue) => String(searchString).toLowerCase().startsWith(String(searchValue).toLowerCase());
342
- const endsWith = (searchString, searchValue) => String(searchString).toLowerCase().endsWith(String(searchValue).toLowerCase());
343
- const length = (value) => {
344
- if (typeof value === "string" || Array.isArray(value)) {
345
- return value.length;
346
- }
347
- if (value && typeof value === "object") {
348
- return Object.keys(value).length;
349
- }
350
- return 0;
351
- };
352
- const always = () => true;
353
- const success = () => true;
354
- const failure = () => false;
355
- const log = (...args) => {
356
- console.log("\u{1F50D} Debug:", ...args);
357
- };
358
- const hasIssue = (issues2, field, value) => {
359
- if (!Array.isArray(issues2)) return false;
360
- return issues2.some((issue) => issue[field] === value);
361
- };
362
- const countIssues = (issues2, field, value) => {
363
- if (!Array.isArray(issues2)) return 0;
364
- return issues2.filter((issue) => issue[field] === value).length;
365
- };
366
- const hasFileMatching = (issues2, pattern) => {
367
- if (!Array.isArray(issues2)) return false;
368
- return issues2.some((issue) => issue.file?.includes(pattern));
369
- };
370
- const hasIssueWith = hasIssue;
371
- const hasFileWith = hasFileMatching;
372
- const permissionHelpers = createPermissionHelpers(
373
- context.authorAssociation,
374
- detectLocalMode()
375
- );
376
- const hasMinPermission = permissionHelpers.hasMinPermission;
377
- const isOwner = permissionHelpers.isOwner;
378
- const isMember = permissionHelpers.isMember;
379
- const isCollaborator = permissionHelpers.isCollaborator;
380
- const isContributor = permissionHelpers.isContributor;
381
- const isFirstTimer = permissionHelpers.isFirstTimer;
382
- const output = context.output || {};
383
- let issues = output.issues || [];
384
- if (typeof issues === "string") {
385
- try {
386
- issues = JSON.parse(issues);
387
- } catch {
388
- issues = [];
389
- }
390
- }
391
- if (!Array.isArray(issues)) {
392
- issues = [];
393
- }
394
- const metadata = context.metadata || {
395
- checkName: context.checkName || "",
396
- schema: context.schema || "",
397
- group: context.group || "",
398
- criticalIssues: issues.filter((i) => i.severity === "critical").length,
399
- errorIssues: issues.filter((i) => i.severity === "error").length,
400
- warningIssues: issues.filter((i) => i.severity === "warning").length,
401
- infoIssues: issues.filter((i) => i.severity === "info").length,
402
- totalIssues: issues.length,
403
- hasChanges: context.hasChanges || false
404
- };
405
- const criticalIssues = metadata.criticalIssues;
406
- const errorIssues = metadata.errorIssues;
407
- const totalIssues = metadata.totalIssues;
408
- const warningIssues = metadata.warningIssues;
409
- const infoIssues = metadata.infoIssues;
410
- const checkName = context.checkName || "";
411
- const schema = context.schema || "";
412
- const group = context.group || "";
413
- const branch = context.branch || "unknown";
414
- const baseBranch = context.baseBranch || "main";
415
- const filesChanged = context.filesChanged || [];
416
- const filesCount = context.filesCount || 0;
417
- const event = context.event || "manual";
418
- const env = context.env || {};
419
- const outputs = context.outputs || {};
420
- const inputs = context.inputs || {};
421
- const debugData = context.debug || null;
422
- const conversation = context.conversation || null;
423
- const memoryStore = MemoryStore.getInstance();
424
- const memoryAccessor = {
425
- get: (key, ns) => memoryStore.get(key, ns),
426
- has: (key, ns) => memoryStore.has(key, ns),
427
- list: (ns) => memoryStore.list(ns),
428
- getAll: (ns) => memoryStore.getAll(ns)
429
- };
430
- const scope = {
431
- // Primary context variables
432
- output,
433
- outputs,
434
- debug: debugData,
435
- // Memory accessor for fail_if expressions
436
- memory: memoryAccessor,
437
- // Legacy compatibility variables
438
- issues,
439
- metadata,
440
- criticalIssues,
441
- errorIssues,
442
- totalIssues,
443
- warningIssues,
444
- infoIssues,
445
- // If condition context
446
- checkName,
447
- schema,
448
- group,
449
- branch,
450
- baseBranch,
451
- filesChanged,
452
- filesCount,
453
- event,
454
- env,
455
- inputs,
456
- // Conversation context (TUI/CLI/Slack)
457
- conversation,
458
- // Helper functions
459
- contains,
460
- startsWith,
461
- endsWith,
462
- length,
463
- always,
464
- success,
465
- failure,
466
- log,
467
- hasIssue,
468
- countIssues,
469
- hasFileMatching,
470
- hasIssueWith,
471
- hasFileWith,
472
- // Permission helpers
473
- hasMinPermission,
474
- isOwner,
475
- isMember,
476
- isCollaborator,
477
- isContributor,
478
- isFirstTimer
479
- };
480
- const raw = condition.trim();
481
- if (!this.sandbox) {
482
- this.sandbox = this.createSecureSandbox();
483
- }
484
- let exec;
485
- try {
486
- exec = this.sandbox.compile(`return (${raw});`);
487
- } catch {
488
- const normalizedExpr = normalize(condition);
489
- exec = this.sandbox.compile(`return (${normalizedExpr});`);
490
- }
491
- const result = exec(scope).run();
492
- try {
493
- (init_logger(), __toCommonJS(logger_exports)).logger.debug(` fail_if: result=${Boolean(result)}`);
494
- } catch {
495
- }
496
- return Boolean(result);
497
- } catch (error) {
498
- console.error("\u274C Failed to evaluate expression:", condition, error);
499
- throw error;
500
- }
501
- }
502
- /**
503
- * Extract the expression from a failure condition
504
- */
505
- extractExpression(condition) {
506
- if (typeof condition === "string") {
507
- return condition;
508
- }
509
- return condition.condition;
510
- }
511
- /**
512
- * Extract configuration from a failure condition
513
- */
514
- extractConditionConfig(condition) {
515
- if (typeof condition === "string") {
516
- return {};
517
- }
518
- return {
519
- message: condition.message,
520
- severity: condition.severity,
521
- halt_execution: condition.halt_execution
522
- };
523
- }
524
- /**
525
- * Build the evaluation context for expressions
526
- */
527
- buildEvaluationContext(checkName, checkSchema, checkGroup, reviewSummary, previousOutputs, authorAssociation) {
528
- const { issues, debug } = reviewSummary;
529
- const reviewSummaryWithOutput = reviewSummary;
530
- const {
531
- output: extractedOutput,
532
- // Exclude issues from otherFields since we handle it separately
533
- issues: _issues,
534
- // eslint-disable-line @typescript-eslint/no-unused-vars
535
- ...otherFields
536
- } = reviewSummaryWithOutput;
537
- const aggregatedOutput = {
538
- issues: (issues || []).map((issue) => ({
539
- file: issue.file,
540
- line: issue.line,
541
- endLine: issue.endLine,
542
- ruleId: issue.ruleId,
543
- message: issue.message,
544
- severity: issue.severity,
545
- category: issue.category,
546
- group: issue.group,
547
- schema: issue.schema,
548
- suggestion: issue.suggestion,
549
- replacement: issue.replacement
550
- })),
551
- // Include additional schema-specific data from reviewSummary
552
- ...otherFields
553
- };
554
- if (Array.isArray(extractedOutput)) {
555
- aggregatedOutput.items = extractedOutput;
556
- const anyError = extractedOutput.find(
557
- (it) => it && typeof it === "object" && it.error
558
- );
559
- if (anyError && anyError.error !== void 0) {
560
- aggregatedOutput.error = anyError.error;
561
- }
562
- } else if (extractedOutput && typeof extractedOutput === "object") {
563
- Object.assign(aggregatedOutput, extractedOutput);
564
- }
565
- try {
566
- const raw = reviewSummaryWithOutput.__raw;
567
- if (raw && typeof raw === "object") {
568
- Object.assign(aggregatedOutput, raw);
569
- }
570
- } catch {
571
- }
572
- try {
573
- if (typeof extractedOutput === "string") {
574
- const parsed = this.tryExtractJsonFromEnd(extractedOutput) ?? (() => {
575
- try {
576
- return JSON.parse(extractedOutput);
577
- } catch {
578
- return null;
579
- }
580
- })();
581
- if (parsed !== null) {
582
- if (Array.isArray(parsed)) {
583
- aggregatedOutput.items = parsed;
584
- } else if (typeof parsed === "object") {
585
- Object.assign(aggregatedOutput, parsed);
586
- }
587
- }
588
- const lower = extractedOutput.toLowerCase();
589
- const boolFrom = (key) => {
590
- const reTrue = new RegExp(
591
- `(?:^|[^a-z0-9_])${key}[^a-z0-9_]*[:=][^a-z0-9_]*true(?:[^a-z0-9_]|$)`
592
- );
593
- const reFalse = new RegExp(
594
- `(?:^|[^a-z0-9_])${key}[^a-z0-9_]*[:=][^a-z0-9_]*false(?:[^a-z0-9_]|$)`
595
- );
596
- if (reTrue.test(lower)) return true;
597
- if (reFalse.test(lower)) return false;
598
- return null;
599
- };
600
- const keys = ["error"];
601
- for (const k of keys) {
602
- const v = boolFrom(k);
603
- if (v !== null && aggregatedOutput[k] === void 0) {
604
- aggregatedOutput[k] = v;
605
- }
606
- }
607
- }
608
- } catch {
609
- }
610
- try {
611
- const rsAny = reviewSummaryWithOutput;
612
- const hasStructuredOutput = extractedOutput !== void 0 && extractedOutput !== null;
613
- if (!hasStructuredOutput && typeof rsAny?.content === "string") {
614
- const parsedFromContent = this.tryExtractJsonFromEnd(rsAny.content);
615
- if (parsedFromContent !== null && parsedFromContent !== void 0) {
616
- if (Array.isArray(parsedFromContent)) {
617
- aggregatedOutput.items = parsedFromContent;
618
- } else if (typeof parsedFromContent === "object") {
619
- Object.assign(aggregatedOutput, parsedFromContent);
620
- }
621
- }
622
- }
623
- } catch {
624
- }
625
- const memoryStore = MemoryStore.getInstance();
626
- const context = {
627
- output: aggregatedOutput,
628
- outputs: (() => {
629
- if (!previousOutputs) return {};
630
- const outputs = {};
631
- for (const [checkName2, result] of Object.entries(previousOutputs)) {
632
- const summary = result;
633
- outputs[checkName2] = summary.output !== void 0 ? summary.output : summary;
634
- }
635
- return outputs;
636
- })(),
637
- // Add memory accessor for fail_if expressions
638
- memory: {
639
- get: (key, ns) => memoryStore.get(key, ns),
640
- has: (key, ns) => memoryStore.has(key, ns),
641
- list: (ns) => memoryStore.list(ns),
642
- getAll: (ns) => memoryStore.getAll(ns)
643
- },
644
- // Add basic context info for failure conditions
645
- checkName,
646
- schema: checkSchema,
647
- group: checkGroup,
648
- authorAssociation
649
- };
650
- if (debug) {
651
- context.debug = {
652
- errors: debug.errors || [],
653
- processingTime: debug.processingTime || 0,
654
- provider: debug.provider || "unknown",
655
- model: debug.model || "unknown"
656
- };
657
- }
658
- return context;
659
- }
660
- // Minimal JSON-from-end extractor for fail_if context fallback
661
- tryExtractJsonFromEnd(text) {
662
- try {
663
- const lines = text.split("\n");
664
- for (let i = lines.length - 1; i >= 0; i--) {
665
- const t = lines[i].trim();
666
- if (t.startsWith("{") || t.startsWith("[")) {
667
- const candidate = lines.slice(i).join("\n").trim();
668
- if (candidate.startsWith("{") && candidate.endsWith("}") || candidate.startsWith("[") && candidate.endsWith("]")) {
669
- return JSON.parse(candidate);
670
- }
671
- }
672
- }
673
- } catch {
674
- }
675
- return null;
676
- }
677
- /**
678
- * Check if any failure condition requires halting execution
679
- */
680
- static shouldHaltExecution(results) {
681
- return results.some((result) => result.failed && result.haltExecution);
682
- }
683
- /**
684
- * Get all failed conditions
685
- */
686
- static getFailedConditions(results) {
687
- return results.filter((result) => result.failed);
688
- }
689
- /**
690
- * Group results by severity
691
- */
692
- static groupResultsBySeverity(results) {
693
- return {
694
- // Only 'error' severity now (no backward compatibility needed here as this is internal)
695
- error: results.filter((r) => r.severity === "error"),
696
- warning: results.filter((r) => r.severity === "warning"),
697
- info: results.filter((r) => r.severity === "info")
698
- };
699
- }
700
- /**
701
- * Format results for display
702
- */
703
- static formatResults(results) {
704
- const failed = _FailureConditionEvaluator.getFailedConditions(results);
705
- if (failed.length === 0) {
706
- return "\u2705 All failure conditions passed";
707
- }
708
- const grouped = _FailureConditionEvaluator.groupResultsBySeverity(failed);
709
- const sections = [];
710
- if (grouped.error.length > 0) {
711
- sections.push(`\u274C **Error severity conditions (${grouped.error.length}):**`);
712
- grouped.error.forEach((result) => {
713
- sections.push(` - ${result.conditionName}: ${result.message || result.expression}`);
714
- });
715
- }
716
- if (grouped.warning.length > 0) {
717
- sections.push(`\u26A0\uFE0F **Warning conditions (${grouped.warning.length}):**`);
718
- grouped.warning.forEach((result) => {
719
- sections.push(` - ${result.conditionName}: ${result.message || result.expression}`);
720
- });
721
- }
722
- if (grouped.info.length > 0) {
723
- sections.push(`\u2139\uFE0F **Info conditions (${grouped.info.length}):**`);
724
- grouped.info.forEach((result) => {
725
- sections.push(` - ${result.conditionName}: ${result.message || result.expression}`);
726
- });
727
- }
728
- return sections.join("\n");
729
- }
730
- };
731
- }
732
- });
733
-
734
- export {
735
- FailureConditionEvaluator,
736
- failure_condition_evaluator_exports,
737
- init_failure_condition_evaluator
738
- };
739
- //# sourceMappingURL=chunk-L6ABOJVL.mjs.map