hunkwise
CLAUDE.md87 starsChanged 8 months agoMITView on GitHub
To run a single unit test file: Unit tests use Node's built-in node:test runner. Integration tests use @vscode/test-cli with Mocha in a real VSCode extension host (config: .vscode-test.mjs, workspace: src/test/integration/workspace/). hunkwise is a VSCode extension that provides per-hunk Accept/Discard controls for any external file change (AI tools, scripts, etc.). It requires the proposed editorInsets API and cannot be installed from the marketplace. Insets are reused across refreshes by cache key (afterLine:height) to avoid flicker.
In this repositoryOne other file it gives its agents.
- copilot-review-loopSkill
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
Self-edit suppression: Before programmatically writing a file (discard/accept), fileWatcher.markSelfEdit(filePath) is called so the watcher …
- Very specific: line 49
Deleted file support: If a file is externally deleted, its baseline is preserved and shown in a diff view via the hunkwise-baseline: …
- Very specific: line 52
Git queue serialization: All git write operations (snapshot, removeFile, renameFile, snapshotBatch) go through StateManager.gitQueue to …
- Very specific: line 53
syncIgnoreState: When .gitignore or ignorePatterns change, syncIgnoreState() both adds newly-allowed files and removes newly-ignored files …
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Commands
npm run compile # compile TypeScript to out/
npm run watch # watch mode compilation
npm test # compile test config + run unit tests
npm run test:integration # compile + run VSCode integration testsTo run a single unit test file:
tsc -p ./tsconfig.test.json && node --test out-test/test/diffEngine.test.jsUnit tests use Node's built-in node:test runner. Integration tests use @vscode/test-cli with Mocha in a real VSCode extension host (config: .vscode-test.mjs, workspace: src/test/integration/workspace/).
Architecture
hunkwise is a VSCode extension that provides per-hunk Accept/Discard controls for any external file change (AI tools, scripts, etc.). It requires the proposed editorInsets API and cannot be installed from the marketplace.
Core data flow
FileWatchermonitors all workspace file changes via VSCode'sFileSystemWatcherandonDidChangeTextDocument. It distinguishes user edits (ignored) from external tool writes (triggers review) by checking if the open document buffer matches the disk content.StateManagerholds in-memoryMap<filePath, FileState>whereFileState = { status: 'reviewing' | 'idle', baseline: string }. All mutations are synchronously reflected in memory and asynchronously queued to git via a serialgitQueuepromise chain.HunkwiseGitpersists baselines in a private git repo at.vscode/hunkwise/git/usingGIT_DIR=<hunkwiseDir>/git GIT_WORK_TREE=<workspaceRoot>. The repo always has at most one commit (each mutation does--amend). Settings live in.vscode/hunkwise/settings.json.DiffEngine(diffEngine.ts) computes hunks by callingDiff.diffLines(baseline, current)from thediffnpm package. Hunk IDs are stable strings derived from position (newStart:newLines:oldStart:oldLines).DecorationManagerrenders the diff UI using the proposededitorInsetsAPI (vscode.window.createWebviewTextEditorInset). For each hunk it creates:- A red "deleted lines" inset (HTML webview) above the green block
- A green line decoration on added lines
- An "Accept / Discard" action bar inset below the green block
Insets are reused across refreshes by cache key (
afterLine:height) to avoid flicker.ReviewPanel(reviewPanel.ts) is the sidebar webview panel showing all pending files with batch actions. It communicates with the extension viavscode.postMessage.
Key behaviors
- Self-edit suppression: Before programmatically writing a file (discard/accept),
fileWatcher.markSelfEdit(filePath)is called so the watcher ignores the resulting disk event. - Baseline update on accept hunk: Accepting a single hunk splices the accepted lines into
fileState.baselineso subsequent diffs remain correct. - Baseline as the single source of truth: Whether a file is "new" or "existing" is determined solely by whether it has a baseline in hunkwise git — not by file content, encoding, or binary detection.
baseline === nullmeans new file (not tracked in git);baseline === ''means existing empty file;baseline === <string>means existing file with content. This distinction must be consistent across all code paths (onDiskCreate,load,rebuildState,collectUntrackedFiles). - Deleted file support: If a file is externally deleted, its baseline is preserved and shown in a diff view via the
hunkwise-baseline:content provider. - Persistence across restarts: On
activate(),StateManager.load()checks if.vscode/hunkwise/git/exists (enabled state), then reads all baselines fromgit ls-tree HEAD+git show :path. Files on disk that are not tracked in hunkwise git are detected as new files (baseline: null) viacollectUntrackedFiles(). - Rename/delete handling:
onWillRenameFilesmigrates state+git before the actual rename;onDidRenameFilestriggers UI refresh after. Manual deletes (via VSCode) silently remove the baseline; external deletes produce a deletion hunk. - Git queue serialization: All git write operations (
snapshot,removeFile,renameFile,snapshotBatch) go throughStateManager.gitQueueto prevent concurrent index/commit operations. UsestateManager.snapshotFile()from FileWatcher, never callgit.snapshot()directly. - syncIgnoreState: When
.gitignoreorignorePatternschange,syncIgnoreState()both adds newly-allowed files and removes newly-ignored files from the git repo. It awaits the fullgitQueuebefore returning. --force-removefor git index:git update-index --removeonly removes files missing from disk — use--force-removeto unconditionally remove from the index even if the file exists on disk.
Files that can be tested without VSCode
tsconfig.test.json compiles only diffEngine.ts, hunkwiseGit.ts, gitignoreManager.ts, and the test files — these have no vscode dependency and run in plain Node.
Integration tests
tsconfig.integration.json compiles to out-integration/. Tests run in a real VSCode instance via .vscode-test.mjs config with --enable-proposed-api=molon.hunkwise. Test workspace is at src/test/integration/workspace/. Each test setup() cleans the workspace and teardown() disables hunkwise.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

