@bacnh85/pi-serena 0.3.0 → 0.3.2
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 +13 -2
- package/lib/detect.ts +56 -0
- package/package.json +3 -2
package/index.ts
CHANGED
|
@@ -150,6 +150,9 @@ export function normalizeSearchPatternParams(params: Record<string, unknown>): R
|
|
|
150
150
|
normalized.substring_pattern = normalized.pattern;
|
|
151
151
|
}
|
|
152
152
|
delete normalized.pattern;
|
|
153
|
+
// The Python SearchForPatternTool.apply() does not accept a multiline parameter.
|
|
154
|
+
// Strip it here to avoid TypeError when the parameter description says "when supported by Serena".
|
|
155
|
+
delete normalized.multiline;
|
|
153
156
|
return normalized;
|
|
154
157
|
}
|
|
155
158
|
|
|
@@ -206,8 +209,16 @@ function truncateText(text: string): string {
|
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
function resultText(response: SerenaWorkerResponse): string {
|
|
209
|
-
|
|
210
|
-
|
|
212
|
+
if (!response.ok) {
|
|
213
|
+
return `Error: ${response.error ?? "Unknown Serena error"}`;
|
|
214
|
+
}
|
|
215
|
+
// For search results, show a friendly empty-state instead of raw "{}".
|
|
216
|
+
if (response.tool === "search_for_pattern") {
|
|
217
|
+
if (response.result == null || (typeof response.result === "object" && Object.keys(response.result as object).length === 0)) {
|
|
218
|
+
return "No results found.";
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return typeof response.result === "string" ? response.result : JSON.stringify(response, null, 2);
|
|
211
222
|
}
|
|
212
223
|
|
|
213
224
|
export default function serenaToolsExtension(pi: ExtensionAPI) {
|
package/lib/detect.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure detection logic for code-vs-non-code and semantic-search-vs-text-search decisions.
|
|
3
|
+
* Extracted from index.ts so it can be tested without importing pi-coding-agent.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const CODE_FILE_EXTENSIONS = new Set([
|
|
7
|
+
".c",
|
|
8
|
+
".cc",
|
|
9
|
+
".cpp",
|
|
10
|
+
".cs",
|
|
11
|
+
".css",
|
|
12
|
+
".go",
|
|
13
|
+
".java",
|
|
14
|
+
".js",
|
|
15
|
+
".jsx",
|
|
16
|
+
".kt",
|
|
17
|
+
".lua",
|
|
18
|
+
".mjs",
|
|
19
|
+
".php",
|
|
20
|
+
".py",
|
|
21
|
+
".rb",
|
|
22
|
+
".rs",
|
|
23
|
+
".scala",
|
|
24
|
+
".sh",
|
|
25
|
+
".swift",
|
|
26
|
+
".ts",
|
|
27
|
+
".tsx",
|
|
28
|
+
".vue",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const NON_SEMANTIC_FILE_EXTENSIONS = new Set([".json", ".jsonl", ".lock", ".md", ".txt", ".yaml", ".yml"]);
|
|
32
|
+
|
|
33
|
+
export const SEMANTIC_MISS_THRESHOLD = 2;
|
|
34
|
+
|
|
35
|
+
export function pathLooksLikeCode(value: unknown): boolean {
|
|
36
|
+
if (typeof value !== "string" || value.trim() === "") return false;
|
|
37
|
+
const cleanPath = value.split(/[?#]/, 1)[0].toLowerCase();
|
|
38
|
+
const dotIndex = cleanPath.lastIndexOf(".");
|
|
39
|
+
if (dotIndex < 0) return false;
|
|
40
|
+
return CODE_FILE_EXTENSIONS.has(cleanPath.slice(dotIndex));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function pathLooksNonSemantic(value: unknown): boolean {
|
|
44
|
+
if (typeof value !== "string" || value.trim() === "") return false;
|
|
45
|
+
const cleanPath = value.split(/[?#]/, 1)[0].toLowerCase();
|
|
46
|
+
const dotIndex = cleanPath.lastIndexOf(".");
|
|
47
|
+
if (dotIndex < 0) return false;
|
|
48
|
+
return NON_SEMANTIC_FILE_EXTENSIONS.has(cleanPath.slice(dotIndex));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function commandLooksLikeSemanticCodeSearch(command: string): boolean {
|
|
52
|
+
if (!/\b(rg|grep|fd|find)\b/.test(command)) return false;
|
|
53
|
+
if (/\b(SKILL\.md|README\.md|AGENTS\.md|package\.json|skill-registry\.json|skill-history\.jsonl)\b/i.test(command)) return false;
|
|
54
|
+
if (/\b(symbol|class|method|function|def|interface|references?|implementation|declaration|rename|refactor)\b/i.test(command)) return true;
|
|
55
|
+
return /\.(c|cc|cpp|cs|go|java|js|jsx|kt|lua|mjs|php|py|rb|rs|scala|sh|swift|ts|tsx|vue)\b/i.test(command);
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bacnh85/pi-serena",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Pi extension that provides Serena semantic code tools through a persistent worker.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"README.md",
|
|
26
26
|
"index.ts",
|
|
27
|
-
"worker.ts"
|
|
27
|
+
"worker.ts",
|
|
28
|
+
"lib/"
|
|
28
29
|
],
|
|
29
30
|
"pi": {
|
|
30
31
|
"extensions": [
|