# pigibrack

**pi guile bracket extension** for structural Scheme/Guile editing.

## What it provides

Tools:

- `pigibrack_read_module(path)`
- `pigibrack_read_form(path, name?, index?)`
- `pigibrack_read_forms(path, selectors[])`
- `pigibrack_search_forms(path, query, caseSensitive?)`
- `pigibrack_replace_form(path, name?, index?, newSource, includeDiff?)`
- `pigibrack_insert_form(path, anchorName?, anchorIndex?, position, newSource)`
- `pigibrack_delete_form(path, name?, index?)`
- `pigibrack_check_syntax({ path } | { source })`
- `pigibrack_eval_expr(expr, module?)`
- `pigibrack_macro_expand(expr, module?)`

Commands:

- `/pigibrack-status`
- `/pigibrack-repl-reset`

## How to load

As a package resource, this extension entrypoint is:

- `extensions/pigibrack/index.ts`

When developing in this repository, Pi auto-discovers the shim at:

- `.pi/extensions/pigibrack/index.ts`

## Notes

- Structural operations can target top-level forms by **name** or **1-based index** from `pigibrack_read_module` output.
- `pigibrack_read_module` includes per-form line/byte counts and better collapsed summaries for large forms.
- `pigibrack_replace_form` supports `includeDiff`: `none`, `preview` (default, capped to 150 lines), or `full`.
- Syntax checks run through **guile** reader scripts in `guile/`.
- Eval uses a persistent Guile REPL sidecar (`repl_sidecar.scm`) with fallback to one-shot eval if sidecar startup fails.
- File mutations use pi's `withFileMutationQueue()` to avoid race conditions in parallel tool mode.
- Output is truncated to avoid context blowups.

## Current limitations

- Name extraction targets common `define*` patterns; unusual macro forms may be unnamed by the tool.
