From 5ead1499cd46c033a94baa096eda2502248a7c1d Mon Sep 17 00:00:00 2001 From: aecsocket <43144841+aecsocket@users.noreply.github.com> Date: Sun, 2 Aug 2026 15:13:13 +0100 Subject: [PATCH] flatten input context --- .../moderation/technical-review/rules.vue | 4 ++-- .../moderation/tech_review/rules_scan.rs | 20 +++++++++++++++---- packages/delphi-cel-experiment/src/main.rs | 14 ++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/frontend/src/pages/moderation/technical-review/rules.vue b/apps/frontend/src/pages/moderation/technical-review/rules.vue index 47032a24a9..fbc86e94c5 100644 --- a/apps/frontend/src/pages/moderation/technical-review/rules.vue +++ b/apps/frontend/src/pages/moderation/technical-review/rules.vue @@ -64,7 +64,7 @@

- Input (input) + Context

 = {
diff --git a/apps/labrinth/src/routes/internal/moderation/tech_review/rules_scan.rs b/apps/labrinth/src/routes/internal/moderation/tech_review/rules_scan.rs
index 99d573803f..ed39d82193 100644
--- a/apps/labrinth/src/routes/internal/moderation/tech_review/rules_scan.rs
+++ b/apps/labrinth/src/routes/internal/moderation/tech_review/rules_scan.rs
@@ -114,7 +114,7 @@ pub struct DelphiRuleSchemaResponse {
     pub components: BTreeMap,
 }
 
-/// Get the schemas for the CEL input and output values.
+/// Get the schemas for the CEL context and output values.
 #[utoipa::path(
     context_path = "/moderation/tech-review",
     tag = "moderation",
@@ -800,12 +800,24 @@ async fn insert_materialized_effects(
 
 pub(super) fn evaluate_rule(
     program: &cel::Program,
-    input: impl Serialize,
+    input: &RuleInput,
 ) -> Result> {
     let mut context = cel::Context::default();
     context
-        .add_variable("input", input)
-        .wrap_err("failed to build cel input")?;
+        .add_variable("schema_version", input.schema_version)
+        .wrap_err("failed to add `schema_version` to cel context")?;
+    context
+        .add_variable("trace", &input.trace)
+        .wrap_err("failed to add `trace` to cel context")?;
+    context
+        .add_variable("scan", &input.scan)
+        .wrap_err("failed to add `scan` to cel context")?;
+    context
+        .add_variable("artifact", &input.artifact)
+        .wrap_err("failed to add `artifact` to cel context")?;
+    context
+        .add_variable("scope", &input.scope)
+        .wrap_err("failed to add `scope` to cel context")?;
 
     let value = program
         .execute(&context)
diff --git a/packages/delphi-cel-experiment/src/main.rs b/packages/delphi-cel-experiment/src/main.rs
index 7163504bee..8657e94a1c 100644
--- a/packages/delphi-cel-experiment/src/main.rs
+++ b/packages/delphi-cel-experiment/src/main.rs
@@ -4,10 +4,10 @@ use cel::{Context, Program};
 use serde::{Deserialize, Serialize};
 
 const EFFECT_RULE: &str = r#"
-	input.trace.issue_type == "OBFUSCATED_NAMES"
-		&& input.trace.severity == "high"
-		&& "confidence" in input.trace.data
-		&& input.trace.data.confidence >= 0.9
+	trace.issue_type == "OBFUSCATED_NAMES"
+		&& trace.severity == "high"
+		&& "confidence" in trace.data
+		&& trace.data.confidence >= 0.9
 	? {
 		"severity": "low"
 	}
@@ -116,7 +116,11 @@ fn evaluate_rule(
     input: &RuleInput,
 ) -> Result, Box> {
     let mut context = Context::default();
-    context.add_variable("input", input)?;
+    context.add_variable("schema_version", input.schema_version)?;
+    context.add_variable("trace", &input.trace)?;
+    context.add_variable("scan", &input.scan)?;
+    context.add_variable("artifact", &input.artifact)?;
+    context.add_variable("scope", &input.scope)?;
 
     let value = Program::compile(expression)?.execute(&context)?;
     let json = value