@mammothb/pi-read

extension

Smart read for pi — AST outlines for large files via optional tree-sitter WASM grammars, delegating everything else to the built-in read

by — · v0.2.2 · published 4w ago

$ pi install npm:@mammothb/pi-read
downloads/mo
132
stars
—
last push
—
open issues
—

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

No downloads in the last 12 weeks.

README

@mammothb/pi-read

Smart read for pi — returns an AST structural outline for large files, and delegates everything else to the built-in read.

Behavior

InputResult
Small file (≤ threshold)Built-in read (full content, exact output)
Large file, supported + enabled languageAST outline with line ranges
Large file, unsupported/disabled languageBuilt-in read (truncate + "continue" markers)
Image / binaryBuilt-in read (image attachment, MIME handling)
offset/limit drill-downBuilt-in read (raw section)
Missing path / directoryBuilt-in read

The override spreads createReadToolDefinition and only replaces execute, so fallback paths are byte-identical to the built-in read — truncation signaling, image attachments, prompt metadata, and TUI rendering all preserved.

Optional dependencies

tree-sitter is fully optional and WASM-based (no native build):

  • web-tree-sitter — the WASM runtime (Parser.init(), Language.load()).
  • grammar packages — each ships a prebuilt .wasm (e.g. tree-sitter-python/tree-sitter-python.wasm).

When any is missing, large files fall through to the built-in read.

Config

.pi/pi-read.json (project) over ~/.pi/agent/pi-read.json (global):

{
  "enabled": true,
  "thresholdLines": 2000,
  "thresholdBytes": 51200,
  "maxBytes": 10485760,
  "maxDepth": 10,
  "languages": {
    "typescript": true,
    "tsx": true,
    "javascript": true,
    "csharp": true,
    "python": true,
    "rust": true
  }
}

Set a language to false to disable outlining for it (falls back to built-in read).

Supported languages

LanguageExtensionsSymbols
TypeScript / TSX.ts, .mts, .cts, .tsxclass, function, method, interface, enum, type alias, arrow-fn const
JavaScript.js, .mjs, .cjs, .jsxclass, function, method, interface, enum, type alias, arrow-fn const
C#.csclass, interface, method, constructor, struct, enum, namespace
Python.pyclass, function
Rust.rsfunction, struct, enum, trait, impl

Symbols render as a terse outline with line ranges:

server.ts (typescript) — 2502 lines
├── class App (3 children) [1:7]
│   ├── method constructor [2:2]
│   └── method handleRequest [3:5]
└── function main [8:10]

Use read with offset/limit to view a specific section.