Skip to content

feat(hashline-edit): add anchor insert modes and strict insert validation#2026

Merged
code-yeongyu merged 2 commits intodevfrom
feat/hashline-edit-anchor-modes
Feb 21, 2026
Merged

feat(hashline-edit): add anchor insert modes and strict insert validation#2026
code-yeongyu merged 2 commits intodevfrom
feat/hashline-edit-anchor-modes

Conversation

@code-yeongyu
Copy link
Owner

@code-yeongyu code-yeongyu commented Feb 21, 2026

Summary

  • Add insert_before and insert_between hashline edit operations with dual-anchor validation.
  • Enforce non-empty insert payloads for all insert operations, align with strict empty-insert error behavior.
  • Improve hash mismatch errors with >>> context output, add edit dedup/noop reporting, and support delete/rename edit modes in tool args.
  • Add streaming hashline formatters and expand tests for new operations and error behavior.

Verification

  • bun test src/tools/hashline-edit/edit-operations.test.ts src/tools/hashline-edit/validation.test.ts src/tools/hashline-edit/hash-computation.test.ts src/tools/hashline-edit/tools.test.ts
  • bun run typecheck
  • bun run build

Summary by cubic

Adds precise anchor insert modes with strict validation and improved mismatch context, plus consistent chunked hashline streaming. Reports dedup/no-op edits and supports file delete/rename.

  • Bug Fixes
    • Fixed anchor-echo stripping for single-line inserts and boundary-only insert_between payloads (empty inserts now error).
    • Aligned streamHashLines* with formatHashLines for empty inputs using a shared chunk formatter for consistent chunking.
    • Added regression tests for the above cases.

Written for commit 7e68690. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 13 files

Confidence score: 3/5

  • src/tools/hashline-edit/edit-text-normalization.ts has concrete logic bugs (boundary-only payload length check and early return) that can leave echo artifacts or duplicate a line, which is user-visible behavior.
  • These are higher-severity issues (6–7/10) with high confidence, so there is some regression risk despite the limited scope.
  • Pay close attention to src/tools/hashline-edit/edit-text-normalization.ts - normalization edge cases around boundary/anchor echoes.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tools/hashline-edit/hash-computation.ts">

<violation number="1" location="src/tools/hashline-edit/hash-computation.ts:75">
P3: Stateful chunking logic (`pushLine` and `flush`) is heavily duplicated between stream formatters.</violation>

<violation number="2" location="src/tools/hashline-edit/hash-computation.ts:131">
P2: `streamHashLinesFromUtf8` handles empty streams inconsistently compared to `formatHashLines`.</violation>

<violation number="3" location="src/tools/hashline-edit/hash-computation.ts:205">
P2: `streamHashLinesFromLines` handles empty iterables inconsistently compared to `formatHashLines`.</violation>
</file>

<file name="src/tools/hashline-edit/edit-text-normalization.ts">

<violation number="1" location="src/tools/hashline-edit/edit-text-normalization.ts:60">
P2: Early return prevents stripping a single-line anchor echo, bypassing empty-insert validation and duplicating the line.</violation>

<violation number="2" location="src/tools/hashline-edit/edit-text-normalization.ts:77">
P1: Incorrect length check prevents stripping of trailing boundary echo when the payload consists only of the boundaries.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…king dedup, empty stream alignment

- Fix single-line anchor-echo stripping to trigger empty-insert validation

- Fix trailing boundary-echo stripping for boundary-only payloads

- Extract shared chunking logic to hashline-chunk-formatter

- Align empty stream/iterable handling with formatHashLines

- Add regression tests for all fixes
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tools/hashline-edit/edit-text-normalization.ts">

<violation number="1" location="src/tools/hashline-edit/edit-text-normalization.ts:60">
P1: `stripInsertBeforeEcho` still uses `newLines.length <= 1` and was missed in this strict validation update. An `insert_before` payload containing only an echo line will duplicate the anchor instead of erroring out.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@@ -0,0 +1,109 @@
const HASHLINE_PREFIX_RE = /^\s*(?:>>>|>>)?\s*\d+#[A-Z]{2}:/
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: stripInsertBeforeEcho still uses newLines.length <= 1 and was missed in this strict validation update. An insert_before payload containing only an echo line will duplicate the anchor instead of erroring out.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tools/hashline-edit/edit-text-normalization.ts, line 60:

<comment>`stripInsertBeforeEcho` still uses `newLines.length <= 1` and was missed in this strict validation update. An `insert_before` payload containing only an echo line will duplicate the anchor instead of erroring out.</comment>

<file context>
@@ -57,7 +57,7 @@ export function restoreLeadingIndent(templateLine: string, line: string): string
 
 export function stripInsertAnchorEcho(anchorLine: string, newLines: string[]): string[] {
-  if (newLines.length <= 1) return newLines
+  if (newLines.length === 0) return newLines
   if (equalsIgnoringWhitespace(newLines[0], anchorLine)) {
     return newLines.slice(1)
</file context>
Fix with Cubic

@code-yeongyu code-yeongyu merged commit 07ec7be into dev Feb 21, 2026
8 checks passed
@code-yeongyu code-yeongyu deleted the feat/hashline-edit-anchor-modes branch February 21, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant