pi-loc0.2.0
pi extension that reports LOC ceilings after edit and write
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-loc
In-process pi extension that reports a file's line count after every completed edit or write tool result. It appends one line to the tool result when the file crosses a LOC ceiling, and nothing when it does not.
There is no language server, no MCP server, no child process, and no runtime dependency.
Install
Requires pi 1.4.0 or newer and Node 22.19 or newer.
From npm:
pi install npm:pi-loc
pi list should name pi-loc and point at the installed dist/index.js.
From a local checkout:
(cd modules/pi-loc && npm ci --ignore-scripts && npm run build)
pi install ./modules/pi-loc
As a manual extensions-directory copy:
(cd modules/pi-loc && npm ci --ignore-scripts && npm run build)
mkdir -p ~/.pi/agent/extensions/pi-loc
rm -rf ~/.pi/agent/extensions/pi-loc/dist
cp -R modules/pi-loc/dist ~/.pi/agent/extensions/pi-loc/dist
cp modules/pi-loc/package.json modules/pi-loc/README.md modules/pi-loc/LICENSE modules/pi-loc/CHANGELOG.md ~/.pi/agent/extensions/pi-loc/
The extensions-directory copy loads automatically and does not appear in pi list. Do not keep both installs, or the extension runs twice. After changing the source and rebuilding, refresh the copy:
rm -rf ~/.pi/agent/extensions/pi-loc/dist
cp -R modules/pi-loc/dist ~/.pi/agent/extensions/pi-loc/dist
cp modules/pi-loc/package.json ~/.pi/agent/extensions/pi-loc/package.json
Behavior
| Lines | Appended to the tool result |
|---|---|
| 0-150 | nothing |
| 151-500 | LOC warning: <file> has N lines (target 150); consider splitting. |
| 501+ | LOC error: <file> has N lines (limit 500); split the file. |
The ceilings are strict: 150 is clean, 151 warns, 500 warns, 501 errors.
The line is appended to the existing tool result content, so the model receives it in the next request. It is not a new message and it cannot block the edit. The word error is message severity only: isError is never set, so the edit remains successful.
The line follows every existing content part, and structuredContent is preserved when the tool result carried it.
Status bar
The footer shows the latest checked file as LOC: foo.ts. Only the filename is colored:
| Check | Color |
|---|---|
| clean | green (theme success) |
| warning | yellow/orange (theme warning) |
| error | red (theme error) |
| unreadable | grey (theme dim) |
It is the latest check only: one file, no count, no path. A failed tool result or a non-edit/write tool leaves the previous status. The status is UI-only; it never enters the model context, and print/json modes have no footer.
Counting rule
The count is the number of \n bytes in the file, matching wc -l:
- 200 content lines plus one trailing newline -> 200.
- 600
\r\nline endings -> 600. - 600 lines with no final newline -> 599.
- An empty file -> 0.
For write, the count comes from input.content, so no disk read is needed. For edit, the file is read after the tool completes. If it cannot be read, one LOC check skipped: ... line is appended and the tool result stays successful.
Performance
Measured with npm run bench on this machine (Node 26.10.0, warm cache, readFile plus countNewlines):
| Fixture | Read | Count | Total |
|---|---|---|---|
| 4 KB | 0.11 ms | 0.01 ms | 0.13 ms |
| 1 MB | 0.86 ms | 2.30 ms | 3.16 ms |
| 10 MB | 4.96 ms | 21.82 ms | 26.78 ms |
The benchmark fails if the 4 KB case exceeds 1 ms, the 1 MB case 10 ms, or the 10 MB case 100 ms.
Coverage
Only edit and write tool results are checked. A file rewritten through bash (sed -i, a formatter, cat >) produces no LOC line, and the extension does not try to infer shell mutations. This is deliberate: the rule is a nudge on deliberate file edits, not a repository gate.
Thresholds
The default ceilings live in src/classify.ts as DEFAULT_WARN_LINES (150) and DEFAULT_ERROR_LINES (500). Changing them requires a rebuild and a reinstall. There is no configuration file.
Uninstall
For the npm package:
pi remove npm:pi-loc
For a local checkout:
pi remove ./modules/pi-loc
For the extensions-directory copy:
rm -rf ~/.pi/agent/extensions/pi-loc
Development
npm run typecheck
npm test
npm run bench
npm run pack:audit
npm test builds dist/ first, then runs the boundary, adapter, and entry-point tests.
License
MIT