outline

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 18 Imported by: 0

README

outline

Reduce a source tree to a structural skeleton suitable for feeding to an LLM. Function and method bodies are dropped; signatures, types, comments and imports are kept. Unsupported file types pass through unchanged.

Pure Go, no CGo. Parsing is done by gotreesitter, file selection respects .gitignore via git-pkgs/gitignore. Full API docs are on pkg.go.dev.

import "github.com/git-pkgs/outline"

r, err := outline.Pack(".", outline.Options{Compress: true})
if err != nil {
    return err
}
r.Markdown(os.Stdout)

Or per file:

src, _ := os.ReadFile("main.go")
out, ok := outline.Outline(src, "main.go")

A Go file like

func SayHello(name string) {
    fmt.Printf("Hello, %s!\n", name)
}

becomes

func SayHello(name string) {
⋮----

with the body elided and gaps marked by ⋮----.

API

Outline(src []byte, filename string) (string, bool) compresses one file. The second return is false if the language is not supported.

Imports(src []byte, filename string) ([]Import, bool) extracts module imports, their source-language form, named imports, local aliases, and one-based source lines. A statement containing both default and named imports returns one value for each form.

Refs(src []byte, filename string, receivers []string) ([]Ref, bool) extracts direct member accesses on the supplied receiver identifiers. This lets callers pass the local aliases returned by Imports without collecting unrelated member expressions from the file.

imports, ok := outline.Imports(src, "app.py")
if !ok {
    return
}

refs, _ := outline.Refs(src, "app.py", []string{"flask", "f"})

For both functions, false means the language is unsupported or parsing did not complete, including a parse timeout. A true result with an empty slice means the language is supported but the file contains no matches. Import and reference extraction currently cover Go, Ruby, Python, JavaScript, TypeScript/TSX, Rust, PHP, Elixir, Dart, Swift, Haskell, Perl, Lua, R, Julia, OCaml, Crystal, Nim, Zig, and D.

Pack(root string, opts Options) (*Result, error) walks root, applies .gitignore plus a built-in ignore list (vendored deps, build output, lockfiles), skips binaries and oversized files, and outlines what it can. Options lets you set size and file-count limits, extra ignore patterns, concurrency, and whether to compress.

Result carries []File and a rendered Tree string. Result.Markdown(w) and Result.XML(w) write the packed document.

Tree(paths []string) string renders a box-drawing directory tree from a flat path list.

Supported(filename string) bool reports whether a file's extension maps to a language with an outlining query.

SetParseTimeout(d time.Duration) overrides the per-file parse timeout (default 1s). Must be called before the first Outline or Pack call.

Languages

35 languages have body-stripping queries: Go, Ruby, Python, JavaScript, TypeScript/TSX, Rust, Java, C, C++, C#, PHP, Kotlin, Swift, Scala, Dart, Elixir, Erlang, Haskell, Clojure, Perl, Lua, R, Julia, OCaml, F#, Crystal, Nim, Zig, D, Groovy, HCL/Terraform, Starlark/Bazel, CMake, Bash and Make. gotreesitter ships ~200 grammars so adding a language means writing one .scm query file. cmd/outline-compare -dump <lang> prints the S-expression tree for stdin and is the easiest way to work out what to capture.

Performance

On an M1 Pro, outlining runs at ~6 MB/s per core and reaches ~36 MB/s across all eight via the parser pool. Packing a 600-file repo takes about 34ms; the Markdown render of that result is ~140µs. Almost all the time is in gotreesitter's full-parse path; chunk extraction and rendering barely register.

License

MIT

Documentation

Index

Constants

View Source
const DefaultParseTimeout = time.Second

DefaultParseTimeout caps how long the parser will spend on a single file. Past this point the file is treated as unsupported and falls through as raw content. Pathological inputs (large table-driven test files, generated parser tables) can otherwise dominate runtime.

View Source
const Separator = "⋮----"

Variables

This section is empty.

Functions

func Outline

func Outline(src []byte, filename string) (string, bool)

Outline reduces source to a structural skeleton: declarations, signatures and comments are kept, function bodies are dropped. Returns the outline and true if the file's language is supported, otherwise "", false.

func SetParseTimeout

func SetParseTimeout(d time.Duration)

SetParseTimeout overrides the per-file parse timeout. Must be called before the first Outline or Pack call; later calls are ignored once a language pool has been created. A zero duration disables the timeout.

func Supported

func Supported(filename string) bool

Supported reports whether Outline can handle the given filename.

func Tree

func Tree(paths []string) string

Tree renders a sorted list of slash-separated relative paths as a box-drawing directory tree. Directories are inferred from path segments and listed before files.

Types

type File

type File struct {
	Path     string
	Content  string
	Language string
	Outlined bool
	Symbols  []Symbol // populated when Outlined is true
	Size     int64
	Skipped  string // reason content was omitted, e.g. "binary", "too-large"
}

File is one packed file.

type Import added in v0.2.0

type Import struct {
	Module string
	Kind   ImportKind
	Names  []Name
	Line   int
}

Import is one source import form. A statement containing more than one form, such as a JavaScript default plus named import, produces one Import value for each form. Names is empty for side-effect and wildcard imports, and when a local binding cannot be established from the statement alone, such as an unaliased Go import.

func Imports added in v0.2.0

func Imports(src []byte, filename string) ([]Import, bool)

Imports returns structured imports from one source file. The second return is false when the file's language or syntax tree is unsupported.

type ImportKind added in v0.2.0

type ImportKind string

ImportKind identifies the source-language form of an import.

const (
	// ImportNamed imports one or more named exports.
	ImportNamed ImportKind = "named"
	// ImportDefault imports a default export.
	ImportDefault ImportKind = "default"
	// ImportNamespace imports a module namespace.
	ImportNamespace ImportKind = "namespace"
	// ImportModule binds a module object using the language's module form.
	ImportModule ImportKind = "module"
	// ImportSideEffect loads a module without binding a local name.
	ImportSideEffect ImportKind = "side-effect"
	// ImportWildcard imports every exported name.
	ImportWildcard ImportKind = "wildcard"
)

type Name added in v0.2.0

type Name struct {
	Name  string
	Alias string
}

Name is one named import and its optional local alias. ImportDefault, ImportNamespace, and ImportModule use Alias for a local binding declared by the source syntax.

type Options

type Options struct {
	// MaxFileSize is the per-file byte limit. Files larger than this are
	// listed in the tree but their content is omitted. Zero means 1MB.
	MaxFileSize int64
	// MaxFiles caps the number of files read. Zero means 10000.
	MaxFiles int
	// Compress applies tree-sitter outlining to supported source files.
	// When false, full file contents are kept.
	Compress bool
	// Ignore adds gitignore-syntax patterns on top of .gitignore and the
	// built-in defaults.
	Ignore []string
	// Concurrency is the number of files processed in parallel.
	// Zero means runtime.NumCPU().
	Concurrency int
}

Options configures Pack.

type Ref added in v0.2.0

type Ref struct {
	Receiver string
	Member   string
	Line     int
}

Ref is a direct member access on a caller-supplied receiver.

func Refs added in v0.2.0

func Refs(src []byte, filename string, receivers []string) ([]Ref, bool)

Refs returns direct member accesses on the requested receiver identifiers. The second return is false when the file's language or syntax tree is unsupported.

type Result

type Result struct {
	Root      string
	Files     []File
	Tree      string
	Truncated bool // MaxFiles was hit
}

Result is the output of Pack.

func Pack

func Pack(root string, opts Options) (*Result, error)

Pack walks root, reads text files that survive gitignore and default filtering, optionally outlines them, and returns the collected result.

func (*Result) Markdown

func (r *Result) Markdown(w io.Writer) error

Markdown writes the result as a single markdown document: directory tree followed by one fenced code block per file.

func (*Result) XML

func (r *Result) XML(w io.Writer) error

XML writes the result in repomix-compatible <file path="...">...</file> form.

type Symbol added in v0.2.0

type Symbol struct {
	Name     string
	Kind     string // func, type, class, const, or var
	Line     int    // one-based source line
	Exported bool
}

Symbol is a top-level declaration captured while outlining a file.

Directories

Path Synopsis
cmd
outline-compare command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL