@0xkahi/pi-qol 1.0.2 → 1.0.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/package.json +4 -4
- package/src/extensions/auto-session-name/guards.ts +17 -1
- package/src/extensions/auto-session-name/index.ts +42 -11
- package/src/schemas/auto-session-name.config.schema.ts +1 -0
- package/src/schemas/config.schema.ts +1 -0
- package/src/utils/model-resolver.util.ts +2 -2
- package/src/utils/parse-agent-content.util.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xkahi/pi-qol",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "quality of life pi extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@earendil-works/pi-tui": "*"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@earendil-works/pi-ai": "^0.
|
|
47
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
48
|
-
"@earendil-works/pi-tui": "^0.
|
|
46
|
+
"@earendil-works/pi-ai": "^0.84.0",
|
|
47
|
+
"@earendil-works/pi-coding-agent": "^0.84.0",
|
|
48
|
+
"@earendil-works/pi-tui": "^0.84.0",
|
|
49
49
|
"@biomejs/biome": "^2.4.15",
|
|
50
50
|
"@changesets/cli": "^2.31.0",
|
|
51
51
|
"@types/node": "^24.0.0",
|
|
@@ -16,7 +16,23 @@ export class AutoSessionNameGuard {
|
|
|
16
16
|
|
|
17
17
|
static isUsersFirstTurn(sessionManager: Pick<SessionManagerForGuards, 'getBranch'>): boolean {
|
|
18
18
|
// Pi emits before_agent_start before appending the current user message, so a fresh opening turn has zero prior user messages.
|
|
19
|
-
const userMsgs = sessionManager.getBranch().filter(
|
|
19
|
+
const userMsgs = sessionManager.getBranch().filter(AutoSessionNameGuard.userEntryFilter);
|
|
20
20
|
return userMsgs.length === 0;
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
static isFirstCustomExtensionMessage(sessionManager: Pick<SessionManagerForGuards, 'getBranch'>, whitelist: Set<string>): boolean {
|
|
24
|
+
const customMsg = sessionManager.getBranch().filter(entry => entry.type === 'custom_message' && whitelist.has(entry.customType));
|
|
25
|
+
return customMsg.length === 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static userEntryFilter(entry: SessionEntry) {
|
|
29
|
+
if (entry.type !== 'message') return false;
|
|
30
|
+
if (entry.message.role !== 'user') return false;
|
|
31
|
+
const { content } = entry.message;
|
|
32
|
+
if (typeof content === 'string') return content !== '';
|
|
33
|
+
if (content.length === 0) return false;
|
|
34
|
+
const onlyContent = content.length === 1 ? content[0] : undefined;
|
|
35
|
+
if (onlyContent?.type === 'text' && onlyContent.text === '') return false;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
22
38
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
2
2
|
import type { ConfigLoader } from '../../config-loader';
|
|
3
3
|
import { ModelResolver } from '../../utils/model-resolver.util';
|
|
4
|
+
// import { parseAgentContentToPrompt } from '../../utils/parse-agent-content.util';
|
|
4
5
|
import { AutoSessionNameGuard } from './guards';
|
|
5
6
|
import { AutoSessionNameTitleGenerator } from './title-generator';
|
|
6
7
|
|
|
@@ -17,15 +18,7 @@ export function registerAutoSessionName(pi: ExtensionAPI, deps: { config: Config
|
|
|
17
18
|
titleController = undefined;
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
if (!deps.config.isEnabled('auto_session_name')) return;
|
|
22
|
-
if (AutoSessionNameGuard.isSessionNameSet(pi)) return;
|
|
23
|
-
if (AutoSessionNameGuard.isChildSession({ startReason: lastSessionStartReason, manager: ctx.sessionManager })) return;
|
|
24
|
-
if (!AutoSessionNameGuard.isUsersFirstTurn(ctx.sessionManager)) return;
|
|
25
|
-
|
|
26
|
-
const userText = event.prompt?.trim();
|
|
27
|
-
if (!userText) return;
|
|
28
|
-
|
|
21
|
+
const setAutoSessionName = (ctx: ExtensionContext, text: string) => {
|
|
29
22
|
const cfg = deps.config.getAutoSessionName();
|
|
30
23
|
const configModel = cfg.enabled ? cfg.model : undefined;
|
|
31
24
|
|
|
@@ -42,7 +35,7 @@ export function registerAutoSessionName(pi: ExtensionAPI, deps: { config: Config
|
|
|
42
35
|
|
|
43
36
|
const result = await AutoSessionNameTitleGenerator.generateAndApplyTitle({
|
|
44
37
|
pi,
|
|
45
|
-
userText,
|
|
38
|
+
userText: text,
|
|
46
39
|
resolvedModel: {
|
|
47
40
|
...resolved.result,
|
|
48
41
|
reasoning: resolved.result.reasoning ?? 'minimal',
|
|
@@ -70,5 +63,43 @@ export function registerAutoSessionName(pi: ExtensionAPI, deps: { config: Config
|
|
|
70
63
|
})().catch(err => {
|
|
71
64
|
ctx.ui.notify(`(pi-qol) auto_session_name: ${JSON.stringify(err)}`, 'error');
|
|
72
65
|
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
pi.on('before_agent_start', (event, ctx) => {
|
|
69
|
+
if (!deps.config.isEnabled('auto_session_name')) return;
|
|
70
|
+
if (AutoSessionNameGuard.isSessionNameSet(pi)) return;
|
|
71
|
+
if (AutoSessionNameGuard.isChildSession({ startReason: lastSessionStartReason, manager: ctx.sessionManager })) return;
|
|
72
|
+
if (!AutoSessionNameGuard.isUsersFirstTurn(ctx.sessionManager)) return;
|
|
73
|
+
|
|
74
|
+
const userText = event.prompt?.trim();
|
|
75
|
+
if (!userText) return;
|
|
76
|
+
|
|
77
|
+
setAutoSessionName(ctx, userText);
|
|
73
78
|
});
|
|
79
|
+
|
|
80
|
+
// need fixing, currently does not work
|
|
81
|
+
// pi.on('message_start', (event, ctx) => {
|
|
82
|
+
// // ctx.ui.notify('hello0', 'info');
|
|
83
|
+
// if (!deps.config.isEnabled('auto_session_name')) return;
|
|
84
|
+
// const whitelist = new Set(deps.config.getAutoSessionName().customMessageWhitelist);
|
|
85
|
+
// // ctx.ui.notify(JSON.stringify(deps.config.getAutoSessionName()), 'warning');
|
|
86
|
+
// if (whitelist.size === 0) return;
|
|
87
|
+
// // ctx.ui.notify('hello1', 'info');
|
|
88
|
+
// const message = event.message;
|
|
89
|
+
// if (message.role !== 'custom' || !whitelist.has(message.customType)) {
|
|
90
|
+
// return;
|
|
91
|
+
// }
|
|
92
|
+
//
|
|
93
|
+
// ctx.ui.notify('hello2', 'info');
|
|
94
|
+
// if (AutoSessionNameGuard.isSessionNameSet(pi)) return;
|
|
95
|
+
// ctx.ui.notify('hello3', 'info');
|
|
96
|
+
// if (AutoSessionNameGuard.isChildSession({ startReason: lastSessionStartReason, manager: ctx.sessionManager })) return;
|
|
97
|
+
// ctx.ui.notify('hello4', 'info');
|
|
98
|
+
// if (!AutoSessionNameGuard.isFirstCustomExtensionMessage(ctx.sessionManager, whitelist)) return;
|
|
99
|
+
// ctx.ui.notify('hello5', 'info');
|
|
100
|
+
// const prompt = parseAgentContentToPrompt(message.content);
|
|
101
|
+
// ctx.ui.notify(prompt, 'info');
|
|
102
|
+
// if (!prompt) return;
|
|
103
|
+
// setAutoSessionName(ctx, prompt);
|
|
104
|
+
// });
|
|
74
105
|
}
|
|
@@ -4,6 +4,7 @@ import { ModelConfigSchema } from './shared-config.schema';
|
|
|
4
4
|
export const AutoSessionNameConfigSchema = z.object({
|
|
5
5
|
enabled: z.boolean().default(false),
|
|
6
6
|
model: ModelConfigSchema.optional(),
|
|
7
|
+
// customMessageWhitelist: z.array(z.string()).describe('a list of pi custom_messages, customType to be used to trigger auto session name'),
|
|
7
8
|
});
|
|
8
9
|
export type AutoSessionNameConfig = z.infer<typeof AutoSessionNameConfigSchema>;
|
|
9
10
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Api, Model } from '@earendil-works/pi-ai';
|
|
1
|
+
import type { Api, Model, ProviderHeaders } from '@earendil-works/pi-ai';
|
|
2
2
|
import type { ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
3
3
|
import type { ModelConfig } from '../schemas/shared-config.schema';
|
|
4
4
|
|
|
5
5
|
export type ResolvedModel = {
|
|
6
6
|
model: Model<Api>;
|
|
7
7
|
apiKey?: string;
|
|
8
|
-
headers?:
|
|
8
|
+
headers?: ProviderHeaders;
|
|
9
9
|
reasoning?: ModelConfig['reasoning'];
|
|
10
10
|
isOauth?: boolean;
|
|
11
11
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ImageContent, TextContent } from '@earendil-works/pi-ai';
|
|
2
|
+
|
|
3
|
+
export function parseAgentContentToPrompt(content: string | (TextContent | ImageContent)[]): string {
|
|
4
|
+
if (typeof content === 'string') return content;
|
|
5
|
+
|
|
6
|
+
return content
|
|
7
|
+
.filter((block): block is TextContent => block.type === 'text')
|
|
8
|
+
.map(block => block.text)
|
|
9
|
+
.join('');
|
|
10
|
+
}
|