trueline-mcp 2.6.2 → 2.7.0

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/INSTALL.md CHANGED
@@ -148,6 +148,44 @@ to use trueline tools instead of `read_file` and `shell cat`.
148
148
  Codex CLI does not support hooks. The instruction file is the only mechanism
149
149
  for tool redirection (~60% compliance).
150
150
 
151
+ ## CLI (no MCP)
152
+
153
+ For agents that can run shell commands but don't support MCP, trueline
154
+ provides a standalone CLI with the same hash-verified operations.
155
+
156
+ ### 1. Install
157
+
158
+ ```sh
159
+ npm i -g trueline-mcp
160
+ ```
161
+
162
+ This puts the `trueline` command on your PATH.
163
+
164
+ ### 2. Verify
165
+
166
+ ```sh
167
+ trueline --help
168
+ ```
169
+
170
+ ### 3. Configure your agent
171
+
172
+ Add the contents of `configs/cli/instructions.md` to your agent's system
173
+ prompt or instruction file. This teaches the agent the trueline workflow:
174
+ outline, read targeted ranges, search for edit targets, edit with checksums.
175
+
176
+ The key rules for the agent:
177
+
178
+ - Use `trueline read` instead of `cat`
179
+ - Use `trueline edit` instead of `sed` or manual file writes
180
+ - Use `trueline outline` to navigate before reading full files
181
+ - Use `trueline search` to find lines with checksums before editing
182
+
183
+ ### 4. Path access
184
+
185
+ By default the CLI allows access to the current working directory. Set
186
+ `TRUELINE_ALLOWED_DIRS` to a colon-separated list of additional paths,
187
+ or set `CLAUDE_PROJECT_DIR` to override the project root.
188
+
151
189
  ## CLI hook dispatcher
152
190
 
