Skip to content

fix(hashline): adopt oh-my-pi improvements — startsWith bug, Map-based mismatch, context display, prepend support #323

@randomm

Description

@randomm

Background

Comparison of our hashline implementation against oh-my-pi's revealed several improvements worth adopting. With hashline as the sole editing mechanism, these are all blocking or high-value.

Changes Required

1. startsWith display bug (Critical — correctness)

File: packages/opencode/src/tool/hashline.ts ~line 117

Mismatch detection uses string startsWith against line numbers, causing false markers. Example: mismatch at line 1 incorrectly marks lines 10–19 because '1' is a prefix of '10', '11', etc.

Fix: Use Map<number, HashMismatch> indexed by line number, check mismatchSet.has(lineNum) — exact integer match.

2. Mismatch error context display (High — agent UX)

Error output shows only mismatched lines with no surrounding context, making it hard for agents to orient themselves.

Fix: Show ±2 context lines around each mismatch with ... gap separators for non-contiguous regions (oh-my-pi: MISMATCH_CONTEXT = 2).

3. Prepend to BOF support (High — blocking gap)

insert_after requires a valid anchor (line ≥ 1), so there is no way to insert lines before line 1 of a file.

Fix: Add insert_before operation (or support insert_after with a virtual BOF anchor) so agents can prepend to the start of any file.

Acceptance Criteria

  • startsWith false-positive bug eliminated — mismatch detection uses exact integer line number matching
  • New regression test: mismatch at line 1 does NOT mark lines 10–19
  • Error output shows ±2 context lines around each mismatch with ... gap separators
  • Agents can insert lines before line 1 of an existing file
  • All existing hashline tests still pass
  • Adversarial review: APPROVED

Quality Gates

  • bun run typecheck — 0 errors
  • bun test — 0 failures

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions