npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-loc

v0.2.0

Published

pi extension that reports LOC ceilings after edit and write

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\n line 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