@pi-api/cli
v0.1.8
Published
Pi CLI — Intelligence infrastructure for AI agents. The Hokage of your codebase.
Maintainers
Readme
@pi-api/cli
Pi CLI — Hokage Edition: pi learn, pi resonate, pi prompt, pi routine, pi validate, plus the pi-hokage onboarding wizard.
Install
# Recommended: summon the Hokage (also published as `pi-hokage`)
bunx pi-hokage@latest
npx pi-hokage@latest
pnpx pi-hokage@latest
yarn dlx pi-hokage@latest
# Or install the CLI package directly
npm install -g @pi-api/cliNon-interactive / CI install
# Zero prompts — accepts smart defaults for every step
npx pi-hokage@latest --yes \
--api-key=$PI_API_KEY \
--base-url=https://pi.yourco.com \
--persona=expertFlags: -y / --yes, --api-key=<key> (or PI_API_KEY), --base-url=<url> (or PI_CLI_BASE_URL), --persona=<newbie|normal|expert|designer|pm>, -h / --help.
In --yes mode: Pi runs pi init, pi learn, installs git hooks, generates CI configs when it detects .github/ or .gitlab-ci.yml, adds a README badge if a README exists, and skips the watch daemon + global install prompts.
Personas
During pi-hokage, Pi asks how you want to be spoken to. The choice is persisted in ~/.config/pi/config.json, sent on every API call as X-Pi-Persona, and consumed by the Mastra agents (cli-resonate, cli-architect, cli-enforcer) so responses adapt to your level and role.
| Persona | Who it's for | Effect on Pi responses |
|------------|-------------------------------|----------------------------------------------------------------------------------------|
| newbie | New to coding / to this stack | Explains every command, expected outcome, prerequisites, and how to verify |
| normal | Default | Balanced explanations; skips definitions for common terms |
| expert | Senior engineers | Terse; paths, diffs, exit codes only; no hand-holding |
| designer | UI/UX focused | Frames everything as components, tokens, spacing, accessibility; biases UI templates |
| pm | Product managers | Acceptance criteria, user-visible behavior, test plans; hides implementation detail |
Resolution order: PI_PERSONA env var > persona in .pi/config.json (team/project override) > persona in ~/.config/pi/config.json (wizard) > "normal".
Change it later: re-run pi-hokage or export PI_PERSONA=expert in your shell.
Env
PI_API_KEY— Pi API key (pi_...), or configure viapi auth login/pi-hokage.PI_CLI_BASE_URL— API origin (defaulthttps://piii-black.vercel.app).PI_PERSONA— override the configured persona for the current shell (one ofnewbie/normal/expert/designer/pm). See the Personas section below.PI_CLI_ASYNC— set totrueto always use async workflows (?async=true) for learn / validate / routine (optional; can use--asyncper command instead).PI_CLI_AUTO_SYNC— set totrueto always runpi syncbefore validate when an API key is present (optional; by default sync also runs when.pi/system-style.jsonis missing).PI_CLI_NO_AGENTIC_INJECT— set to1to skip merging Pi’s marked section into.cursorrules,CLAUDE.md,.clinerules, and.windsurf/rules/pi-context.mdafterpi learn/pi routine.- Pi watch (daemon / observable) —
PI_CLI_WATCH_HEARTBEAT_MS(default 10000),PI_CLI_WATCH_STALE_MS(default 45000, used bypi watch --status),PI_CLI_WATCH_LOG_MAX_BYTES(~1.5MB, log rotation),PI_CLI_WATCH_DEBOUNCE_MS(file watcher debounce).
CI templates
Generated workflows are documented in docs/cli/ci.md (package managers, monorepo PI_CLI_ROOT, .pi cache caveats, secrets).
File layout and agent handoff
- Cloud generates, CLI writes — routines and
system-style.jsonare persisted under.pi/by the local CLI after API responses. - Token-aware IDE hints — after
pi learnorpi routine, the CLI updates a small auto-managed block in common agent config files (only when those files already exist, except.clinerules/.windsurf/rules/pi-context.mdwhich are Pi-specific). Routine paths injected for a run are primary + references + optional API id lists, never the wholeroutines/folder. - Details: see
docs/cli/file-management-architecture.md.
Universal entrypoint (Omni-Router)
Run natural language without a subcommand:
pi "audit my uncommitted changes"
pi "construire un tableau de bord avec Recharts" # any language — server normalizes intentBehavior:
- Multilingual — calls the NLP plan API (
pi reminduses the same planner). Detected locale + normalized (English) intent are logged when non-English. - VCS-aware fallbacks — if the API is offline, local heuristics use your working tree (Git, GitLab/Bitbucket/Gerrit hosts, Perforce via
p4, etc.; seepi vcs). - Multi-step chains — e.g.
validate → fixwhen the plan or heuristics call for it. You’ll see◐ Execution plan: validate → fix.
Flags: --force-resonate, --force-routine (same as before).
Implicit preflight (dependency chaining)
Several commands hydrate context before doing work (unless you opt out):
| Command | Auto behavior |
|--------|----------------|
| pi validate / pi check | pi init if .pi/ missing → pi sync when API key exists and style is missing (or PI_CLI_AUTO_SYNC=true) → pi learn if rules still missing |
| pi fix | pi init if needed → deterministic “validate-style” scan, then autofix |
| pi prompt / pi p, pi routine "<intent>" | pi init → optional pi sync → pi learn if needed (API errors are warned, not fatal) |
| pi resonate, pi watch | pi init if .pi/ missing |
Opt out: --no-auto on validate, check, fix, prompt, p, routine (generate path), resonate, watch. For validate / routine / prompt you can also use --skip-learn or --skip-sync to fine-tune.
Universal VCS
pi vcs— prints detected provider (Git / GitLab / Bitbucket / Gerrit / Perforce / unknown) and adapter capabilities.- Config — optional
.pi/config.jsonwith"vcs": { "type": "auto" | "git" | "perforce" | ... }(created bypi initif missing). Seedocs/cli/vcs-support.md.
Agent task tracking
pi tasks— list active (pending/running) tasks for this repo.pi tasks show <task_id>/pi tasks tree <root_id>— inspect steps.pi tasks clean— reap stale running/pending tasks (default: older than ~1h;pi tasks clean forcemarks all active rows failed), then prune aged completed rows. After each successfulpi resonatesession, the CLI also reaps other staleresonatetasks for the same repo (~25m) sopi tasks listdoes not show ghost “running” rows from abandoned omnirouter runs.pi tasks resume [session_id]— show where work stopped and suggestpi resume <runId>orpi resonate … --session ….- Dropped connection / timeout — async
validate/learn/routineprint a “Pick up where you left off” block withpi resume <runId>;pi tasksrepeats the resume line when a workflow id is stored so you do not restart from scratch. - Details:
docs/cli/task-tracking.md.
Strict pi fix (CI)
Use pi fix --strict or set PI_CLI_STRICT_FIX=1 to exit with code 1 when no matching TS/JS files were found, or when violations existed but no deterministic autofixes were applied. The default remains exit 0 so existing scripts that treat “nothing to do” as success keep working.
Commands
pi init— create.pi/scaffold.--with-hooksinstalls Pi-managed Git hooks (pre-commit / pre-push).--ci github/--ci gitlab/--ci circle(repeatable) writes CI templates (pi-hokagecan do the same interactively).pi watch— realtime deterministic checks on save.--daemonspawns a child with.pi/.watch.lock,.pi/.watch-health.json,.pi/logs/watch.log(rotating), and.pi/.watch-pid.json.--statususes heartbeat freshness (not onlykill -0).--stopclears state.--foregroundruns in this terminal with log + heartbeat;--daemon --foregroundruns the daemon inline (debug).pi badge— insert or refresh a Pi badge inREADME.md(--dry-run,--copy, optional--dynamic-url).pi learn— structural scan →.pi/system-style.json(--with-graph,--async,--dry-run)pi resonate "<intent>"— Staff Engineer multi-turn terminal session: challenges your feature idea using repo +system-style.json+ optional.pi/constitution.md(no code generation). Saves.pi/resonance/<slug>-<date>.md(decisions, claims, exit criteria) for handoff topi routineor Cursor. Flags:--mode explore|challenge|decision,--staged(diff-aware),--deep(excerpts + follow-up pulls fromfiles_likely_touched),--resume <file>,--export(printpi routinehandoff),--with-violations <validate.json>,--no-save.--with-excerptsis an alias for--deep.pi prompt "<intent>"(alias:pi p) — Prompt compiler: turns a vague request into a paste-ready, codebase-aware instruction for Cursor / Claude / Windsurf (usessystem-style.json+ repo context + server memory/graph). Shows context quality, a memory highlight, diff vs last run (.pi/prompt-cache/), next-step hints (pi routine/pi validate), and optional y/n feedback (stored in Pi memory).--rawprints prompt only;--no-copyskips clipboard;--with-excerptssends redacted snippets for deeper hints.pi routine "<intent>"— Architect routine →.pi/routines/<slug>.v<n>.md(Pi routine v2: YAML +files_manifest+ phased steps). Sends local repo context (paths, import histogram, metadata for v2 routines for smarter matching);--with-excerptsadds redacted snippets for AST.--format cursor,claude,windsurfalso writes agent rule files.--list/--tags/--show/--upgrade <file>manage the library. Generation is v2-only (no legacy Markdown fallback server-side).pi validate [intent]/pi check [intent]— Sharingan deterministic rules + cloud semantic merge (--async,--hunks-only,--staged). When issues are found, suggestspi prompt "fix these …".pi intent "<query>"— Byakugan intent DSL (debug)pi auth-status/pi auth-login --api-key .../pi auth-logout— credentialspi tasks/pi vcs— task audit trail and VCS diagnostics (see sections above)
See the Pi API docs for HTTP counterparts under /api/cli/* (including /api/cli/workflow/poll for async runs).
