pi-llm-debugging 0.1.0

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 ADDED
@@ -0,0 +1,75 @@
1
+ # pi-llm-debugging
2
+
3
+ A [pi](https://shittycodingagent.ai) extension that captures the full LLM provider request payload to disk before each call — letting you inspect exactly what gets sent to the model, turn by turn.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:pi-llm-debugging
9
+ ```
10
+
11
+ To uninstall:
12
+
13
+ ```bash
14
+ pi remove npm:pi-llm-debugging
15
+ ```
16
+
17
+ ## How it works
18
+
19
+ Every time pi is about to call the LLM, the extension intercepts the raw provider payload and writes it as a JSON file into your project's local `.pi` directory:
20
+
21
+ ```
22
+ .pi/pi-llm-debugging/<session_id>/<seq>.json
23
+ ```
24
+
25
+ - **`session_id`** — the current pi session identifier (visible in the footer bar). Resets on `/new`, `/resume`, and `/fork`.
26
+ - **`seq`** — a zero-padded sequence number (`001`, `002`, ...) that increments with each LLM call within the session.
27
+
28
+ For example, a session might produce:
29
+
30
+ ```
31
+ .pi/pi-llm-debugging/
32
+ └── abc123def/
33
+ ├── 001.json ← first turn
34
+ ├── 002.json ← second turn (after a tool call loops back)
35
+ └── 003.json
36
+ ```
37
+
38
+ Each file is the exact payload the provider receives: the full message history, system prompt, tool definitions, model parameters, and any cache hints.
39
+
40
+ ## What you can debug
41
+
42
+ **Session health** — Read through the messages array to see how the conversation is growing. Spot runaway context, unexpected role ordering, or missing tool results that might confuse the model.
43
+
44
+ **Token usage** — Compare payloads across turns to see what's eating your context window. Identify large tool results or verbose system prompt sections that could be trimmed.
45
+
46
+ **System prompt drift** — Check whether injected context from extensions or skills is accumulating correctly, being duplicated, or getting dropped.
47
+
48
+ **Tool serialization** — Verify that tool definitions and arguments are serialized the way the provider expects, especially useful when debugging custom tools or provider-specific quirks.
49
+
50
+ **Compaction quality** — Compare the payload just before and just after a `/compact` to see what the summary replaced and whether important context was preserved.
51
+
52
+ ## Tips
53
+
54
+ Add the debugging output to your `.gitignore` so it doesn't end up in version control:
55
+
56
+ ```
57
+ .pi/pi-llm-debugging/
58
+ ```
59
+
60
+ Use `jq` to quickly inspect a payload:
61
+
62
+ ```bash
63
+ # See just the messages
64
+ jq '.messages' .pi/pi-llm-debugging/<session_id>/001.json
65
+
66
+ # Count tokens approximation: check message content lengths
67
+ jq '[.messages[].content | .. | strings | length] | add' .pi/pi-llm-debugging/<session_id>/001.json
68
+
69
+ # Diff two consecutive turns to see what changed
70
+ diff \
71
+ <(jq . .pi/pi-llm-debugging/<session_id>/001.json) \
72
+ <(jq . .pi/pi-llm-debugging/<session_id>/002.json)
73
+ ```
74
+
75
+ Since files are scoped per-project under `.pi/`, each project manages its own debugging output independently — nothing bleeds into other projects or your global `~/.pi` directory.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Pi LLM Debugging — Saves the full provider request payload to disk before each LLM call.
3
+ *
4
+ * Files are written to <project>/.pi/pi-llm-debugging/<pi_session_id>/<sequence>.json
5
+ * where <sequence> is a zero-padded counter (001, 002, ...).
6
+ *
7
+ * Unlike the global save-llm-prompt extension, each project manages its own debugging
8
+ * files under its local .pi directory, making it easy to review, diff, and gitignore
9
+ * per-project LLM traffic.
10
+ *
11
+ * The current Pi session ID is shown in the footer bar and updates on /new, /resume, and /fork.
12
+ */
13
+
14
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
15
+ import { mkdirSync, writeFileSync } from "node:fs";
16
+ import { join } from "node:path";
17
+
18
+ export default function (pi: ExtensionAPI) {
19
+ let outDir = "";
20
+ let sequence = 0;
21
+
22
+ function initSession(ctx: {
23
+ cwd: string;
24
+ sessionManager: { getSessionId(): string };
25
+ ui: { setStatus(key: string, value: string | undefined): void };
26
+ }) {
27
+ const sessionId = ctx.sessionManager.getSessionId();
28
+ outDir = join(ctx.cwd, ".pi", "pi-llm-debugging", sessionId);
29
+ sequence = 0;
30
+ mkdirSync(outDir, { recursive: true });
31
+ ctx.ui.setStatus("llm-debugging", `🐛 ${sessionId}`);
32
+ }
33
+
34
+ pi.on("session_start", async (_event, ctx) => {
35
+ initSession(ctx);
36
+ });
37
+
38
+ pi.on("session_switch", async (_event, ctx) => {
39
+ initSession(ctx);
40
+ });
41
+
42
+ pi.on("session_fork", async (_event, ctx) => {
43
+ initSession(ctx);
44
+ });
45
+
46
+ pi.on("before_provider_request", (_event, ctx) => {
47
+ if (!outDir) initSession(ctx);
48
+ sequence++;
49
+ const filename = `${String(sequence).padStart(3, "0")}.json`;
50
+ const filepath = join(outDir, filename);
51
+ writeFileSync(filepath, JSON.stringify(_event.payload, null, 2), "utf-8");
52
+ });
53
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "pi-llm-debugging",
3
+ "version": "0.1.0",
4
+ "description": "Saves LLM provider request payloads to the project's .pi folder for per-project debugging",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/ross-jill-ws/pi-llm-debugging.git"
8
+ },
9
+ "keywords": [
10
+ "pi-package",
11
+ "debugging",
12
+ "llm",
13
+ "prompt",
14
+ "token",
15
+ "context",
16
+ "inspect",
17
+ "logging",
18
+ "tracing",
19
+ "optimization"
20
+ ],
21
+ "peerDependencies": {
22
+ "@mariozechner/pi-coding-agent": "*",
23
+ "@mariozechner/pi-tui": "*",
24
+ "@mariozechner/pi-ai": "*",
25
+ "@sinclair/typebox": "*"
26
+ },
27
+ "pi": {
28
+ "extensions": ["./extensions"]
29
+ }
30
+ }