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

Commit d75acf4

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 706454c commit d75acf4

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
@@ -271,7 +271,7 @@ def _redact_text(
271271
return text_encryptor.obfuscate(text, snippet)
272272

273273
async def process(
274-
self, reques: Any, context: PipelineContext
274+
self, request: Any, context: PipelineContext
275275
) -> PipelineResult:
276276
"""
277277
Process the request to find and protect secrets in all messages.
@@ -498,33 +498,30 @@ async def process_chunk(
498498
)
499499

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

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

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

0 commit comments

Comments
 (0)