Make redactAndTruncate line-boundary aware#19
Conversation
Replace the blunt 70%/20% head/tail char slice with structure-aware truncation (inspired by pi's harness truncate.ts): when the content has line structure (diffs, build/test logs), snap the head back to the last complete line and the tail forward to the next line start, so the critic never reasons over a line cut mid-token. The elision marker now reports both omitted chars and omitted lines. A single very long line with no boundaries falls back to the original hard char slice. Redaction still runs over the full input first, so secrets in the retained head/tail remain masked. Tests (+3): multi-line boundary truncation (all retained lines complete, middle dropped, line count reported), single-long-line char-slice fallback, and secret redaction preserved through truncation.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesNewline-aware truncation in
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/redaction.test.ts (1)
44-79: ⚡ Quick winAdd regression tests for newline-at-boundary edge cases.
Please add explicit cases where truncation encounters newline at exact boundary positions (head newline at boundary start, tail newline at tail end) so whole-line retention is guaranteed in those edge inputs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/redaction.test.ts` around lines 44 - 79, Add new test cases to test/redaction.test.ts that specifically verify newline-at-boundary edge cases for the redactAndTruncate function. Create test cases where truncation encounters newlines at exact boundary positions: one where the head segment ends exactly at a newline character, and another where the tail segment starts exactly at a newline character. These tests should verify that whole lines are retained without mid-line cuts in these edge scenarios, ensuring the function handles boundary alignment correctly when newlines coincide with truncation boundaries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/engine/redaction.ts`:
- Around line 101-107: The boundary guard conditions in the head and tail
trimming logic are excluding valid newline positions. Change the condition at
line 102 from `headNl > 0` to `headNl >= 0` to include the case where the
newline is at position 0 (the start of the head string). Similarly, change the
condition at line 107 from `tailNl < tail.length - 1` to `tailNl <= tail.length
- 1` to include the case where the newline is at the very end of the tail
string. These adjustments ensure that whole-line boundaries are properly
respected even in edge cases.
---
Nitpick comments:
In `@test/redaction.test.ts`:
- Around line 44-79: Add new test cases to test/redaction.test.ts that
specifically verify newline-at-boundary edge cases for the redactAndTruncate
function. Create test cases where truncation encounters newlines at exact
boundary positions: one where the head segment ends exactly at a newline
character, and another where the tail segment starts exactly at a newline
character. These tests should verify that whole lines are retained without
mid-line cuts in these edge scenarios, ensuring the function handles boundary
alignment correctly when newlines coincide with truncation boundaries.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: aa622b82-9417-480d-ac74-93085ab9ce19
📒 Files selected for processing (2)
src/engine/redaction.tstest/redaction.test.ts
headNl > 0 left a partial line when the only newline was at position 0; the tail guard kept a partial leading line when the newline sat at the very end. Use headNl >= 0 and tailNl >= 0 so the whole-line guarantee holds in those edge cases. Addresses CodeRabbit review on PR #19. Co-authored-by: Inzimam Ul Haq <27832433+inhaq@users.noreply.github.com>
This pull request was created by @kiro-agent on behalf of @inhaq 👻
Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro Web
Closes out the final Tier 1 item from the pi-harness deep-dive: structure-aware truncation.
Problem
redactAndTruncate(used for every diff and mechanical-gate log placed in a critic artifact bundle) did a blunt slice: first 70% + last 20% of characters. On the line-structured content the critic actually reasons over — unified diffs, build/test output — this routinely cut mid-line and mid-token, degrading the signal the critic sees.Change
Inspired by pi's harness
truncate.ts, the head is now snapped back to the last complete line within budget and the tail forward to the next line start, so retained content is always whole lines. The elision marker reports both omitted chars and omitted lines. A single very long line with no boundaries falls back to the original hard char slice.Redaction still runs over the full input first, so secrets in the retained head/tail stay masked — unchanged.
Tests (+3)
Existing redaction/truncation tests unchanged and green.
npm run typecheckclean; full suite 176 tests pass.Context
With this merged, Tier 1 and Tier 2 of the deep-dive are complete:
kind:"agent"runner + permission gating (Add native agentic runner (kind: "agent") on pi agent-core + ai #18).Independent of #17/#18 (touches only
redaction.ts); branched offmain.Summary by CodeRabbit