feat(grokbuild): adopt rewind, hunk tracking, fast copy, and edit hardening - #234
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/filestateRewindToreturns a restore plan (only drifted files) and truncates later history.Hunk tracker —
internal/hunktrackerAgentTouchedFilesexposes the agent-vs-user split.Compaction transcript segments —
internal/engine/compact+ wiringsegment_NNNN.md+INDEX.md) with detail levels viaHAWK_COMPACTION_SEGMENT_DETAIL, so full history stays retrievable after compaction.smartCompactBodywrites segments best-effort before dropping turns.Fast CoW tree copy —
internal/fastcopyPrompt-queue combining —
internal/engine/prompt_queue_combine.goDequeueCombined: 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.gofuzzyFindstrategy folding typographic chars (em/en dashes, smart quotes, ellipsis, nbsp) to ASCII before falling back to Levenshtein.Testing
go testsuite,go vet; golangci-lint 0 issues