MCPcopy Index your code
hub / github.com/0xSero/pi-brain

github.com/0xSero/pi-brain @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
160 symbols 379 edges 38 files 36 documented · 22%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

pi-brain

Privacy-first dataset extraction from AI coding sessions.

A Pi package with a thin Pi extension on top of a source-agnostic TypeScript core. Extract sessions from Pi, Claude Code, Codex, OpenCode, and Cursor, sanitize them locally, optionally run structured review, export to training formats, and upload to Hugging Face or custom HTTP targets.

Quick Start

npm install -g @0xsero/pi-brain

# Or install as a Pi package
pi install npm:@0xsero/pi-brain

CLI Usage

# List available sessions across all sources
pi-brain list

# Export Pi sessions (sanitized, with privacy redaction)
pi-brain export pi

# Export Claude Code sessions
pi-brain export claude

# Export from all available sources
pi-brain export codex
pi-brain export opencode
pi-brain export cursor

Pi Extension Commands

When installed as a Pi package, these commands are available inside Pi:

  • /export-local — Export sanitized Pi sessions to disk
  • /export-public — Export sanitized Pi sessions and publish to Hugging Face
  • /export — TUI alias that asks local vs public, then current vs all

Both commands open a TUI picker when you omit the scope. You can also skip the picker with --current or --all.

/export-public reads defaults from ~/.pi/agent/pi-brain.json when present:

{
  "huggingface": {
    "repo": "0xSero/pi-brain-private-publish-test",
    "visibility": "private"
  },
  "export": {
    "formats": ["sessions"]
  }
}

You can still override these per command, for example:

/export-local --format=sessions,chatml
/export-local --all
/export-public --repo 0xSero/my-dataset --public
/export-public --all

Architecture

Source plugin (pi, claude, codex, ...) → CanonicalSession
    → Static privacy engine (local only)
    → [Optional] Structured review (OpenAI-compatible, sanitized chunks only)
    → Training formatters (sessions, sft-jsonl, chatml)
    → Upload targets (HF dataset or custom HTTP)

See docs/design.md for the full architecture.

Core File Budget (15 files)

File Purpose
core/index.ts Public API surface
core/configs/types.ts Configuration types
core/configs/defaults.ts Default values
core/privacy/types.ts Privacy/redaction types
core/privacy/detectors.ts Pattern-based secret detection
core/privacy/redactor.ts Placeholder replacement engine
core/privacy/reviewer.ts Optional AI-powered review
core/data-processing/types.ts Canonical data types
core/data-processing/canonicalize.ts Session validation/normalization
core/data-processing/chunker.ts Deterministic text chunking
core/data-processing/formatters.ts Training format converters
core/data-processing/bundle.ts Export bundle assembly
core/uploads/types.ts Upload target types
core/uploads/http-client.ts HTTP upload utilities
core/uploads/uploader.ts Upload routing

Source Plugins

Plugin Status Storage Location
Pi Complete ~/.pi/agent/sessions/
Claude Code Complete ~/.claude/projects/
Codex Complete ~/.codex/sessions/
OpenCode Complete ~/.local/share/opencode/ or ~/Library/Application Support/opencode/
Cursor Complete Reads pre-extracted JSONL from ~/extracted_data/
Factory Stub Not yet supported (awaiting format documentation)

Privacy Guarantees

  • Local-first: Raw session text never leaves your machine in v1.
  • Deterministic redaction: API keys, passwords, emails, phones, JWTs, auth headers, IPs, filesystem paths, labeled personal fields, and provider tokens are all replaced with stable placeholders.
  • Placeholder stability: The same secret always gets the same placeholder within a session (e.g. <EMAIL_1>).
  • Optional structured review: Off by default. When enabled, only already-sanitized text is sent to an OpenAI-compatible endpoint for residual entity detection.

Development

npm install
npm run typecheck    # Type checking
npm run check        # Lint with Biome
npm test             # Run tests with Vitest
npm run build        # Build to dist/

License

MIT

Extension points exported contracts — how you extend this code

DetectorDef (Interface)
A single detector definition: a category and a pattern to match.
core/privacy/detectors.ts
ClaudeEntry (Interface)
Envelope shape for every line in a Claude JSONL session file.
plugins/claude/index.ts
SourcePlugin (Interface)
(no doc)
core/index.ts
PrivacyConfig (Interface)
(no doc)
core/configs/types.ts
HttpResponse (Interface)
(no doc)
core/uploads/http-client.ts
CanonicalMessage (Interface)
(no doc)
core/data-processing/types.ts
SessionRow (Interface)
(no doc)
plugins/opencode/index.ts
HermesSessionRow (Interface)
(no doc)
plugins/hermes/index.ts

Core symbols most depended-on inside this repo

detectAll
called by 13
core/privacy/detectors.ts
sanitize
called by 11
core/privacy/redactor.ts
anonymize
called by 11
core/privacy/anonymizer.ts
createBundle
called by 9
core/data-processing/bundle.ts
home
called by 9
plugins/helpers.ts
chunk
called by 8
core/data-processing/chunker.ts
canonicalize
called by 7
core/data-processing/canonicalize.ts
findFiles
called by 7
plugins/helpers.ts

Shape

Function 119
Interface 35
Method 4
Class 2

Languages

TypeScript100%

Modules by API surface

plugins/pi/index.ts23 symbols
plugins/opencode/index.ts12 symbols
plugins/hermes/index.ts12 symbols
plugins/helpers.ts10 symbols
cli.ts8 symbols
plugins/factory/index.ts7 symbols
core/privacy/anonymizer.ts7 symbols
core/configs/types.ts7 symbols
plugins/claude/index.ts6 symbols
core/privacy/types.ts6 symbols
core/index.ts6 symbols
core/data-processing/types.ts6 symbols

For agents

$ claude mcp add pi-brain \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact