pi-smart-sessions 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HazAT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # pi-smart-sessions
2
+
3
+ A [Pi](https://github.com/badlogic/pi) extension that automatically names your sessions with AI-generated summaries. No more scrolling through a wall of skill tags in your session list.
4
+
5
+ ## Before
6
+
7
+ Every skill session looks the same — impossible to tell them apart:
8
+
9
+ ![Before — all sessions show raw skill tags](assets/before.png)
10
+
11
+ ## After
12
+
13
+ Each session gets a short, meaningful name:
14
+
15
+ ![After — sessions have AI-generated summaries](assets/after.png)
16
+
17
+ The name is a skill prefix plus a 5–10 word summary of your prompt:
18
+
19
+ ![Session name close-up](assets/session-name.png)
20
+
21
+ ## How it works
22
+
23
+ 1. Detects when you start a session with `/skill:name your prompt here`
24
+ 2. Immediately sets a temporary name with the first 60 characters
25
+ 3. Calls a cheap model (Codex mini → Haiku → current model) to summarize your prompt in 5–10 words
26
+ 4. Updates the session name with the AI summary, prefixed by the skill name
27
+
28
+ The summarization happens in the background — no delay to your workflow. If the model call fails, the truncated name is kept as a fallback.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pi install npm:pi-smart-sessions
34
+ ```
35
+
36
+ Or try it without installing:
37
+
38
+ ```bash
39
+ pi -e npm:pi-smart-sessions
40
+ ```
41
+
42
+ You can also install from git:
43
+
44
+ ```bash
45
+ pi install git:github.com/HazAT/pi-smart-sessions
46
+ ```
47
+
48
+ ## Tips
49
+
50
+ - **Existing sessions** can be renamed manually with **Ctrl+R** in the session selector
51
+ - The extension only names the first skill-based prompt per session — it won't overwrite names you set yourself
52
+ - Works with any skill, not just brainstorm
53
+
54
+ ## License
55
+
56
+ MIT
@@ -0,0 +1,88 @@
1
+ import { complete, type Model, type Api } from "@mariozechner/pi-ai";
2
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
3
+
4
+ const skillPattern = /^\/skill:(\S+)\s*([\s\S]*)/;
5
+
6
+ const SUMMARY_PROMPT =
7
+ "Summarize the user's request in 5-10 words max. Output ONLY the summary, nothing else. No quotes, no punctuation at the end.";
8
+
9
+ const CODEX_MODEL_ID = "gpt-5.1-codex-mini";
10
+ const HAIKU_MODEL_ID = "claude-haiku-4-5";
11
+
12
+ async function pickCheapModel(ctx: {
13
+ model: Model<Api> | null;
14
+ modelRegistry: {
15
+ find: (p: string, id: string) => Model<Api> | undefined;
16
+ getApiKey: (m: Model<Api>) => Promise<string | undefined>;
17
+ };
18
+ }): Promise<{ model: Model<Api>; apiKey: string } | null> {
19
+ const codex = ctx.modelRegistry.find("openai-codex", CODEX_MODEL_ID);
20
+ if (codex) {
21
+ const key = await ctx.modelRegistry.getApiKey(codex);
22
+ if (key) return { model: codex, apiKey: key };
23
+ }
24
+ const haiku = ctx.modelRegistry.find("anthropic", HAIKU_MODEL_ID);
25
+ if (haiku) {
26
+ const key = await ctx.modelRegistry.getApiKey(haiku);
27
+ if (key) return { model: haiku, apiKey: key };
28
+ }
29
+ if (ctx.model) {
30
+ const key = await ctx.modelRegistry.getApiKey(ctx.model);
31
+ if (key) return { model: ctx.model, apiKey: key };
32
+ }
33
+ return null;
34
+ }
35
+
36
+ export default function (pi: ExtensionAPI) {
37
+ let named = false;
38
+
39
+ pi.on("session_start", () => {
40
+ named = !!pi.getSessionName();
41
+ });
42
+
43
+ pi.on("input", async (event, ctx) => {
44
+ if (named) return;
45
+
46
+ const match = event.text.match(skillPattern);
47
+ if (!match) return;
48
+
49
+ const skillName = match[1];
50
+ const userPrompt = match[2].trim();
51
+ named = true;
52
+
53
+ if (!userPrompt) {
54
+ pi.setSessionName(`[${skillName}]`);
55
+ return;
56
+ }
57
+
58
+ // Set a temporary name immediately so something shows up
59
+ pi.setSessionName(`[${skillName}] ${userPrompt.slice(0, 60)}`);
60
+
61
+ // Summarize in the background with a cheap model
62
+ const cheap = await pickCheapModel(ctx);
63
+ if (!cheap) return;
64
+
65
+ try {
66
+ const response = await complete(
67
+ cheap.model,
68
+ {
69
+ systemPrompt: SUMMARY_PROMPT,
70
+ messages: [{ role: "user", content: [{ type: "text", text: userPrompt }], timestamp: Date.now() }],
71
+ },
72
+ { apiKey: cheap.apiKey },
73
+ );
74
+
75
+ const summary = response.content
76
+ .filter((c): c is { type: "text"; text: string } => c.type === "text")
77
+ .map((c) => c.text)
78
+ .join("")
79
+ .trim();
80
+
81
+ if (summary) {
82
+ pi.setSessionName(`[${skillName}] ${summary}`);
83
+ }
84
+ } catch {
85
+ // Keep the truncated name, no big deal
86
+ }
87
+ });
88
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "pi-smart-sessions",
3
+ "version": "1.0.0",
4
+ "description": "Auto-names Pi sessions with AI-generated summaries — no more cryptic skill tags in your session list",
5
+ "keywords": ["pi-package", "pi-extension", "sessions", "skills"],
6
+ "license": "MIT",
7
+ "author": "HazAT",
8
+ "homepage": "https://github.com/HazAT/pi-smart-sessions#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/HazAT/pi-smart-sessions"
12
+ },
13
+ "files": [
14
+ "extensions",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "peerDependencies": {
19
+ "@mariozechner/pi-coding-agent": "*",
20
+ "@mariozechner/pi-ai": "*"
21
+ },
22
+ "pi": {
23
+ "extensions": ["./extensions"]
24
+ }
25
+ }