@levnikolaevich/hex-line-mcp 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Hash-verified file editing MCP + token efficiency hook for AI coding agents.
4
4
 
5
+ [![npm](https://img.shields.io/npm/v/@levnikolaevich/hex-line-mcp)](https://www.npmjs.com/package/@levnikolaevich/hex-line-mcp)
6
+ ![License](https://img.shields.io/badge/license-MIT-green)
7
+
5
8
  Every line carries an FNV-1a content hash. Every edit must present those hashes back -- proving the agent is editing what it thinks it's editing. No stale context, no silent corruption.
6
9
 
7
10
  ## Features
@@ -40,13 +43,8 @@ PreToolUse also intercepts simple Bash commands: cat, head, tail, ls, tree, find
40
43
  ### MCP Server
41
44
 
42
45
  ```bash
43
- claude mcp add -s user hex-line -- node path/to/mcp/hex-line-mcp/server.mjs
44
- ```
45
-
46
- Then install dependencies:
47
-
48
- ```bash
49
- cd mcp/hex-line-mcp && npm install
46
+ npm i -g @levnikolaevich/hex-line-mcp
47
+ claude mcp add -s user hex-line -- hex-line-mcp
50
48
  ```
51
49
 
52
50
  ### Hooks
@@ -57,40 +55,47 @@ Automatic setup (run once after MCP install):
57
55
  mcp__hex-line__setup_hooks(agent="claude")
58
56
  ```
59
57
 
60
- Or manual add to `.claude/settings.local.json`:
58
+ Hooks are written to global `~/.claude/settings.json` with absolute path to `hook.mjs` from the global npm install. Manual configuration is not needed.
61
59
 
62
- ```json
63
- {
64
- "hooks": {
65
- "PreToolUse": [{"matcher": "Read|Edit|Write|Grep|Bash", "hooks": [{"type": "command", "command": "node mcp/hex-line-mcp/hook.mjs", "timeout": 5}]}],
66
- "PostToolUse": [{"matcher": "Bash", "hooks": [{"type": "command", "command": "node mcp/hex-line-mcp/hook.mjs", "timeout": 10}]}]
67
- }
68
- }
69
- ```
60
+ ### Output Style
70
61
 
71
- ## Token Efficiency
62
+ Optional: install a persistent Output Style that embeds tool preferences directly in Claude's system prompt. Reduces hook firings by making Claude prefer hex-line tools from the start.
72
63
 
73
- Benchmark v3 (46 code files, 9,134 lines, 18 scenarios):
64
+ ```
65
+ mcp__hex-line__setup_hooks(agent="claude")
66
+ ```
74
67
 
75
- | Scenario | Without | With Hex-line | Savings |
76
- |----------|---------|---------------|--------|
77
- | Read full (any size) | raw | hash-annotated | 6-8% |
78
- | Outline+read (200-500L) | 10,723 ch | 3,347 ch | **69%** |
79
- | Outline+read (500L+) | 39,617 ch | 9,531 ch | **76%** |
80
- | Edit x5 sequential | 2,581 ch | 1,529 ch | **41%** |
81
- | Verify checksums | 8,295 ch | 93 ch | **99%** |
82
- | Directory tree | 80,853 ch | 22,120 ch | **73%** |
83
- | File info | 368 ch | 195 ch | **47%** |
84
- | bulk_replace (5 files) | 2,795 ch | 1,706 ch | **39%** |
85
- | Changes (semantic diff) | 830 ch | 133 ch | **84%** |
86
- | FILE_NOT_FOUND recovery | 2,020 ch | 283 ch | **86%** |
87
- | Hash mismatch recovery | 8,918 ch | 423 ch | **95%** |
88
- | Bash redirects (cat+ls+stat) | 54,658 ch | 25,153 ch | **54%** |
89
- | Grep search | 3,938 ch | 4,091 ch | -4% |
68
+ The `setup_hooks` tool automatically installs the output style to `~/.claude/output-styles/hex-line.md` and activates it if no other style is set. To activate manually: `/config` > Output style > hex-line.
90
69
 
91
- **Average savings: 46%.** Break-even: ~50 lines. Hash overhead: negligible.
70
+ ## Token Efficiency
92
71
 
93
- Reproduce: `node benchmark.mjs` or `node benchmark.mjs --repo /path/to/repo`
72
+ Benchmark v3 (21 code files, 4,801 lines, 18 scenarios):
73
+
74
+ | # | Scenario | Baseline | Hex-line | Savings | Ops | Steps |
75
+ |---|----------|----------|----------|---------|-----|-------|
76
+ | 1 | Read full (<50L) | 1,837 ch | 1,676 ch | 9% | 1→1 | 1→1 |
77
+ | 1 | Read full (50-200L) | 4,976 ch | 4,609 ch | 7% | 1→1 | 1→1 |
78
+ | 1 | Read full (200-500L) | 11,702 ch | 10,796 ch | 8% | 1→1 | 1→1 |
79
+ | 1 | Read full (500L+) | 76,079 ch | 71,578 ch | 6% | 1→1 | 1→1 |
80
+ | 2 | Outline+read (200-500L) | 11,702 ch | 3,620 ch | **69%** | 1→2 | 1→2 |
81
+ | 2 | Outline+read (500L+) | 76,079 ch | 19,020 ch | **75%** | 1→2 | 1→2 |
82
+ | 3 | Grep search | 2,816 ch | 2,926 ch | -4% | 1→1 | 1→1 |
83
+ | 4 | Directory tree | 1,967 ch | 699 ch | **64%** | 1→1 | 1→1 |
84
+ | 5 | File info | 371 ch | 197 ch | **47%** | 1→1 | 1→1 |
85
+ | 6 | Create file (200L) | 113 ch | 85 ch | **25%** | 1→1 | 1→1 |
86
+ | 7 | Edit x5 sequential | 2,581 ch | 1,529 ch | **41%** | 5→5 | 5→5 |
87
+ | 8 | Verify checksums (4 ranges) | 8,295 ch | 93 ch | **99%** | 4→1 | 4→1 |
88
+ | 9 | Multi-file read (2 files) | 3,674 ch | 3,358 ch | 9% | 2→1 | 1→1 |
89
+ | 10 | bulk_replace dry_run (5 files) | 2,795 ch | 1,706 ch | **39%** | 5→1 | 5→1 |
90
+ | 11 | Changes (semantic diff) | 830 ch | 271 ch | **67%** | 1→1 | 1→1 |
91
+ | 12 | FILE_NOT_FOUND recovery | 2,071 ch | 101 ch | **95%** | 3→1 | 3→1 |
92
+ | 13 | Hash mismatch recovery | 8,918 ch | 423 ch | **95%** | 3→1 | 3→1 |
93
+ | 14 | Bash redirects (cat+ls+stat) | 5,602 ch | 4,695 ch | **16%** | 3→3 | 1→1 |
94
+ | 15 | HASH_HINT multi-match recovery | 8,888 ch | 653 ch | **93%** | 3→2 | 3→1 |
95
+
96
+ **Average savings: 45% (flat) / 52% (weighted) | 39→28 ops (28% fewer) | 36→25 steps.**
97
+
98
+ Reproduce: `node benchmark.mjs` or `node benchmark.mjs --with-graph --repo /path/to/repo`
94
99
 
95
100
  ## Tools Reference
96
101
 
@@ -123,6 +128,7 @@ Edit using hash-verified anchors or text replacement. Returns a unified diff.
123
128
  | `path` | string | yes | File to edit |
124
129
  | `edits` | string | yes | JSON array of edit operations (see below) |
125
130
  | `dry_run` | boolean | no | Preview changes without writing |
131
+ | `restore_indent` | boolean | no | Auto-fix indentation to match anchor context (default: false) |
126
132
 
127
133
  Edit operations (JSON array):
128
134
 
@@ -288,6 +294,43 @@ FNV-1a accumulator over all line hashes in the range (little-endian byte feed).
288
294
  | Transport | stdio only | stdio |
289
295
  | Outline | tree-sitter WASM (15+ languages) | tree-sitter WASM |
290
296
 
297
+ ## FAQ
298
+
299
+ <details>
300
+ <summary><b>Does it work without Claude Code?</b></summary>
301
+
302
+ Yes. hex-line-mcp is a standard MCP server (stdio transport). It works with any MCP-compatible client -- Claude Code, Gemini CLI, Codex CLI, or custom integrations. Hooks are Claude/Gemini/Codex-specific.
303
+
304
+ </details>
305
+
306
+ <details>
307
+ <summary><b>What happens if a hash is stale?</b></summary>
308
+
309
+ The edit is rejected with an error showing which lines changed since the last read. The agent must re-read the affected range and retry. This prevents silent overwrites from stale context.
310
+
311
+ </details>
312
+
313
+ <details>
314
+ <summary><b>Is outline available for all file types?</b></summary>
315
+
316
+ Outline works on code files only (15+ languages via tree-sitter WASM). For markdown, JSON, YAML, and text files use `read_file` directly -- these formats don't benefit from structural outline.
317
+
318
+ </details>
319
+
320
+ <details>
321
+ <summary><b>How does the RTK filter reduce tokens?</b></summary>
322
+
323
+ The PostToolUse hook normalizes Bash output (replaces UUIDs, timestamps, IPs with placeholders), deduplicates identical lines, and truncates to first 12 + last 12 lines. Average savings: 45% (flat) / 52% (weighted) across 18 benchmark scenarios.
324
+
325
+ </details>
326
+
327
+ <details>
328
+ <summary><b>Can I disable the built-in tool blocking?</b></summary>
329
+
330
+ Yes. Remove the PreToolUse hook from `.claude/settings.local.json`. The MCP tools will still work, but agents will be free to use built-in Read/Edit/Write/Grep alongside hex-line tools.
331
+
332
+ </details>
333
+
291
334
  ## License
292
335
 
293
336
  MIT