153
191
  The `trueline-hook` command is the universal entry point for hook integration:
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![CI](https://github.com/rjkaes/trueline-mcp/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rjkaes/trueline-mcp/actions/workflows/ci.yml)
4
4
 
5
- A [Model Context Protocol](https://modelcontextprotocol.io/) plugin that reduces
6
- context usage on large files and catches editing mistakes. Works with Claude
7
- Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI.
5
+ An [MCP](https://modelcontextprotocol.io/) plugin that gives AI coding agents
6
+ hash-verified file editing and targeted reads. Works with Claude Code, Gemini
7
+ CLI, VS Code Copilot, OpenCode, and Codex CLI.
8
8
 
9
9
  ## Installation
10
10
 
@@ -16,38 +16,35 @@ Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI.
16
16
  ```
17
17
 
18
18
  **Other platforms** (Gemini CLI, VS Code Copilot, OpenCode, Codex CLI):
19
- See [INSTALL.md](INSTALL.md) for platform-specific setup instructions.
19
+ See [INSTALL.md](INSTALL.md) for platform-specific setup.
20
20
 
21
- ## The problem
21
+ **CLI (no MCP):** For agents that use shell commands instead of MCP, install
22
+ globally with `npm i -g trueline-mcp` and add `configs/cli/instructions.md`
23
+ to your agent's system prompt. See [INSTALL.md](INSTALL.md#cli-no-mcp).
22
24
 
23
- AI agents waste tokens on large files in two ways:
25
+ ## Why
24
26
 
25
- 1. **Reading too much.** To find a function in a 500-line file, the agent
26
- reads all 500 lines, most of which it doesn't need.
27
+ AI coding agents read entire files to find one function, then echo back
28
+ everything they're replacing. Both waste context on content the agent already
29
+ knows or doesn't need. That context costs money, eats into the conversation
30
+ window, and limits how much real work fits in a session.
27
31
 
28
- 2. **Echoing on edit.** The built-in `Edit` tool requires the agent to
29
- output the old text being replaced (`old_string`) plus the new text.
30
- The old text is pure overhead.
32
+ Worse, the built-in edit tools match by string content. If the agent
33
+ hallucinates a line, works from stale context, or hits an ambiguous match,
34
+ your code gets silently corrupted.
31
35
 
32
- Both problems compound on larger files. A typical editing session reads
33
- dozens of files and makes multiple edits, burning through context on
34
- redundant content.
36
+ trueline fixes both problems: it reads less, writes less, and rejects every
37
+ edit that doesn't match the file's actual content.
35
38
 
36
- And when things go wrong (stale reads, hallucinated anchors, ambiguous
37
- matches) the agent silently corrupts your code.
39
+ ## How it works
38
40
 
39
- ## How trueline fixes this
41
+ trueline provides six MCP tools organized around three workflows.
40
42
 
41
- trueline provides six MCP tools that are smaller, faster, and verified.
42
- For small files, the built-in tools work fine. For larger files, the
43
- savings from targeted reads and compact edits outweigh the token
44
- overhead of crossing the MCP protocol barrier.
43
+ ### Explore: understand before you read
45
44
 
46
- ### Read less: `trueline_outline` + `trueline_read`
47
-
48
- Instead of reading an entire file, the agent starts with
49
- `trueline_outline`, a compact AST outline showing just the functions,
50
- classes, and declarations with their line ranges:
45
+ `trueline_outline` returns an AST-based structural outline of any file:
46
+ functions, classes, declarations, and their line ranges. For a typical
47
+ source file, that's 10-20 lines instead of hundreds.
51
48
 
52
49
  ```
53
50
  1-10: (10 imports)
@@ -60,64 +57,78 @@ classes, and declarations with their line ranges:
60
57
  (12 symbols, 139 source lines)
61
58
  ```
62
59
 
63
- 12 lines instead of 139. The agent sees the full structure, then reads
64
- only the ranges it needs, skipping hundreds of irrelevant lines.
60
+ The agent sees the full structure, then uses `trueline_read` to fetch only
61
+ the ranges it needs. A 500-line file where the agent needs one 20-line
62
+ function? It reads 20 lines, not 500.
65
63
 
66
- The savings scale with file size. MCP tool calls have per-call framing
67
- overhead, so the break-even point is roughly 15KB; below that, a plain
68
- `Read` is cheaper. Above it, the gap widens quickly:
64
+ `trueline_search` finds lines by literal string or regex and returns them
65
+ with edit-ready checksums, no outline or read step needed. For targeted
66
+ edits where the agent knows what it's looking for, this is the fastest path.
69
67
 
70
- | File size | Full read | Outline | Savings |
71
- |-------------|-----------|---------|--------|
72
- | 140 lines | 140 tokens | 12 tokens | 91% |
73
- | 245 lines | 245 tokens | 14 tokens | 94% |
74
- | 504 lines | 504 tokens | 4 tokens | 99% |
68
+ ### Edit: compact and verified
75
69
 
76
- `trueline_read` supports multiple disjoint ranges in a single call.
70
+ The built-in edit tool requires the agent to echo back the old text being
71
+ replaced. `trueline_edit` replaces that with a compact line-range reference
72
+ and a content hash. The agent outputs only the new content.
77
73
 
78
- ### Find and fix: `trueline_search`
74
+ The savings scale with the size of the replaced block. A one-line change
75
+ saves little; replacing 30 lines of old code saves the agent from
76
+ outputting all 30 of those lines again.
79
77
 
80
- When the agent knows what it's looking for, `trueline_search` finds
81
- lines by regex and returns them with enough context to edit immediately,
82
- no outline or read step needed.
78
+ Multiple edits can be batched in a single call and applied atomically.
83
79
 
84
- A search-based workflow uses **~127 tokens** vs **~2000** for
85
- outline+read, a 93% reduction for targeted lookups.
80
+ ### Review: semantic diffs
86
81
 
87
- ### Write less: `trueline_edit`
82
+ `trueline_diff` provides an AST-based summary of structural changes
83
+ compared to a git ref. Instead of raw line diffs, it reports
84
+ added/removed/renamed symbols, signature changes, and logic modifications
85
+ with inline mini-diffs. Pass `["*"]` to diff all changed files at once.
88
86
 
89
- The built-in `Edit` makes the model echo back the old text being
90
- replaced. `trueline_edit` replaces that with a compact line-range
91
- reference: the model only outputs the new content.
87
+ ### Hash verification: no silent corruption
92
88
 
93
- For a typical 15-line edit, that's **44% fewer output tokens**. Output
94
- tokens are the most expensive token class, so this adds up fast.
89
+ Every line from `trueline_read` and `trueline_search` carries a content
90
+ hash. Every edit must present those hashes back, proving the agent is
91
+ editing what it thinks it's editing.
95
92
 
96
- Multiple edits can be batched in a single call and applied atomically.
93
+ If the file changed since the agent read it (concurrent edits, a build
94
+ step, another tool), the edit is rejected. If the agent hallucinates
95
+ content that doesn't match what's on disk, the edit is rejected. If the
96
+ agent targets the wrong lines, the edit is rejected. Nothing hits disk
97
+ unless the hashes match.
98
+
99
+ `trueline_verify` checks whether held checksums are still valid without
100
+ re-reading the file. When nothing changed (the common case), the response
101
+ is a single line.
102
+
103
+ ## How agents actually use it
97
104
 
98
- ### Review smarter: `trueline_diff`
105
+ trueline doesn't just register tools and hope the agent picks them up.
106
+ On platforms that support hooks, it actively intercepts the agent's
107
+ workflow:
99
108
 
100
- `trueline_diff` provides a semantic, AST-based summary of structural
101
- changes compared to a git ref. Instead of raw line diffs, it reports
102
- added/removed/renamed symbols, signature changes, and logic
103
- modifications with inline mini-diffs for small changes.
109
+ - **SessionStart** injects instructions telling the agent how and when
110
+ to use each trueline tool, calibrated per platform.
111
+ - **PreToolUse** intercepts calls to the built-in edit tool and blocks
112
+ them, forcing the agent through hash-verified edits instead.
104
113
 
105
- Pass `["*"]` to diff all changed files at once. The output is compact
106
- enough to review an entire feature branch in a single tool call.
114
+ With hooks, agent compliance is ~98%. Without hooks (instruction-only
115
+ platforms like OpenCode and Codex CLI), compliance is ~60%. The
116
+ instruction file still helps; hooks make it reliable.
107
117
 
108
- ### Never corrupt: hash verification
118
+ The instructions are not one-size-fits-all. They reference each
119
+ platform's native tool names (`Read`/`Edit` on Claude Code,
120
+ `read_file`/`edit_file` on Gemini CLI, `view`/`edit` on OpenCode) and
121
+ adapt advice accordingly.
109
122
 
110
- Every line from `trueline_read` carries a content hash. Every edit must
111
- present those hashes back, proving the agent is working against the
112
- file's actual content. If anything changed (concurrent edits, model
113
- hallucination, stale context) the edit is rejected before any bytes hit
114
- disk.
123
+ ## Where it helps most
115
124
 
116
- No more silent corruption. No more ambiguous string matches.
125
+ trueline's overhead is an MCP round-trip per tool call. For small files
126
+ (under ~200 lines), the built-in tools are perfectly fine, and the
127
+ injected instructions tell the agent so.
117
128
 
118
- `trueline_verify` lets the agent check whether held checksums are still
119
- valid without re-reading the file. When the file hasn't changed (the
120
- common case), the response is a single line — near-zero tokens.
129
+ The payoff comes on larger files and multi-file editing sessions, where
130
+ targeted reads and compact edits avoid sending hundreds or thousands of
131
+ redundant lines through the context window.
121
132
 
122
133
  ## Design
123
134
 
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ // CLI entry point for npm distribution.
3
+ // Delegates to resolve-binary-cli.cjs which prefers bun > deno > node.
4
+ //
5
+ // Usage:
6
+ // npx trueline read src/foo.ts
7
+ // trueline read src/foo.ts # after npm i -g trueline-mcp
8
+
9
+ import { execFileSync } from "node:child_process";
10
+ import { resolve, dirname } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
+ const script = resolve(__dirname, "..", "scripts", "resolve-binary-cli.cjs");
15
+
16
+ try {
17
+ execFileSync("node", [script, ...process.argv.slice(2)], { stdio: "inherit" });
18
+ } catch (err) {
19
+ process.exit(err.status ?? 1);
20
+ }
@@ -0,0 +1,74 @@
1
+ # trueline CLI
2
+
3
+ trueline provides hash-verified file operations via the command line.
4
+ Use trueline commands instead of cat, grep, and sed for reading and
5
+ editing files. Edits are verified against checksums to prevent stale
6
+ overwrites.
7
+
8
+ ## Commands
9
+
10
+ - **trueline read** — Read a file with per-line hashes and range checksums.
11
+ - **trueline edit** — Apply hash-verified edits. Each edit needs a checksum from a prior read or search.
12
+ - **trueline outline** — Compact structural outline (functions, classes, types with line ranges).
13
+ - **trueline search** — Search a file for a string or regex. Returns matching lines with hashes, ready for editing.
14
+ - **trueline diff** — Semantic AST-based diff vs a git ref.
15
+ - **trueline verify** — Check if held checksums are still valid.
16
+
17
+ Run `trueline --help` or `trueline <command> --help` for full usage.
18
+
19
+ ## Workflow
20
+
21
+ 1. **Navigate:** `trueline outline src/foo.ts` to see structure without reading the full file.
22
+ 2. **Read targeted ranges:** `trueline read src/foo.ts --ranges 10-25` to read only what you need.
23
+ 3. **Find edit targets:** `trueline search src/foo.ts "oldFunction"` to get lines with checksums.
24
+ 4. **Edit with verification:** `trueline edit src/foo.ts --edits '[{"checksum":"...","range":"...","content":"..."}]'`
25
+ 5. **Preview first (optional):** Add `--dry-run` to see a unified diff without writing.
26
+
27
+ ## Rules
28
+
29
+ - Never use `cat` to read files; use `trueline read` instead.
30
+ - Never use `sed` or manual file writes; use `trueline edit` instead.
31
+ - Use `trueline outline` for navigation; only read specific ranges you need.
32
+ - Always pass the checksum from `trueline read` or `trueline search` when editing.
33
+ - If an edit fails with a checksum mismatch, re-read the file to get fresh checksums.
34
+
35
+ ## Edit format
36
+
37
+ The `--edits` flag takes a JSON array. Each edit object has:
38
+
39
+ - `checksum` — Range checksum from a prior read (format: `startLine-endLine:hexhash`)
40
+ - `range` — Target lines, in one of three formats:
41
+ - `startLine:lineHash-endLine:lineHash` — replace lines
42
+ - `+lineNum:hash` — insert after line
43
+ - `+0:` — insert at beginning of file
44
+ - `content` — New content for those lines
45
+
46
+ Example:
47
+
48
+ ```sh
49
+ trueline edit src/foo.ts --edits '[{
50
+ "checksum": "10-15:a1b2c3d4",
51
+ "range": "10:ab-15:cd",
52
+ "content": "function newName() {\n return true;\n}"
53
+ }]'
54
+ ```
55
+
56
+ To insert after a line (without replacing), use `+lineNum:hash` as the range:
57
+
58
+ ```sh
59
+ trueline edit src/foo.ts --edits '[{
60
+ "checksum": "10-15:a1b2c3d4",
61
+ "range": "+12:ef",
62
+ "content": "// inserted after line 12"
63
+ }]'
64
+ ```
65
+
66
+ To insert at the beginning of a file, use `+0:` as the range:
67
+
68
+ ```sh
69
+ trueline edit src/foo.ts --edits '[{
70
+ "checksum": "1-1:a1b2c3d4",
71
+ "range": "+0:",
72
+ "content": "// Copyright 2025 Acme Corp\n// SPDX-License-Identifier: MIT\n"
73
+ }]'
74
+ ```