pi-auto-session-title 0.1.2 → 0.1.3
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/index.ts +43 -13
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -16,6 +16,30 @@ function textFromContent(content: unknown): string {
|
|
|
16
16
|
.join("\n");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function hasTitleworthyUserPrompt(
|
|
20
|
+
entries: Array<{ message: { role: string; content?: unknown } }>,
|
|
21
|
+
): boolean {
|
|
22
|
+
const userText = entries
|
|
23
|
+
.filter((entry) => entry.message.role === "user")
|
|
24
|
+
.map((entry) => textFromContent(entry.message.content).trim())
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(" ")
|
|
27
|
+
.replace(/\s+/g, " ")
|
|
28
|
+
.trim();
|
|
29
|
+
|
|
30
|
+
if (!userText) return false;
|
|
31
|
+
|
|
32
|
+
const normalized = userText
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.replace(/[^a-z0-9\s]/g, " ")
|
|
35
|
+
.replace(/\s+/g, " ")
|
|
36
|
+
.trim();
|
|
37
|
+
|
|
38
|
+
return !/^(?:hi|hello|hey|yo|sup|test|testing|thanks|thank you|ok|okay|bye|goodbye)$/.test(
|
|
39
|
+
normalized,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
19
43
|
function cleanTitle(raw: string): string | undefined {
|
|
20
44
|
const title = raw
|
|
21
45
|
.split("\n")
|
|
@@ -40,20 +64,25 @@ export default function (pi: ExtensionAPI) {
|
|
|
40
64
|
|
|
41
65
|
pi.on("agent_settled", async (_event, ctx) => {
|
|
42
66
|
if (attempted || pi.getSessionName() || !ctx.model) return;
|
|
67
|
+
|
|
68
|
+
const messages = ctx.sessionManager.getBranch().filter(
|
|
69
|
+
(
|
|
70
|
+
entry,
|
|
71
|
+
): entry is typeof entry & {
|
|
72
|
+
message: { role: string; content?: unknown };
|
|
73
|
+
} =>
|
|
74
|
+
entry.type === "message" &&
|
|
75
|
+
"role" in entry.message &&
|
|
76
|
+
(entry.message.role === "user" || entry.message.role === "assistant"),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Avoid forcing the model to invent specificity for content-free sessions.
|
|
80
|
+
// Do not mark the attempt complete, so a later substantive prompt can retry.
|
|
81
|
+
if (!hasTitleworthyUserPrompt(messages)) return;
|
|
82
|
+
|
|
43
83
|
attempted = true;
|
|
44
84
|
|
|
45
|
-
const conversation =
|
|
46
|
-
.getBranch()
|
|
47
|
-
.filter(
|
|
48
|
-
(
|
|
49
|
-
entry,
|
|
50
|
-
): entry is typeof entry & {
|
|
51
|
-
message: { role: string; content?: unknown };
|
|
52
|
-
} =>
|
|
53
|
-
entry.type === "message" &&
|
|
54
|
-
"role" in entry.message &&
|
|
55
|
-
(entry.message.role === "user" || entry.message.role === "assistant"),
|
|
56
|
-
)
|
|
85
|
+
const conversation = messages
|
|
57
86
|
.slice(-10)
|
|
58
87
|
.map((entry) => {
|
|
59
88
|
const text = textFromContent(entry.message.content)
|
|
@@ -72,7 +101,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
72
101
|
ctx.model,
|
|
73
102
|
{
|
|
74
103
|
systemPrompt:
|
|
75
|
-
"Write a specific, searchable 3-7 word title
|
|
104
|
+
"Write a specific, searchable 3-7 word title grounded only in the supplied " +
|
|
105
|
+
"conversation. Never invent technologies, tasks, or details not present in it. " +
|
|
76
106
|
"Return only the title with no quotes, markdown, or prefix.",
|
|
77
107
|
messages: [
|
|
78
108
|
{
|