Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 39efa62

Browse files
jhrozekblkt
authored andcommitted
Secrets step simplification (#1074)
* Fix typo * Rely on redacted_secrets_count to detect if this was the first message
1 parent cd5331d commit 39efa62

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/codegate/pipeline/secrets/secrets.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _redact_text(
272272
return text_encryptor.obfuscate(text, snippet)
273273

274274
async def process(
275-
self, reques: Any, context: PipelineContext
275+
self, request: Any, context: PipelineContext
276276
) -> PipelineResult:
277277
"""
278278
Process the request to find and protect secrets in all messages.
@@ -499,33 +499,30 @@ async def process_chunk(
499499
)
500500

501501
# Check if this is the first chunk (delta role will be present, others will not)
502-
for _ in itertools.takewhile(lambda x: x[0] == 1, enumerate(chunk.get_content())):
503-
redacted_count = input_context.metadata["redacted_secrets_count"]
504-
secret_text = "secret" if redacted_count == 1 else "secrets"
505-
# Create notification chunk
506-
if tool_name in ["cline", "kodu"]:
507-
# NOTE: Original code was ensuring that role was
508-
# "assistant" here, we might have to do that as well,
509-
# but I believe it was defensive programming or
510-
# leftover of some refactoring.
511-
notification_chunk = self._create_chunk(
512-
chunk,
513-
f"<thinking>\n🛡️ [CodeGate prevented {redacted_count} {secret_text}]"
514-
f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
515-
f"by redacting them.</thinking>\n\n",
516-
)
517-
else:
518-
notification_chunk = self._create_chunk(
519-
chunk,
520-
f"\n🛡️ [CodeGate prevented {redacted_count} {secret_text}]"
521-
f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
522-
f"by redacting them.\n\n",
523-
)
524-
525-
# Reset the counter
526-
input_context.metadata["redacted_secrets_count"] = 0
502+
redacted_count = input_context.metadata["redacted_secrets_count"]
503+
secret_text = "secret" if redacted_count == 1 else "secrets"
504+
# Create notification chunk
505+
if tool_name in ["cline", "kodu"]:
506+
# NOTE: Original code was ensuring that role was
507+
# "assistant" here, we might have to do that as well,
508+
# but I believe it was defensive programming or
509+
# leftover of some refactoring.
510+
notification_chunk = self._create_chunk(
511+
chunk,
512+
f"<thinking>\n🛡️ [CodeGate prevented {redacted_count} {secret_text}]"
513+
f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
514+
f"by redacting them.</thinking>\n\n",
515+
)
516+
else:
517+
notification_chunk = self._create_chunk(
518+
chunk,
519+
f"\n🛡️ [CodeGate prevented {redacted_count} {secret_text}]"
520+
f"(http://localhost:9090/?search=codegate-secrets) from being leaked "
521+
f"by redacting them.\n\n",
522+
)
527523

528-
# Return both the notification and original chunk
529-
return [notification_chunk, chunk]
524+
# Reset the counter
525+
input_context.metadata["redacted_secrets_count"] = 0
530526

531-
return [chunk]
527+
# Return both the notification and original chunk
528+
return [notification_chunk, chunk]

0 commit comments

Comments
 (0)