trueline-mcp 1.2.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 +190 -0
- package/LICENSE +190 -0
- package/README.md +194 -0
- package/bin/trueline-hook.js +92 -0
- package/bin/trueline-mcp.js +20 -0
- package/configs/claude-code/CLAUDE.md +24 -0
- package/configs/codex/AGENTS.md +27 -0
- package/configs/codex/config.toml +3 -0
- package/configs/gemini-cli/GEMINI.md +23 -0
- package/configs/gemini-cli/hooks.json +9 -0
- package/configs/gemini-cli/mcp.json +8 -0
- package/configs/opencode/AGENTS.md +23 -0
- package/configs/vscode-copilot/copilot-instructions.md +23 -0
- package/configs/vscode-copilot/mcp.json +8 -0
- package/dist/server.js +24005 -0
- package/hooks/core/access.js +69 -0
- package/hooks/core/formatters.js +42 -0
- package/hooks/core/instructions.js +74 -0
- package/hooks/core/platform.js +44 -0
- package/hooks/core/routing.js +92 -0
- package/hooks/gemini-cli/beforetool.js +36 -0
- package/hooks/gemini-cli/session-start.js +10 -0
- package/hooks/hooks.json +36 -0
- package/hooks/pretooluse.js +33 -0
- package/hooks/session-start.js +40 -0
- package/hooks/vscode-copilot/pretooluse.js +35 -0
- package/hooks/vscode-copilot/session-start.js +10 -0
- package/package.json +61 -0
- package/scripts/resolve-binary.cjs +58 -0
- package/src/security.js +214 -0
package/INSTALL.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
trueline-mcp works with any AI coding agent that speaks MCP. Platform-specific
|
|
4
|
+
hooks bring compliance from ~60% (instruction-only) to ~98% (with hooks).
|
|
5
|
+
|
|
6
|
+
## Claude Code
|
|
7
|
+
|
|
8
|
+
Install from the plugin marketplace — no manual configuration needed:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
/plugin marketplace add rjkaes/trueline-mcp
|
|
12
|
+
/plugin install trueline-mcp@trueline-mcp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Hooks (`SessionStart`, `PreToolUse`) are registered automatically via the
|
|
16
|
+
plugin's `hooks.json`.
|
|
17
|
+
|
|
18
|
+
## Gemini CLI
|
|
19
|
+
|
|
20
|
+
### 1. Add the MCP server
|
|
21
|
+
|
|
22
|
+
Add to `~/.gemini/settings.json`:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"mcpServers": {
|
|
27
|
+
"trueline": {
|
|
28
|
+
"command": "npx",
|
|
29
|
+
"args": ["-y", "trueline-mcp"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Add the instruction file
|
|
36
|
+
|
|
37
|
+
Copy `configs/gemini-cli/GEMINI.md` into your project root. This tells the
|
|
38
|
+
agent to prefer trueline tools over built-in `read_file` and `edit_file`.
|
|
39
|
+
|
|
40
|
+
### 3. Add hooks (optional, recommended)
|
|
41
|
+
|
|
42
|
+
Install trueline globally so the hook dispatcher is available:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm i -g trueline-mcp
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then add to `~/.gemini/settings.json`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"hooks": {
|
|
53
|
+
"BeforeTool": [
|
|
54
|
+
{
|
|
55
|
+
"command": "trueline-hook gemini-cli beforetool"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This intercepts `read_file` and `edit_file` calls and redirects them to
|
|
63
|
+
trueline equivalents.
|
|
64
|
+
|
|
65
|
+
## VS Code Copilot
|
|
66
|
+
|
|
67
|
+
### 1. Add the MCP server
|
|
68
|
+
|
|
69
|
+
Add to `.vscode/mcp.json` in your project:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"servers": {
|
|
74
|
+
"trueline": {
|
|
75
|
+
"command": "npx",
|
|
76
|
+
"args": ["-y", "trueline-mcp"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 2. Add the instruction file
|
|
83
|
+
|
|
84
|
+
Copy `configs/vscode-copilot/copilot-instructions.md` into your project's
|
|
85
|
+
`.github/` directory (or wherever your Copilot instructions live).
|
|
86
|
+
|
|
87
|
+
### 3. Add hooks (optional, recommended)
|
|
88
|
+
|
|
89
|
+
Install trueline globally:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
npm i -g trueline-mcp
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Then configure the hook in your VS Code Copilot agent settings to run:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
trueline-hook vscode-copilot pretooluse
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## OpenCode
|
|
102
|
+
|
|
103
|
+
### 1. Add the MCP server
|
|
104
|
+
|
|
105
|
+
Add to your `opencode.json`:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"mcp": {
|
|
110
|
+
"trueline": {
|
|
111
|
+
"command": "npx",
|
|
112
|
+
"args": ["-y", "trueline-mcp"]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 2. Add the instruction file
|
|
119
|
+
|
|
120
|
+
Copy `configs/opencode/AGENTS.md` into your project root. This tells the
|
|
121
|
+
agent to use trueline tools instead of built-in `view` and `edit`.
|
|
122
|
+
|
|
123
|
+
### 3. Hooks
|
|
124
|
+
|
|
125
|
+
OpenCode uses in-process TypeScript plugins rather than JSON stdin/stdout
|
|
126
|
+
hooks. Hook support for OpenCode is not yet implemented — the instruction file
|
|
127
|
+
provides ~60% compliance on its own.
|
|
128
|
+
|
|
129
|
+
## Codex CLI
|
|
130
|
+
|
|
131
|
+
### 1. Add the MCP server
|
|
132
|
+
|
|
133
|
+
Add to `~/.codex/config.toml`:
|
|
134
|
+
|
|
135
|
+
```toml
|
|
136
|
+
[mcp_servers.trueline]
|
|
137
|
+
command = "npx"
|
|
138
|
+
args = ["-y", "trueline-mcp"]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 2. Add the instruction file
|
|
142
|
+
|
|
143
|
+
Copy `configs/codex/AGENTS.md` into your project root. This tells the agent
|
|
144
|
+
to use trueline tools instead of `read_file` and `shell cat`.
|
|
145
|
+
|
|
146
|
+
### 3. Hooks
|
|
147
|
+
|
|
148
|
+
Codex CLI does not support hooks. The instruction file is the only mechanism
|
|
149
|
+
for tool redirection (~60% compliance).
|
|
150
|
+
|
|
151
|
+
## CLI hook dispatcher
|
|
152
|
+
|
|
153
|
+
The `trueline-hook` command is the universal entry point for hook integration:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
trueline-hook <platform> <event>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Platform | Event | Description |
|
|
160
|
+
|----------------|----------------|---------------------------------|
|
|
161
|
+
| gemini-cli | beforetool | Intercept tool calls |
|
|
162
|
+
| gemini-cli | session-start | Inject trueline instructions |
|
|
163
|
+
| vscode-copilot | pretooluse | Intercept tool calls |
|
|
164
|
+
| vscode-copilot | session-start | Inject trueline instructions |
|
|
165
|
+
| claude-code | pretooluse | Intercept tool calls |
|
|
166
|
+
| claude-code | session-start | Inject trueline instructions |
|
|
167
|
+
|
|
168
|
+
Install globally to make it available:
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
npm i -g trueline-mcp
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Path access
|
|
175
|
+
|
|
176
|
+
By default, trueline tools can access files inside the project directory and
|
|
177
|
+
`~/.claude/`. To allow additional directories, set `TRUELINE_ALLOWED_DIRS` to
|
|
178
|
+
a colon-separated list of paths (semicolon-separated on Windows).
|
|
179
|
+
|
|
180
|
+
## Platform detection
|
|
181
|
+
|
|
182
|
+
The hook dispatcher auto-detects the platform from environment variables:
|
|
183
|
+
|
|
184
|
+
| Env var | Platform |
|
|
185
|
+
|------------------------|----------------|
|
|
186
|
+
| `GEMINI_PROJECT_DIR` | gemini-cli |
|
|
187
|
+
| `OPENCODE_PROJECT_DIR` | opencode |
|
|
188
|
+
| `CLAUDE_PROJECT_DIR` | claude-code |
|
|
189
|
+
|
|
190
|
+
Override with `TRUELINE_PLATFORM=<platform>` if auto-detection doesn't work.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Robert James Kaes
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# trueline-mcp
|
|
2
|
+
|
|
3
|
+
[](https://github.com/rjkaes/trueline-mcp/actions/workflows/ci.yml) [](LICENSE) [](https://github.com/rjkaes/trueline-mcp) [](https://github.com/rjkaes/trueline-mcp/commits/main) [](https://www.typescriptlang.org/)
|
|
4
|
+
|
|
5
|
+
A [Model Context Protocol](https://modelcontextprotocol.io/) plugin that cuts
|
|
6
|
+
context usage and catches editing mistakes. Works with Claude Code, Gemini CLI,
|
|
7
|
+
VS Code Copilot, OpenCode, and Codex CLI.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
**Claude Code** (recommended — hooks are automatic):
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
/plugin marketplace add rjkaes/trueline-mcp
|
|
15
|
+
/plugin install trueline-mcp@trueline-mcp
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Other platforms** (Gemini CLI, VS Code Copilot, OpenCode, Codex CLI):
|
|
19
|
+
See [INSTALL.md](INSTALL.md) for platform-specific setup instructions.
|
|
20
|
+
|
|
21
|
+
## The problem
|
|
22
|
+
|
|
23
|
+
AI agents waste tokens in two ways:
|
|
24
|
+
|
|
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
|
+
|
|
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.
|
|
31
|
+
|
|
32
|
+
Both problems compound. A typical editing session reads dozens of files
|
|
33
|
+
and makes multiple edits, burning through context on redundant content.
|
|
34
|
+
|
|
35
|
+
And when things go wrong — stale reads, hallucinated anchors, ambiguous
|
|
36
|
+
matches — the agent silently corrupts your code.
|
|
37
|
+
|
|
38
|
+
## How trueline fixes this
|
|
39
|
+
|
|
40
|
+
trueline replaces Claude Code's built-in `Read` and `Edit` with four
|
|
41
|
+
tools that are smaller, faster, and verified.
|
|
42
|
+
|
|
43
|
+
### 95% fewer input tokens with `trueline_outline`
|
|
44
|
+
|
|
45
|
+
Instead of reading an entire file to understand its structure,
|
|
46
|
+
`trueline_outline` returns a compact AST outline — just the functions,
|
|
47
|
+
classes, types, and declarations with their line ranges:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
1-10: (10 imports)
|
|
51
|
+
12-12: const VERSION = pkg.version;
|
|
52
|
+
14-17: const server = new McpServer({
|
|
53
|
+
25-45: async function resolveAllowedDirs(): Promise<string[]> {
|
|
54
|
+
49-69: server.registerTool(
|
|
55
|
+
71-92: server.registerTool(
|
|
56
|
+
|
|
57
|
+
(12 symbols, 139 source lines)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
12 lines instead of 139. The agent sees the full structure, picks the
|
|
61
|
+
ranges it needs, and reads only those — skipping hundreds of irrelevant
|
|
62
|
+
lines.
|
|
63
|
+
|
|
64
|
+
| File size | Full read | Outline | Savings |
|
|
65
|
+
|-------------|-----------|---------|---------|
|
|
66
|
+
| 140 lines | 140 tokens | 12 tokens | 91% |
|
|
67
|
+
| 245 lines | 245 tokens | 14 tokens | 94% |
|
|
68
|
+
| 504 lines | 504 tokens | 4 tokens | 99% |
|
|
69
|
+
|
|
70
|
+
Every line range in the outline maps directly to a `trueline_read` call.
|
|
71
|
+
|
|
72
|
+
Supports 20+ languages: TypeScript, JavaScript, Python, Go, Rust, Java, C,
|
|
73
|
+
C++, C#, Ruby, PHP, Kotlin, Swift, Scala, Elixir, Lua, Dart, Zig, Bash.
|
|
74
|
+
|
|
75
|
+
### 44% fewer output tokens with `trueline_edit`
|
|
76
|
+
|
|
77
|
+
The built-in `Edit` makes the model echo back the text being replaced:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
// Built-in Edit — model must output the old text
|
|
81
|
+
{
|
|
82
|
+
"old_string": "export function handleRequest(req: Request) {\n ...\n}",
|
|
83
|
+
"new_string": "export function handleRequest(req: Request) {\n ...(new)...\n}"
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`trueline_edit` replaces old text with a compact line-range reference:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
// trueline_edit — just the range and the new content
|
|
91
|
+
{
|
|
92
|
+
"edits": [{
|
|
93
|
+
"checksum": "1-50:a3b1c2d4",
|
|
94
|
+
"range": "12:kf..16:qz",
|
|
95
|
+
"content": "export function handleRequest(req: Request) {\n ...(new)...\n}"
|
|
96
|
+
}]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The model never echoes old text. For a typical 15-line edit:
|
|
101
|
+
|
|
102
|
+
| | Built-in Edit | trueline_edit |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| Old text echoed (output tokens) | ~225 | 0 |
|
|
105
|
+
| New text (output tokens) | ~225 | ~225 |
|
|
106
|
+
| Range/checksum overhead | 0 | ~13 |
|
|
107
|
+
| **Total output tokens** | **~470** | **~263** |
|
|
108
|
+
| **Savings** | | **44%** |
|
|
109
|
+
|
|
110
|
+
Output tokens are the most expensive token class. Cutting them by 44%
|
|
111
|
+
on every edit adds up fast.
|
|
112
|
+
|
|
113
|
+
### Targeted reads save more input tokens
|
|
114
|
+
|
|
115
|
+
`trueline_read` supports multiple disjoint ranges in a single call.
|
|
116
|
+
Instead of re-reading a 2000-line file to edit two distant sections,
|
|
117
|
+
the agent reads only the ranges it needs:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
trueline_read(file_path: "big-file.ts", ranges: [{start: 45, end: 60}, {start: 200, end: 215}])
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
30 lines instead of 2000 — with separate checksums for each range.
|
|
124
|
+
|
|
125
|
+
### Hash verification catches mistakes
|
|
126
|
+
|
|
127
|
+
Every line from `trueline_read` carries a content hash. Every edit must
|
|
128
|
+
present those hashes back, proving the agent is working against the
|
|
129
|
+
file's actual content:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
1:bx|import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
133
|
+
2:dd|
|
|
134
|
+
3:ew|const server = new Server({ name: "trueline-mcp", version: "0.1.0" });
|
|
135
|
+
|
|
136
|
+
checksum: 1-3:8a64a3f7
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
If anything changed since the read — concurrent edits, model
|
|
140
|
+
hallucination, stale context — the edit is rejected before any bytes
|
|
141
|
+
hit disk. Three layers of protection:
|
|
142
|
+
|
|
143
|
+
| Layer | What it catches |
|
|
144
|
+
|-------|----------------|
|
|
145
|
+
| Per-line hash | Changed content at edit boundaries |
|
|
146
|
+
| Range checksum | Any change within the read window |
|
|
147
|
+
| mtime guard | Concurrent modification by another process |
|
|
148
|
+
|
|
149
|
+
No more silent corruption. No more ambiguous string matches.
|
|
150
|
+
|
|
151
|
+
### Batch edits in one call
|
|
152
|
+
|
|
153
|
+
The built-in `Edit` handles one replacement per call. `trueline_edit`
|
|
154
|
+
accepts an array of edits applied atomically, cutting tool-call
|
|
155
|
+
overhead for multi-site changes.
|
|
156
|
+
|
|
157
|
+
## Workflow
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
trueline_outline (navigate)
|
|
161
|
+
→ trueline_read (targeted ranges)
|
|
162
|
+
→ trueline_diff (preview) [optional]
|
|
163
|
+
→ trueline_edit (apply)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
A `SessionStart` hook injects instructions directing the agent to use
|
|
167
|
+
trueline tools. A `PreToolUse` hook blocks the built-in `Edit` tool and
|
|
168
|
+
redirects to the trueline workflow. On other platforms, equivalent hooks
|
|
169
|
+
are available via the `trueline-hook` CLI dispatcher — see
|
|
170
|
+
[INSTALL.md](INSTALL.md).
|
|
171
|
+
|
|
172
|
+
## Path access
|
|
173
|
+
|
|
174
|
+
By default, trueline tools can access files inside the project directory
|
|
175
|
+
and `~/.claude/`. To allow additional directories, set
|
|
176
|
+
`TRUELINE_ALLOWED_DIRS` to a colon-separated list of paths
|
|
177
|
+
(semicolon-separated on Windows).
|
|
178
|
+
|
|
179
|
+
## Development
|
|
180
|
+
|
|
181
|
+
Requires [Bun](https://bun.sh) ≥ 1.3.
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
bun install # install dependencies
|
|
185
|
+
bun test # run tests
|
|
186
|
+
bun run build # build binary for the current platform
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Inspiration
|
|
190
|
+
|
|
191
|
+
Inspired by [The Harness Problem](https://blog.can.ac/2026/02/12/the-harness-problem/)
|
|
192
|
+
by Can Boluk and the
|
|
193
|
+
[vscode-hashline-edit-tool](https://github.com/sethml/vscode-hashline-edit-tool)
|
|
194
|
+
by Seth Livingston.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ==============================================================================
|
|
3
|
+
// CLI Dispatcher: trueline-hook <platform> <event>
|
|
4
|
+
// ==============================================================================
|
|
5
|
+
//
|
|
6
|
+
// Universal entry point for hook integration on any platform.
|
|
7
|
+
//
|
|
8
|
+
// Usage:
|
|
9
|
+
// trueline-hook gemini-cli beforetool # Gemini CLI BeforeTool hook
|
|
10
|
+
// trueline-hook gemini-cli session-start # Gemini CLI session instructions
|
|
11
|
+
// trueline-hook vscode-copilot pretooluse
|
|
12
|
+
// trueline-hook claude-code pretooluse
|
|
13
|
+
//
|
|
14
|
+
// Reads hook event JSON from stdin (for tool-use hooks), writes platform-
|
|
15
|
+
// formatted JSON to stdout.
|
|
16
|
+
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { resolve, dirname } from "node:path";
|
|
19
|
+
|
|
20
|
+
const hooksDir = resolve(dirname(fileURLToPath(import.meta.url)), "..", "hooks");
|
|
21
|
+
|
|
22
|
+
const USAGE = `Usage: trueline-hook <platform> <event>
|
|
23
|
+
|
|
24
|
+
Platforms: claude-code, gemini-cli, vscode-copilot
|
|
25
|
+
Events: pretooluse, beforetool, session-start
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
trueline-hook gemini-cli beforetool
|
|
29
|
+
trueline-hook vscode-copilot pretooluse
|
|
30
|
+
trueline-hook claude-code session-start`;
|
|
31
|
+
|
|
32
|
+
// ==============================================================================
|
|
33
|
+
// Argument Parsing
|
|
34
|
+
// ==============================================================================
|
|
35
|
+
|
|
36
|
+
const platform = process.argv[2];
|
|
37
|
+
const event = process.argv[3];
|
|
38
|
+
|
|
39
|
+
if (!platform || !event || process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
40
|
+
console.error(USAGE);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Normalize event names across platforms.
|
|
45
|
+
// Gemini calls it "beforetool", Claude Code calls it "pretooluse" — both map
|
|
46
|
+
// to the same routing logic.
|
|
47
|
+
const EVENT_ALIASES = {
|
|
48
|
+
beforetool: "pretooluse",
|
|
49
|
+
before_tool: "pretooluse",
|
|
50
|
+
"session-start": "session-start",
|
|
51
|
+
sessionstart: "session-start",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const normalizedEvent = EVENT_ALIASES[event.toLowerCase()] ?? event.toLowerCase();
|
|
55
|
+
|
|
56
|
+
// ==============================================================================
|
|
57
|
+
// Event Dispatch
|
|
58
|
+
// ==============================================================================
|
|
59
|
+
|
|
60
|
+
if (normalizedEvent === "session-start") {
|
|
61
|
+
const { getInstructions } = await import(resolve(hooksDir, "core", "instructions.js"));
|
|
62
|
+
process.stdout.write(getInstructions(platform));
|
|
63
|
+
} else if (normalizedEvent === "pretooluse") {
|
|
64
|
+
const { createAccessChecker } = await import(resolve(hooksDir, "core", "access.js"));
|
|
65
|
+
const { routePreToolUse } = await import(resolve(hooksDir, "core", "routing.js"));
|
|
66
|
+
const { formatDecision } = await import(resolve(hooksDir, "core", "formatters.js"));
|
|
67
|
+
const { getProjectDir } = await import(resolve(hooksDir, "core", "platform.js"));
|
|
68
|
+
|
|
69
|
+
const chunks = [];
|
|
70
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
71
|
+
process.stdin.on("end", async () => {
|
|
72
|
+
let hookEvent;
|
|
73
|
+
try {
|
|
74
|
+
hookEvent = JSON.parse(Buffer.concat(chunks).toString());
|
|
75
|
+
} catch {
|
|
76
|
+
console.error("trueline-hook: failed to parse JSON from stdin");
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const projectDir = getProjectDir(platform);
|
|
81
|
+
const canAccess = await createAccessChecker(projectDir);
|
|
82
|
+
const routing = await routePreToolUse(hookEvent.tool_name, hookEvent.tool_input, canAccess);
|
|
83
|
+
const result = formatDecision(platform, routing);
|
|
84
|
+
|
|
85
|
+
if (result !== null) {
|
|
86
|
+
process.stdout.write(JSON.stringify(result));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
console.error(`trueline-hook: unknown event "${event}". Use pretooluse, beforetool, or session-start.`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// MCP server entry point for npm distribution.
|
|
3
|
+
// Delegates to resolve-binary.cjs which prefers bun > deno > node.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// npx trueline-mcp # via npx
|
|
7
|
+
// trueline-mcp # 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.cjs");
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
execFileSync("node", [script, ...process.argv.slice(2)], { stdio: "inherit" });
|
|
18
|
+
} catch (err) {
|
|
19
|
+
process.exit(err.status ?? 1);
|
|
20
|
+
}
|