← Catalog

pi-tool-wal

Write-ahead log for Pi tool calls: record intent before execution, reconcile results after, persist to SQLite for audit and crash recovery

Extension

Install

Install with PiG

pig install npm:pi-tool-wal

Install with Pi

pi install npm:pi-tool-wal
Review before installing

Packages 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": [
    "./extensions/tool-wal"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.1 (README.md). PiG does not review it.

pi-tool-wal

Write-ahead log (WAL) for Pi tool calls.

Before a tool runs, the extension records the intent (tool name, input, timestamps). After execution, it reconciles the result and stores the final status in a local SQLite database for audit and crash recovery.

This is not a transactional undo log. It does not roll back filesystem side effects. Pair it with something like git checkpoints if you need restore.

Install

Requires Node.js ≥ 22.5 (uses built-in node:sqlite).

pi install npm:pi-tool-wal

Or from git:

pi install git:github.com/boyuruan/pi-tool-wal

Local checkout:

pi install /absolute/path/to/pi-tool-wal

Then restart pi or run /reload.

How it works

Hooks into Pi’s tool lifecycle — the model cannot skip them:

PhaseEventsAction
Beforetool_execution_start, tool_callInsert/update pending intent
Aftertool_result, tool_execution_endComplete as success / failed / partial / blocked
Sessionsession_start / session_shutdownOpen DB, orphan stale pending ops
LLM tool call
    → tool_execution_start   write pending
    → tool_call              refresh final input (write-ahead intent)
    → execute tool
    → tool_result            reconcile (primary)
    → tool_execution_end     complete if still pending (blocked / immediate errors)

Storage

Single SQLite file:

~/.pi/agent/tool-wal/wal.db

Logical scopes (narrow → wide):

ScopeKeyMeaning
sessionsession_idOne Pi conversation
projectproject_keyStable project identity
global—Entire database

cwd is stored for display only; scoping uses project_key.

Stable project identity

Absolute paths differ across machines. Resolution order:

  1. Explicit
    • env TOOL_WAL_PROJECT_ID
    • .pi/wal-project-id (cwd or git toplevel)
    • .pi/tool-wal.json → { "projectId": "..." }
  2. Git — normalized origin remote + path relative to toplevel
    Examples: git:github.com/org/repo, git:github.com/org/repo#packages/api
  3. cwd fallback — Pi-style path encoding (machine-local)

HTTPS/SSH remotes and credentialed URLs normalize to the same host/path.

Commands

CommandDescription
/walThis project summary + recent ops
/wal statusSession + project + global counts
/wal pending [scope]Pending ops (session | project | global)
/wal recent [n] [scope]Recent ops (default: project)
/wal sessionCurrent session only
/wal projectAll sessions in this project
/wal projectsList projects in the DB
/wal global [n]Cross-project recent
/wal show <id|callId>Full record
/wal orphaned [scope]Orphaned ops
/wal prune [days] [global]Delete old completed rows (default: 30 days, this project)
/wal pathDB path + current project identity
/wal helpCommand list

Footer shows wal:N pending while the current session has in-flight ops.

Status values

StatusMeaning
pendingIntent recorded, no completion yet
successCompleted without error
partialCompleted with truncated/partial output
failedError or non-zero bash exit
blockedBlocked before execution (e.g. permission extension)
orphanedLeft pending across crash/shutdown

expected_ok flags whether completion matched the write-ahead intent (input hash, error state, etc.).

What is covered

  • Pi tool calls (built-in and extension-registered tools)

Not covered by default:

  • Interactive user bash (! / !!) — uses a different event path
  • Side effects outside tools

Development

git clone https://github.com/boyuruan/pi-tool-wal.git
cd pi-tool-wal
npm test
pi install "$PWD"    # or: pi -e ./extensions/tool-wal

Package layout follows the Pi package conventions (pi key in package.json).

License

MIT