🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

pi-continuous-learning

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pi-continuous-learning

A Pi extension that observes coding sessions and distills patterns into reusable instincts.

Source
npmnpm
Version
0.12.1
Version published
Weekly downloads
118
13.46%
Maintainers
1
Weekly downloads
 
Created
Source

pi-continuous-learning

A Pi extension that watches your coding sessions and distills patterns into reusable instincts — atomic learned behaviours with confidence scoring, project scoping, and closed-loop feedback validation.

CI npm License: MIT

Buy Me A Coffee

Inspired by everything-claude-code/continuous-learning-v2, reimplemented as a native Pi extension in TypeScript.

How it works

Flow diagram

The key idea: the extension watches what you do, learns patterns, injects relevant instincts into future sessions, then validates whether those instincts actually helped — adjusting confidence based on real outcomes rather than observation count alone.

The analyzer runs as a separate background process so it never causes lag or interference inside your Pi session.

Installation

pi install npm:pi-continuous-learning

This installs the extension globally and makes the pi-cl-analyze CLI available on your PATH.

Requirements

RequirementVersion
Pi>= 0.62.0
Node.js>= 18
LLM providerconfigured in Pi (analyzer defaults to Haiku)

Usage

Once installed, the extension runs automatically — no configuration required. To analyse observations and create instincts, set up the background analyzer.

Slash commands

CommandDescription
/instinct-statusShow all instincts grouped by domain with confidence scores and feedback stats
/instinct-evolveLLM-powered analysis: suggests merges, promotions, and cleanup
/instinct-exportExport instincts to JSON (filterable by scope/domain)
/instinct-import <path>Import instincts from a JSON file
/instinct-promote [id]Promote project instincts to global scope
/instinct-graduateGraduate mature instincts to AGENTS.md, skills, or commands
/instinct-projectsList all known projects and their instinct counts

LLM tools

The extension registers tools the LLM can call directly during conversation:

ToolDescription
instinct_listList instincts with optional scope/domain filters
instinct_readRead a specific instinct by ID
instinct_writeCreate or update an instinct
instinct_deleteRemove an instinct by ID
instinct_mergeMerge multiple instincts into one

You can ask Pi things like "show me my instincts", "merge these two instincts", or "delete low-confidence instincts" and it will use these tools.

Background analyzer

The analyzer is a standalone CLI that processes all your projects in a single pass and creates/updates instincts using Haiku. It runs outside of Pi sessions for efficiency.

Running manually

pi-cl-analyze

The script:

  • Iterates all projects in ~/.pi/continuous-learning/projects.json
  • Skips projects with no new observations since the last run
  • Skips projects with fewer than 20 observations (configurable)
  • For eligible projects: runs confidence decay, then uses Haiku to analyse patterns and write instinct files
  • Records a cursor so only new observations are processed on subsequent runs

Safety features:

FeatureDetail
Lockfile guardOnly one instance runs at a time — subsequent invocations exit immediately
Global timeoutProcess exits after 5 minutes regardless of progress
Stale lock detectionAuto-cleaned after 10 minutes or if the owning process is no longer alive

Logging

Structured JSON logs are written to ~/.pi/continuous-learning/analyzer.log. Each run records timing, token usage, cost, instinct changes, skip reasons, and errors.

# View recent run summaries
cat ~/.pi/continuous-learning/analyzer.log | jq 'select(.event == "run_complete")'

# Check total cost over time
cat ~/.pi/continuous-learning/analyzer.log | jq 'select(.event == "run_complete") | .total_cost_usd'

# Per-project breakdown
cat ~/.pi/continuous-learning/analyzer.log | jq 'select(.event == "project_complete") | {project: .project_name, duration_s: (.duration_ms/1000), cost: .cost_usd}'

The log auto-rotates at 10 MB. When the log file is not writable, output falls back to stderr.

Scheduling (macOS)

The recommended approach on macOS is launchd:

1. Find the binary path

which pi-cl-analyze

2. Create the plist

cat > ~/Library/LaunchAgents/com.pi-continuous-learning.analyze.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.pi-continuous-learning.analyze</string>
    <key>ProgramArguments</key>
    <array>
        <string>$(which pi-cl-analyze)</string>
    </array>
    <key>StartInterval</key>
    <integer>300</integer>
    <key>StandardOutPath</key>
    <string>/tmp/pi-cl-analyze-stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/pi-cl-analyze-stderr.log</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>$(echo $PATH)</string>
    </dict>
</dict>
</plist>
EOF

Note: $(which pi-cl-analyze) and $(echo $PATH) are evaluated when you run the cat command, so the plist contains the resolved absolute paths from your current shell.

3. Load

launchctl load ~/Library/LaunchAgents/com.pi-continuous-learning.analyze.plist

4. Verify

launchctl list | grep pi-continuous-learning
tail -5 ~/.pi/continuous-learning/analyzer.log | jq .

Managing the schedule

# Disable (persists across reboots)
launchctl unload ~/Library/LaunchAgents/com.pi-continuous-learning.analyze.plist

# Re-enable
launchctl load ~/Library/LaunchAgents/com.pi-continuous-learning.analyze.plist

# Remove entirely
rm ~/Library/LaunchAgents/com.pi-continuous-learning.analyze.plist

Scheduling (Linux)

