auto-promote: multi-line command summaries leak into raw TOML #11
Labels
No labels
enhancement
observability
research
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jbr870/claude-permit#11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The auto-promote writer generates per-rule TOML comments like:
When the summary contains a newline (multi-line commands, heredocs, chained shell), the continuation lines are written as raw TOML instead of being prefixed with
#. The parser then fails:Impact
toml::from_strfails on the first parse error, so all auto-promoted rules after the first broken block are silently dropped. The fail-open design keeps claude-permit working, but users lose their learned rules with no visible indication.Found live in
~/.claude/claude-permit/auto-rules.toml— 184 leaked lines across many auto-promoted blocks.Affected code
src/auto_promote.rs— theformat_summary/ comment-writer path writes summaries as-is without newline escaping.Proposed fix
In the comment writer, replace any newline in the summary with a space (or split into multiple
#-prefixed continuation lines). Round-trip throughparse_auto_rules_with_metadatashould be exercised by a regression test using a multi-line summary.Repair for existing damage
A one-time script to prefix every non-TOML, non-blank, non-comment line with
#would restore parsing of the existing file. Alternative: delete the affected auto-promoted blocks (cleaner but loses the rules).Discovery context
Hit while running the new
report --htmlsubcommand (feature 10-report-html). The report itself rendered fine (fail-open), but the validate and report paths both log the parse error on every invocation.Fixed in ff23494 (merged to main).
Root cause:
format_rule_tomlrenderedsummaryandcommandverbatim, so any embedded newlines broke out of the#comment line into raw TOML.Fix: Strip
\r/\nfrom both fields before rendering, and switch truncation from byte-indexing (&s[..60]) to char-safechars().take(60)to avoid multibyte panics.Regression coverage:
test_format_rule_toml_multiline_command_stays_one_comment_line— round-trips a multi-line Bash command throughtoml::from_strand asserts every pre-[[allow]]non-blank line starts with#.test_format_rule_toml_multibyte_command_truncation— 80-char multibyte command, asserts the block still parses.Live binary at
~/.claude/bin/claude-permitnow contains the fix.