Skip to content

feat(grokbuild): adopt rewind, hunk tracking, fast copy, and edit hardening - #234

Merged
Patel230 merged 2 commits into
mainfrom
feat/grok-build-adoptions
Aug 22, 2026
Merged

feat(grokbuild): adopt rewind, hunk tracking, fast copy, and edit hardening#234
Patel230 merged 2 commits into
mainfrom
feat/grok-build-adoptions

Conversation

@Patel230

Copy link
Copy Markdown
Contributor

Summary

Six adoptions from a deep-dive of xai-org/grok-build (SpaceXAI's Rust coding agent), each verified as genuinely missing from hawk. Note: grok-build vendors opencode/codex tool ports, so overlapping areas were excluded (ACP, codebase graph, doom-loop detection, fuzzy line matching already covered).

Changes

Turn-boundary file rewind — internal/filestate

  • Per-prompt rewind points: first-wins before snapshots, last-write-wins after snapshots; RewindTo returns a restore plan (only drifted files) and truncates later history.
  • Durable disk mirror: traversal-safe sanitized session dirs, atomic temp+rename checkpoint writes, rehydration on restart, cap-based eviction.

Hunk tracker — internal/hunktracker

  • LCS line diff producing hunks with content-derived stable IDs; reconciliation preserves identity across re-diffs by ID or positional overlap; agent attribution survives external edits overlapping an agent-authored region; AgentTouchedFiles exposes the agent-vs-user split.

Compaction transcript segments — internal/engine/compact + wiring

  • Verbatim compacted turns persist as markdown segments under the session store (segment_NNNN.md + INDEX.md) with detail levels via HAWK_COMPACTION_SEGMENT_DETAIL, so full history stays retrievable after compaction. smartCompactBody writes segments best-effort before dropping turns.

Fast CoW tree copy — internal/fastcopy

  • APFS clonefile on darwin with byte-copy fallback; parallel copy sharded by parent-directory hash (the grok-build fast-worktree technique).

Prompt-queue combining — internal/engine/prompt_queue_combine.go

  • Pure merge rules + DequeueCombined: merges runs of eligible plain prompts into one turn with combined display metadata; steering/synthetic/bash/image items keep their own turns.

Fuzzy-edit unicode pass — internal/tool/file_edit.go

  • Fourth fuzzyFind strategy folding typographic chars (em/en dashes, smart quotes, ellipsis, nbsp) to ASCII before falling back to Levenshtein.

Testing

  • New suites: filestate (7), fastcopy (5), hunktracker (6), prompt-queue combine (7), transcript segments (7), fuzzy unicode (3)
  • Full pre-push hooks green: boundary guards, external-drift, govulncheck, entire go test suite, go vet; golangci-lint 0 issues

…dening

Six adoptions from a deep-dive of xai-org/grok-build (SpaceXAI's Rust coding
agent), each verified as genuinely missing from hawk:

Turn-boundary file rewind (internal/filestate):
- Per-prompt rewind points with first-wins before-snapshots and last-write
  after-snapshots; RewindTo returns a restore plan (only files whose on-disk
  content drifted) and truncates later history.
- Durable disk mirror under the state dir: sanitized session directory names
  (traversal-safe, hash-suffixed), atomic temp+rename checkpoint writes,
  rehydration on construction, cap-based eviction of oldest checkpoints.

Hunk tracker (internal/hunktracker):
- LCS line diff producing per-region hunks with content-derived IDs;
  reconciliation preserves hunk identity across re-diffs by ID or positional
  overlap, and agent attribution survives external edits overlapping an
  agent-authored region. AgentTouchedFiles exposes the agent-vs-user split.

Compaction transcript segments (internal/engine/compact + wiring):
- Verbatim compacted turns persist as self-contained markdown segments under
  the session store with detail levels (none/minimal/balanced/verbose via
  HAWK_COMPACTION_SEGMENT_DETAIL), a 512KB-per-segment truncation notice,
  and an INDEX.md row per segment, so full history stays retrievable after
  compaction. smartCompactBody writes segments best-effort before dropping
  turns from the live context.

Fast CoW tree copy (internal/fastcopy):
- APFS clonefile on darwin with byte-copy fallback elsewhere; parallel copy
  sharded by parent-directory hash so same-directory files share one worker,
  avoiding create-dir contention — the grok-build xai-fast-worktree technique.

Prompt-queue combining (internal/engine/prompt_queue_combine.go):
- Pure merge rules (front/follower eligibility gates) plus DequeueCombined,
  which merges the run of eligible plain prompts behind the front into one
  turn with combined display metadata; steering/synthetic/bash/image items
  keep their own turns.

Fuzzy-edit unicode pass (internal/tool/file_edit.go):
- Fourth fuzzyFind strategy folding typographic characters (em/en dashes,
  smart quotes, ellipsis, nbsp) to ASCII before matching, recovering exact
  matches for common model output drift before falling to Levenshtein.

Verification: go build ./... clean; new suites green (filestate 7, fastcopy
5, hunktracker 6, combine 7, segments 7, fuzzy 3); tool/engine/compact suites
pass; golangci-lint 0 issues; gofmt clean.
unix.Clonefile only exists in darwin build tags of golang.org/x/sys, so
referencing it from a shared file broke linux/windows builds (caught by CI:
module hygiene, vet, race, deadcode, public module graph). Move the APFS
clone into clone_darwin.go with a !darwin stub in clone_other.go; verified
linux/amd64 and windows/amd64 cross-compiles.
@Patel230
Patel230 merged commit 2439c75 into main Aug 22, 2026
26 checks passed
@Patel230
Patel230 deleted the feat/grok-build-adoptions branch August 22, 2026 19:14
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