Add: per-sub-rule threshold tuning in build-time override file (ADR-0017)#233
Merged
Conversation
…DR-0017)
Widens the ADR-0016 leaf-type invariant from boolean-only to
`boolean | finite number`. Each `encoded-payload-redact` sub-rule may now be
a boolean (existing on/off behaviour) or an object carrying `enabled` plus
named tuning thresholds (`minLength`, `minWords`, `validRatio`,
`minCommonWords`, etc.). Bare boolean at a sub-rule is shorthand for
`{ enabled: <boolean> }`; omitted threshold fields keep their committed
defaults.
The `MIN_*` constants that used to live in `encoded-payload-redact.ts`
relocate to `RULE_OPTION_DEFAULTS` in `rule-metadata.ts` alongside the
sub-rule on/off shape, so a reader of one file sees both the binary and
numeric configuration for each sub-rule. The rule reads its merged
thresholds via `getRuleOptions(...)` at module init and rebuilds the
threshold-derived regex candidates from those values.
Validation: leaf type must match the declared default (boolean → boolean,
number → finite number). No range checks — operators tuning thresholds are
reading the rule source by definition (the sophisticated-user policy
recorded in this ADR).
Stacks on PR #232; both PRs together expose the full per-sub-rule
configuration surface.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The ADR was drafted before the PR was opened, with `PR #TBD` placeholders. Resolve to the actual PR number now that the implementation PR is live. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
boolean | finite number. Eachencoded-payload-redactsub-rule may now be a boolean (existing on/off behaviour from Add: ESLint-style per-rule build-time options (encoded-payload sub-rules) #232) or an object carryingenabledplus named tuning thresholds (minLength,minWords,validRatio,minCommonWords, etc.).{ "enabled": <boolean> }; omitted threshold fields keep their committed defaults.MIN_*constants that used to live inextension/src/rules/encoded-payload-redact.tsrelocate intoRULE_OPTION_DEFAULTSinextension/src/rules/rule-metadata.tsalongside the sub-rule on/off shape, so a reader of one file sees both the binary and numeric configuration for each sub-rule. The rule reads its merged thresholds viagetRuleOptions(...)at module init and rebuilds the threshold-derived regex candidates (BASE64_CANDIDATE,HEX_CANDIDATE,TEXT_CIPHER_CANDIDATE,LEET_CANDIDATE,MORSE_CANDIDATE) from those values.Follow-up to #232.
Example
{ "encoded-payload-redact": { "subRules": { "leetspeak": false, "nato": { "enabled": true, "minWords": 14 }, "morse": { "enabled": true, "validRatio": 0.95, "minCommonWords": 5 } } } }Implementation
extension/src/rules/rule-metadata.ts—RULE_OPTION_DEFAULTScarries{ enabled, ...thresholds }per sub-rule.WidenLeaves<T>widens both boolean and number literal leaves.extension/scripts/load-default-overrides.ts— validator walks the option tree; accepts booleans at boolean positions, finite numbers at number positions, and the bare-boolean shorthand at object positions whoseenableddefault is boolean. Reportsmistyped option values for: <path>for type mismatches.extension/src/lib/rule-options.ts—mergeOptionTreehandles all three leaf types and the shorthand. Malformed-bundle defence still falls back to defaults.extension/src/rules/encoded-payload-redact.ts— file-scopeMIN_*constants removed; threshold references now readSUB_RULES.<sub-rule>.<knob>. Shared helpers (qualifies,tryCipherDecode,alreadyEnglish) take the threshold as an argument so each caller passes its own.docs/src/content/docs/install.md,skills/agent-browser-shield-install/SKILL.md, andextension/data/defaults-overrides.example.jsondemonstrate the threshold form. Spec 0011 FR-2a / FR-4 / NFR-S-2 reworded.Test plan
bun run test— 1954 tests pass (8 new: 1 catalog parity check widening the leaf-type invariant, 7 loader cases for the numeric/object/shorthand shapes, 3 threshold-tuning rule tests).bun run check— biome + eslint clean.pre-commit run— markdown preflight clean (mdformat + markdownlint).bun run build --defaults /tmp/threshold-overrides.jsonlogsApplying 1 build-time default override(s)with mixed boolean/object sub-rules.🤖 Generated with Claude Code