Install
Install with PiG
pig install npm:@tduyng/pi-outlineInstall with Pi
pi install npm:@tduyng/pi-outlinePackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/outline.ts"
]
}README
Written by the package's publisher, shown as published in version 0.0.6 (README.md). PiG does not review it.
@tduyng/pi-outline
A map of a source file instead of the file. One call lists every declaration with its line span, so the read that follows fetches one body.
A 1,213-line TypeScript file puts 51 KB into the transcript, and every later turn of the session re-reads it. The depth-1 outline of that file is 47 rows, about 3 KB, and it names the lines worth reading.
How it works
outline(path: "src/goal.ts", depth: 1)
Depth runs from 0 to 5 and defaults to 1. Depth 0 lists top-level declarations, each extra level adds members, and a row with children past the depth ends in [N nested].
The same tool answers three more questions, picked by what path points at and whether name is set:
| Call | Returns |
|---|---|
outline(path: "src/goal.ts", name: "Goal.start") | that declaration body, up to 600 lines, or the close names when it is not declared |
outline(path: "src") | a map of the directory: the declarations other files reference most, ranked like PageRank over cross-file references, in 8 KB |
outline(path: ".", name: "openStore") | where the identifier is defined, and every reference with the declaration it sits in |
The map follows the session. Files this session already read or edited weight the ranking, so the declarations around the current work come first. Test files never count as definers, and a name defined in several packages links to the nearest one by path. Only names visible outside their file count: exported in TypeScript, public in Rust, capitalised in Go, unprefixed in Python.
The symbol search lists files with git ls-files, submodules included, and falls back to a directory walk outside git. A qualified name such as AgentSession.prompt keeps only member accesses (.prompt, ::prompt, ->prompt), so a common method name does not drown in every local variable that shares it.
| Language | Declarations |
|---|---|
| TypeScript, JavaScript | functions, classes, interfaces, type aliases, enums, class methods |
| Python | def, class |
| Go | func, type |
| Rust | fn, struct, enum, trait, impl, mod |
| Lua | function, local function, name = function |
| Nix | top-level attributes and nested attribute sets |
| Shell, fish | functions |
| Markdown | headings |
Headings inside code fences are ignored.
There is no parser. A parser means a dependency, a language server, and a version of both that disagrees with the repository. The outline is built from single-line rules over the text, and spans come from indentation: a declaration runs until the next line at the same or a lower indent, and includes the closing brace that follows its body.
That covers the languages people actually outline, and a miss is visible. A file the rules do not cover gets a line saying so, with grep and a ranged read as the fallback. On the pi repository (2,949 files) a map takes about 370 ms and a symbol search about 160 ms.
With the read guard
pi-subagent's bulk-read guard blocks a read of a file over 350 lines, and its block message names outline first. outline is declared on every request. It used to be deferred and armed by the first large read or search command, and that arming fired in 45 of 74 Claude sessions of ten or more requests, at turn 16 on average. Adding a tool rewrites the tool list at the front of the prompt, so each arming turned about 35k cached tokens into a fresh cache write: $8.63 of misses from 2026-11-07 to 2026-11-16, against about $0.12 for its 200 tokens read from cache on all 4,142 Claude requests in the same window.
Without the guard the tool still works, it just stops being the thing that catches an oversized read.
Install
pi install npm:@tduyng/pi-outline
Limits
- Files over 2 MB are refused, since the map would be bigger than the useful part.
- At most 200 rows, and a row is cut at 120 characters.
- Spans come from indentation, so unusual formatting can miss a declaration, and an object-literal method can show up as a member.
- References are text matches on the identifier, so a name in a string or comment counts. No types, no import resolution.