crontab -e
# Add: runs every 5 minutes
*/5 * * * * pi-cl-analyze 2>> /tmp/pi-cl-analyze-stderr.log

Instinct files

Instincts are stored as Markdown files with YAML frontmatter under ~/.pi/continuous-learning/:

---
id: grep-before-edit
title: Grep Before Edit
trigger: "when modifying code files"
confidence: 0.7
domain: "workflow"
source: "personal"
scope: project
project_id: "a1b2c3d4e5f6"
project_name: "my-project"
observation_count: 8
confirmed_count: 5
contradicted_count: 1
inactive_count: 12
---
Always search with grep to find relevant context before editing files.

Confidence scoring

Confidence comes from two sources:

Discovery (initial, based on observation count):

ObservationsConfidence
1–20.30 — tentative
3–50.50 — moderate
6–100.70 — strong
11+0.85 — very strong

Feedback (ongoing, based on real outcomes):

EventChange
Confirmed (behaviour aligned)+0.05
Contradicted (behaviour went against)−0.15
Inactive (instinct irrelevant)no change
Passive decay−0.02 per week without observations

Range: 0.1 min, 0.9 max. Below 0.1 = flagged for removal.

Instinct quality control

Every write is validated and deduplicated before saving.

Content rules: action and trigger must be non-empty, >= 10 characters, and from a known domain (git, testing, debugging, workflow, typescript, javascript, python, go, css, design, security, performance, documentation, react, node, database, api, devops, architecture, other).

Semantic deduplication: a Jaccard similarity check runs against all existing instincts. If any existing instinct scores >= 0.6, the write is blocked and the LLM is told to update the existing one instead.

Analyzer quality tiers:

TierPattern typeAction
1 — Project conventionse.g. "use Result<T,E> for errors in this codebase"Record as project-scoped instinct
2 — Workflow patternsUniversal multi-step workflowsRecord as global-scoped instinct
3 — Generic agent behaviourRead-before-edit, clarify-before-implementSkip entirely

Instinct graduation

Instincts are designed to be short-lived — they should graduate into permanent knowledge within a few weeks:

Observation → Instinct (days) → AGENTS.md / Skill / Command (1–2 weeks)

Graduation targets:

TargetWhenWhat happens
AGENTS.mdSingle mature instinctAppended as a guideline to your project or global AGENTS.md
Skill3+ related instincts in the same domainScaffolded into a SKILL.md file
Command3+ workflow instincts in the same domainScaffolded into a slash command specification

Maturity criteria: age >= 7 days, confidence >= 0.75, confirmed >= 3 times, contradicted <= 1 time, not a duplicate of existing AGENTS.md content.

TTL enforcement (after 28 days without graduation):

  • Confidence < 0.3 → deleted
  • Confidence >= 0.3 → confidence halved and flagged for removal

Configuration

All defaults work out of the box. Override at ~/.pi/continuous-learning/config.json:

{
  "run_interval_minutes": 5,
  "min_observations_to_analyze": 20,
  "min_confidence": 0.5,
  "max_instincts": 20,
  "max_injection_chars": 4000,
  "model": "claude-haiku-4-5",
  "timeout_seconds": 120,
  "active_hours_start": 8,
  "active_hours_end": 23,
  "max_idle_seconds": 1800
}
FieldDefaultDescription
run_interval_minutes5How often the analyzer runs (used for decay calculations)
min_observations_to_analyze20Minimum observations before analysis triggers
min_confidence0.5Instincts below this are not injected into prompts
max_instincts20Maximum instincts injected per turn
max_injection_chars4000Character budget for the injection block (~1000 tokens)
modelclaude-haiku-4-5Model for the background analyzer
timeout_seconds120Per-project LLM session timeout
active_hours_start8Hour (0–23) at which the active observation window starts
active_hours_end23Hour (0–23) at which the active observation window ends
max_idle_seconds1800Seconds of inactivity before a session is considered idle
log_path~/.pi/continuous-learning/analyzer.logAnalyzer log file path

Storage

All data stays local on your machine:

~/.pi/continuous-learning/
  config.json                   # Optional overrides
  projects.json                 # Project registry
  analyze.lock                  # Present only while analyzer runs
  instincts/personal/           # Global instincts
  projects/<hash>/
    project.json                # Project metadata + analysis cursor
    observations.jsonl          # Current observations
    observations.archive/       # Archived (auto-purged after 30 days)
    instincts/personal/         # Project-scoped instincts

Privacy & security

  • All data stays on your machine — no external telemetry
  • Secrets (API keys, tokens, passwords) are scrubbed from observations before writing to disk
  • Only instincts (patterns) can be exported — never raw observations
  • The analyzer uses your existing Pi LLM credentials — no additional keys needed

Updating

pi install npm:pi-continuous-learning

Your observations, instincts, and configuration in ~/.pi/continuous-learning/ are preserved across updates. If you have a launchd schedule set up, no changes needed.

Development

npm install
npm test          # run tests
npm run check     # tests + lint + typecheck (mirrors CI)
npm run build     # compile to dist/

See CONTRIBUTING.md for full development guidelines.

Contributing

Contributions are welcome! See CONTRIBUTING.md for development setup, commit conventions, and PR guidelines.

Please note that this project has a Code of Conduct. By participating you agree to abide by its terms.

License

MIT

Keywords

pi-package

FAQs

Package last updated on 06 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts