my-pi 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,17 +4,41 @@ Composable [pi](https://pi.dev) coding agent for humans and agents.
4
4
 
5
5
  Built on the
6
6
  [@mariozechner/pi-coding-agent](https://github.com/badlogic/pi-mono)
7
- SDK. Adds MCP server support, extension stacking, JSON output for
8
- agent consumption, and a programmatic API.
7
+ SDK. Adds MCP server support, extension stacking, LSP tools, agent
8
+ chains, prompt presets, local SQLite telemetry for evals, and a
9
+ programmatic API.
9
10
 
10
11
  Extension stacking patterns inspired by
11
12
  [pi-vs-claude-code](https://github.com/disler/pi-vs-claude-code).
12
13
 
13
- ## Setup
14
+ ## Features
15
+
16
+ - **Pi-native CLI + SDK wrapper** — interactive TUI, print mode, JSON
17
+ mode, and programmatic runtime creation.
18
+ - **MCP integration** — stdio and HTTP/streamable-HTTP servers from
19
+ `mcp.json`, auto-registered as Pi tools.
20
+ - **Built-in LSP tools** — diagnostics, hover, definitions,
21
+ references, and document symbols via language servers.
22
+ - **Agent chains** — sequential scout/plan style workflows defined in
23
+ `.pi/agents/agent-chain.yaml`.
24
+ - **Managed skills** — discover, enable, disable, import, and sync
25
+ Pi-native skills.
26
+ - **Prompt presets** — base presets plus additive prompt layers with
27
+ per-project persistence.
28
+ - **Secret redaction** — redact API keys and other sensitive output
29
+ before the model sees tool results.
30
+ - **Session handoff + recall** — export focused handoff markdown and
31
+ teach the model to use `pirecall` for prior-session context.
32
+ - **Local telemetry** — optional SQLite telemetry for evals, tool
33
+ analysis, and operational debugging.
34
+ - **Bundled themes + extension stacking** — ship defaults, then layer
35
+ extra project or ad-hoc extensions on top.
36
+
37
+ ## Get Started
14
38
 
15
39
  ```bash
16
- pnpm install
17
- pnpm run build
40
+ pnpx my-pi@latest
41
+ # or: npx my-pi@latest / bunx my-pi@latest
18
42
  ```
19
43
 
20
44
  ### API Keys
@@ -33,7 +57,7 @@ priority order):
33
57
  ### Interactive mode (full TUI)
34
58
 
35
59
  ```bash
36
- my-pi
60
+ pnpx my-pi@latest
37
61
  ```
38
62
 
39
63
  Pi's full terminal UI with editor, `/commands`, model switching
@@ -42,25 +66,139 @@ Pi's full terminal UI with editor, `/commands`, model switching
42
66
  ### Print mode (one-shot)
43
67
 
44
68
  ```bash
45
- my-pi "your prompt here"
46
- my-pi -P "explicit print mode"
69
+ pnpx my-pi@latest "your prompt here"
70
+ pnpx my-pi@latest -P "explicit print mode"
71
+ # or: npx my-pi@latest ... / bunx my-pi@latest ...
47
72
  ```
48
73
 
49
74
  ### JSON output (for agents)
50
75
 
51
76
  ```bash
52
- my-pi --json "list all TODO comments"
53
- echo "plan a login page" | my-pi --json
77
+ pnpx my-pi@latest --json "list all TODO comments"
78
+ echo "plan a login page" | pnpx my-pi@latest --json
54
79
  ```
55
80
 
56
81
  Outputs NDJSON events — one JSON object per line — for programmatic
57
82
  consumption by other agents or scripts.
58
83
 
84
+ ### Local telemetry (SQLite)
85
+
86
+ Telemetry is **disabled by default**. When enabled, my-pi records
87
+ operational telemetry for each run in a local SQLite database. This is
88
+ intended for eval harnesses, latency analysis, tool failure analysis,
89
+ and local debugging.
90
+
91
+ ```bash
92
+ pnpx my-pi@latest --telemetry --json "solve this task"
93
+ pnpx my-pi@latest --telemetry --telemetry-db ./tmp/evals.db --json "run case"
94
+ ```
95
+
96
+ By default the database lives at:
97
+
98
+ ```text
99
+ ~/.pi/agent/telemetry.db
100
+ ```
101
+
102
+ You can relocate the whole Pi auth/config/session directory for
103
+ sandboxed or CI runs with either:
104
+
105
+ ```bash
106
+ pnpx my-pi@latest --agent-dir /work/pi-agent --telemetry --json "run case"
107
+ ```
108
+
109
+ or:
110
+
111
+ ```bash
112
+ PI_CODING_AGENT_DIR=/work/pi-agent pnpx my-pi@latest --telemetry --json "run case"
113
+ ```
114
+
115
+ Use the interactive command to inspect or persist the setting:
116
+
117
+ ```text
118
+ /telemetry status
119
+ /telemetry stats
120
+ /telemetry query run=<eval-run-id> success=true limit=10
121
+ /telemetry export ./tmp/eval-runs.json suite=smoke
122
+ /telemetry on
123
+ /telemetry off
124
+ /telemetry path
125
+ ```
126
+
127
+ Recommended eval env vars for correlation:
128
+
129
+ - `MY_PI_EVAL_RUN_ID`
130
+ - `MY_PI_EVAL_CASE_ID`
131
+ - `MY_PI_EVAL_ATTEMPT`
132
+ - `MY_PI_EVAL_SUITE`
133
+
134
+ Recorded tables:
135
+
136
+ - `runs`
137
+ - `turns`
138
+ - `tool_calls`
139
+ - `provider_requests`
140
+
141
+ Query and export helpers:
142
+
143
+ - `/telemetry query ...` shows recent run summaries
144
+ - `/telemetry export [path] ...` writes matching runs as JSON
145
+ - supported filters: `run=` / `eval_run_id=`, `case=` /
146
+ `eval_case_id=`, `suite=` / `eval_suite=`,
147
+ `success=true|false|null`, `limit=<n>`
148
+ - `/telemetry query` defaults to `limit=20`
149
+ - `/telemetry export` auto-generates a timestamped JSON file when no
150
+ path is provided
151
+
152
+ Schema notes:
153
+
154
+ - source of truth: `src/extensions/telemetry-schema.sql`
155
+ - current telemetry schema version: `1`
156
+ - schema version is tracked with `PRAGMA user_version`
157
+ - unversioned local telemetry databases are initialized/upgraded to v1
158
+ on open
159
+ - newer unsupported schema versions fail fast instead of silently
160
+ downgrading
161
+ - opens the database in WAL mode: `PRAGMA journal_mode = WAL`
162
+ - waits up to 5s on lock contention: `PRAGMA busy_timeout = 5000`
163
+ - packaged builds ship the schema as `dist/telemetry-schema.sql`
164
+
165
+ CLI flags `--telemetry` and `--no-telemetry` override only the current
166
+ process. `/telemetry on` and `/telemetry off` update the saved default
167
+ for future sessions.
168
+
169
+ ### Sandbox / CI auth and config isolation
170
+
171
+ If you run my-pi in containers, CI, or ephemeral sandboxes, changing
172
+ `HOME` often hides the usual `~/.pi/agent/auth.json` credentials. Use
173
+ a stable agent directory instead of relying on `HOME` alone.
174
+
175
+ Recommended options:
176
+
177
+ 1. Pass provider API keys directly via environment variables.
178
+ 2. Set `--agent-dir /path/to/pi-agent` for the process.
179
+ 3. Or set `PI_CODING_AGENT_DIR=/path/to/pi-agent` in the environment.
180
+
181
+ The agent directory holds Pi-managed state such as:
182
+
183
+ - `auth.json`
184
+ - `settings.json`
185
+ - `sessions/`
186
+ - `telemetry.db`
187
+ - `telemetry.json`
188
+
189
+ A practical sandbox command looks like:
190
+
191
+ ```bash
192
+ PI_CODING_AGENT_DIR=/work/pi-agent \
193
+ ANTHROPIC_API_KEY=... \
194
+ pnpx my-pi@latest --telemetry --json "run eval case"
195
+ ```
196
+
59
197
  ### Extension stacking
60
198
 
61
199
  ```bash
62
- my-pi -e ./ext/damage-control.ts -e ./ext/tool-counter.ts
63
- my-pi --no-builtin -e ./ext/custom.ts "do something"
200
+ pnpx my-pi@latest -e ./ext/damage-control.ts -e ./ext/tool-counter.ts
201
+ pnpx my-pi@latest --no-builtin -e ./ext/custom.ts "do something"
64
202
  ```
65
203
 
66
204
  Stack arbitrary Pi extensions via `-e`. Use `--no-builtin` to skip all
@@ -85,8 +223,8 @@ via Pi settings JSON:
85
223
  ### Stdin piping
86
224
 
87
225
  ```bash
88
- echo "review this code" | my-pi
89
- cat plan.md | my-pi --json
226
+ echo "review this code" | pnpx my-pi@latest
227
+ cat plan.md | pnpx my-pi@latest --json
90
228
  ```
91
229
 
92
230
  When stdin is piped, it's read as the prompt and print mode runs
@@ -95,11 +233,13 @@ automatically.
95
233
  ### Programmatic API
96
234
 
97
235
  ```ts
98
- import { createMyPi, runPrintMode } from 'my-pi';
236
+ import { create_my_pi, runPrintMode } from 'my-pi';
99
237
 
100
- const runtime = await createMyPi({
238
+ const runtime = await create_my_pi({
239
+ agent_dir: './tmp/pi-agent',
101
240
  extensions: ['./my-ext.ts'],
102
- builtins: true,
241
+ telemetry: true,
242
+ telemetry_db_path: './tmp/evals.db',
103
243
  });
104
244
  await runPrintMode(runtime, {
105
245
  mode: 'json',
@@ -154,9 +294,9 @@ HTTP MCP servers are supported too:
154
294
  ```json
155
295
  {
156
296
  "mcpServers": {
157
- "pm-platform": {
297
+ "my-http-mcp": {
158
298
  "type": "http",
159
- "url": "https://project.cloudlobsters.com/api/mcp",
299
+ "url": "https://myproject.com/api/mcp",
160
300
  "headers": {
161
301
  "Authorization": "Bearer ..."
162
302
  }
@@ -201,6 +341,15 @@ In interactive mode:
201
341
  - `/preset reset <name>` — remove a project-local override and fall
202
342
  back to user/built-in if available
203
343
  - `/preset clear` — clear the active base preset and all layers
344
+ - `/chain` — inspect or switch the active agent chain
345
+ - `/agents` — list discovered agent definitions
346
+ - `/lsp status|list|restart` — inspect or restart language server
347
+ state
348
+ - `/redact-stats` — show how many secrets were redacted this session
349
+ - `/handoff <task>` — export current context to a handoff markdown
350
+ file
351
+ - `/telemetry status|stats|query|export|on|off|path` — inspect, query,
352
+ export, or toggle local SQLite telemetry
204
353
 
205
354
  ### How it works
206
355
 
@@ -298,6 +447,52 @@ for the same project via `~/.pi/agent/prompt-preset-state.json`.
298
447
  This repo also includes an example `.pi/presets.json` with sample base
299
448
  presets and layers.
300
449
 
450
+ ## LSP Integration
451
+
452
+ The built-in LSP extension adds Pi tools for:
453
+
454
+ - diagnostics
455
+ - hover
456
+ - definitions
457
+ - references
458
+ - document symbols
459
+
460
+ You still need the underlying language server binaries installed.
461
+ `my-pi` prefers project-local binaries from `node_modules/.bin` and
462
+ otherwise falls back to whatever is on `PATH`.
463
+
464
+ For the main TypeScript / JavaScript / Svelte workflow, install:
465
+
466
+ ```bash
467
+ pnpm add -D typescript typescript-language-server svelte-language-server
468
+ ```
469
+
470
+ That covers:
471
+
472
+ - TypeScript / JavaScript via `typescript-language-server`
473
+ - Svelte via `svelteserver`
474
+
475
+ `my-pi` can also use other language servers if you already have them
476
+ installed and available on `PATH`, including:
477
+
478
+ - Python via `python-lsp-server`
479
+ - Go via `gopls`
480
+ - Rust via `rust-analyzer`
481
+ - Ruby via `solargraph`
482
+ - Java via `jdtls`
483
+ - Lua via `lua-language-server`
484
+
485
+ Use `/lsp status` to inspect active server state and
486
+ `/lsp restart all` or `/lsp restart <language>` to clear cached
487
+ clients.
488
+
489
+ ## Session Recall
490
+
491
+ The recall extension nudges the model to use `npx pirecall` when the
492
+ user references prior work or when historical project context would
493
+ help. It also triggers a background `pirecall sync --json` on session
494
+ start when the local recall database exists.
495
+
301
496
  ## Session Handoff
302
497
 
303
498
  Use `/handoff <task>` to export conversation context as a markdown
@@ -306,7 +501,7 @@ file that can be piped into a new session:
306
501
  ```bash
307
502
  # In session 1: /handoff continue the auth refactor
308
503
  # Then:
309
- my-pi < handoff-1234567890.md
504
+ pnpx my-pi@latest < handoff-1234567890.md
310
505
  ```
311
506
 
312
507
  ## Project Structure
@@ -323,8 +518,11 @@ src/
323
518
  chain.ts Agent chain pipelines
324
519
  filter-output.ts Secret redaction in tool output
325
520
  handoff.ts Session context export
521
+ lsp.ts Language server tools and /lsp command
522
+ otel.ts Local telemetry extension and /telemetry command
326
523
  prompt-presets.ts Runtime prompt preset selection and editing
327
524
  recall.ts Past session recall guidance
525
+ telemetry-*.ts Telemetry config + SQLite storage
328
526
  mcp/
329
527
  client.ts Minimal MCP stdio client (JSON-RPC 2.0)
330
528
  config.ts Loads and merges mcp.json configs