Add context input hardening: trim, allow/deny regex, and onContextOverflow callback#6
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71da240062
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (input.trim !== undefined) { | ||
| const trimMode = input.trim; | ||
| if (input.max_size !== undefined) { | ||
| candidate = trimToMaxSize(candidate, input.max_size, trimMode); |
There was a problem hiding this comment.
Skip truncation when trim is explicitly false
sanitizeContextVariables treats any defined trim value as enabled, so trim: false still flows into trimToMaxSize(...); combined with normalizeTrimMode defaulting non-'start' values to 'end', this silently truncates values even when callers explicitly disabled trimming. In prompts that set max_size with boolean-driven config defaults, this changes output content and can hide the expected oversize warning path.
Useful? React with 👍 / 👎.
|
Duplicate. Merged later pull request. |
Motivation
Description
trim,allow_regex/deny_regex(and legacyregex) fields to the context input schema and normalize them insrc/context.tsandsrc/schema/schema.ts.sanitizeContextVariables()which appliesonContextOverflowcallbacks, trims values tomax_size, and enforces allow/block regex checks, and integrate it intorenderPrompt()and provider input handling (src/index.tsandsrc/providers/prompt-input.ts).src/validation/validate.tsfor malformed regex (POK013),trimwithoutmax_size(POK014), and bothregex+allow_regexconfigured (POK015).README.md,SKILL.md,docs/*.md,website/index.html) to document the new options andonContextOverflowruntime hook.Testing
tests/validation.test.tsandtests/runtime-context-placeholders.test.ts, which exercisePOK013/POK014/POK015, trimming behavior, regex validation, deny rules, and theonContextOverflowcallback, and all tests passed.POK031/POK032style errors.warnings.contextSizepolicy.Codex Task