@pi-kode/file-tools0.1.0
Standalone pi extension: file-tools and checkpoints
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
@pi-kode/file-tools
Standalone pi extension package providing file, search, notebook, shell, and checkpoint/rewind tools.
Capabilities
This package registers the file-tools extension (./index.ts) with pi and requires no other @pi-kode packages.
Registered Tools
| Tool | Execution Mode | Summary |
|---|---|---|
Read |
parallel |
Reads UTF-8 text files with 1-based line numbers, images visually, notebooks as JSON, and PDFs via pdftotext. |
Write |
sequential |
Atomically writes UTF-8 text files with stale-read protection and rewind checkpoints. |
Edit |
sequential |
Performs exact string replacements (old_string -> new_string, optional replace_all) with stale-read protection and rewind checkpoints. |
Glob |
parallel |
Finds files using ripgrep (rg --files) and glob matching. |
Grep |
parallel |
Searches file contents using ripgrep (rg) regular expressions. |
NotebookEdit |
sequential |
Edits .ipynb notebook cells (replace, insert, delete) by cell ID with stale-read protection and rewind checkpoints. |
Bash |
sequential |
Executes foreground /bin/bash -c commands in the session working directory with bounded output and artifact logging. |
Tool Details
Read- Requires an absolute
file_path. - Text files: Up to 4 MB; defaults to
offset: 1andlimit: 2000lines; truncates lines longer than 2000 characters and caps returned output at 64 KB. Rejects binary files containing NUL bytes. Records a SHA-256 content hash so subsequent edits can detect external changes. - Images: Supports
.png,.jpg,.jpeg,.gif, and.webp(up to 10 MB) and returns them as base64 image content. - PDFs: Extracts text using
pdftotext -layout(if installed onPATH), supporting apagesrange of 1–20 pages (default1-20). - Notebooks: Reads
.ipynbfiles as UTF-8 JSON and tracks their hash forNotebookEdit.
- Requires an absolute
Write- Requires an absolute
file_pathandcontent. - Creates new files or overwrites existing files atomically (preserving existing file mode, defaulting to
0o600for new files). - Refuses to overwrite an existing file unless it was read in the current session and remains unchanged since that read.
- Requires an absolute
Edit- Requires an absolute
file_path,old_string,new_string(must differ), and optionalreplace_all. - Refuses to edit files that have not been read or have changed on disk since the last
Read. - Rejects ambiguous matches when
old_stringappears multiple times unlessreplace_all: trueis provided.
- Requires an absolute
Glob- Matches files under
path(defaults to sessioncwd) using ripgrep file discovery and Node glob matching. - Respects ignore files, includes hidden files except
.git, does not follow directory symlinks, and returns up to 1000 sorted paths.
- Matches files under
Grep- Searches with ripgrep (
rg), respecting ignore files and including hidden files except.git. - Supports
output_mode(files_with_matchesdefault,content,count),glob,-i,-n,-A/-B/-C,multiline,offset, andhead_limit(default 200, max 2000).
- Searches with ripgrep (
NotebookEdit- Edits Jupyter notebooks (
.ipynb) bycell_idwithedit_mode(replacedefault,insert,delete) andcell_type(code,markdown). - Requires a fresh
Readof the notebook first; clears staleoutputsandexecution_counton edited code cells and strips them when converting to markdown.
- Edits Jupyter notebooks (
Bash- Runs
/bin/bash -c <command>in the sessioncwdwith optionaltimeoutin milliseconds (default 120,000 ms, max 600,000 ms). - Supports cancellation via
AbortSignal(sendsSIGTERMthenSIGKILLto the process group). - Returns up to 64 KB inline and writes full output (up to 16 MB) to a session output artifact file.
- Runs
Checkpoints and Rewind (/pk-rewind)
- Every
Write,Edit, andNotebookEditoperation records a checkpoint:- Previous file contents are stored in a content-addressed blob store under
~/.local/share/pi-code-compat/<cwd-hash>/<session-hash>/blobs/. - Checkpoint history is persisted to the
pisession branch (pk:checkpoints) and restored onsession_startandsession_tree.
- Previous file contents are stored in a content-addressed blob store under
- The
/pk-rewindcommand reverts the most recent tracked file edit:- Restores the previous file contents from the blob store, or deletes the file if it was newly created.
- Prompts for confirmation when an interactive UI is available.
- Detects conflicts and aborts if the file was modified externally after the tracked edit.
- Shell (
Bash) and external file modifications are not tracked by checkpoints.
Runtime Requirements
- Node.js 22+
rg(ripgrep) onPATHforGlobandGrep/bin/bashforBashpdftotextonPATH(optional, required only for reading.pdffiles)
Installation
Install @pi-kode/file-tools from the public npm registry (https://www.npmjs.com/settings/pi-kode/packages):
npm install @pi-kode/file-tools
Or install it through pi's package manager using the scoped package name @pi-kode/file-tools. The committed .npmrc routes @pi-kode packages to https://registry.npmjs.org.
Contributing & Development
See CONTRIBUTING.md for local setup, running tests and type checks, architecture guidelines, and the release process.