@hasna/terminal 3.7.2 → 3.7.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/dist/mcp/server.js +15 -13
- package/package.json +1 -1
- package/src/mcp/server.ts +18 -16
package/dist/mcp/server.js
CHANGED
|
@@ -578,12 +578,14 @@ export function createServer() {
|
|
|
578
578
|
return { content: [{ type: "text", text: JSON.stringify({ error: `Cannot read ${filePath}` }) }] };
|
|
579
579
|
}
|
|
580
580
|
// AI extracts symbols — works for ANY language
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
581
|
+
let symbols = [];
|
|
582
|
+
try {
|
|
583
|
+
const provider = getOutputProvider();
|
|
584
|
+
const outputModel = provider.name === "groq" ? "llama-3.1-8b-instant" : undefined;
|
|
585
|
+
const content = result.content.length > 8000 ? result.content.slice(0, 8000) : result.content;
|
|
586
|
+
const summary = await provider.complete(`File: ${filePath}\n\n${content}`, {
|
|
587
|
+
model: outputModel,
|
|
588
|
+
system: `Extract all symbols from this source file. Return ONLY a JSON array, no explanation.
|
|
587
589
|
|
|
588
590
|
Each symbol: {"name": "symbolName", "kind": "function|class|method|interface|type|variable|export", "line": lineNumber, "signature": "brief signature"}
|
|
589
591
|
|
|
@@ -591,17 +593,17 @@ For class methods, use "ClassName.methodName" as name with kind "method".
|
|
|
591
593
|
Include: functions, classes, methods, interfaces, types, exported constants.
|
|
592
594
|
Exclude: imports, local variables, comments.
|
|
593
595
|
Line numbers must be accurate (count from 1).`,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
// Parse AI response
|
|
598
|
-
let symbols = [];
|
|
599
|
-
try {
|
|
596
|
+
maxTokens: 2000,
|
|
597
|
+
temperature: 0,
|
|
598
|
+
});
|
|
600
599
|
const jsonMatch = summary.match(/\[[\s\S]*\]/);
|
|
601
600
|
if (jsonMatch)
|
|
602
601
|
symbols = JSON.parse(jsonMatch[0]);
|
|
603
602
|
}
|
|
604
|
-
catch {
|
|
603
|
+
catch (err) {
|
|
604
|
+
// Surface the error instead of silently returning []
|
|
605
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: `AI symbol extraction failed: ${err.message?.slice(0, 200)}`, file: filePath }) }] };
|
|
606
|
+
}
|
|
605
607
|
const outputTokens = estimateTokens(result.content);
|
|
606
608
|
const symbolTokens = estimateTokens(JSON.stringify(symbols));
|
|
607
609
|
logCall("symbols", { command: filePath, outputTokens, tokensSaved: Math.max(0, outputTokens - symbolTokens), durationMs: Date.now() - start, aiProcessed: true });
|
package/package.json
CHANGED
package/src/mcp/server.ts
CHANGED
|
@@ -800,14 +800,16 @@ export function createServer(): McpServer {
|
|
|
800
800
|
}
|
|
801
801
|
|
|
802
802
|
// AI extracts symbols — works for ANY language
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
803
|
+
let symbols: any[] = [];
|
|
804
|
+
try {
|
|
805
|
+
const provider = getOutputProvider();
|
|
806
|
+
const outputModel = provider.name === "groq" ? "llama-3.1-8b-instant" : undefined;
|
|
807
|
+
const content = result.content.length > 8000 ? result.content.slice(0, 8000) : result.content;
|
|
808
|
+
const summary = await provider.complete(
|
|
809
|
+
`File: ${filePath}\n\n${content}`,
|
|
810
|
+
{
|
|
811
|
+
model: outputModel,
|
|
812
|
+
system: `Extract all symbols from this source file. Return ONLY a JSON array, no explanation.
|
|
811
813
|
|
|
812
814
|
Each symbol: {"name": "symbolName", "kind": "function|class|method|interface|type|variable|export", "line": lineNumber, "signature": "brief signature"}
|
|
813
815
|
|
|
@@ -815,17 +817,17 @@ For class methods, use "ClassName.methodName" as name with kind "method".
|
|
|
815
817
|
Include: functions, classes, methods, interfaces, types, exported constants.
|
|
816
818
|
Exclude: imports, local variables, comments.
|
|
817
819
|
Line numbers must be accurate (count from 1).`,
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
820
|
+
maxTokens: 2000,
|
|
821
|
+
temperature: 0,
|
|
822
|
+
}
|
|
823
|
+
);
|
|
822
824
|
|
|
823
|
-
// Parse AI response
|
|
824
|
-
let symbols: any[] = [];
|
|
825
|
-
try {
|
|
826
825
|
const jsonMatch = summary.match(/\[[\s\S]*\]/);
|
|
827
826
|
if (jsonMatch) symbols = JSON.parse(jsonMatch[0]);
|
|
828
|
-
} catch {
|
|
827
|
+
} catch (err: any) {
|
|
828
|
+
// Surface the error instead of silently returning []
|
|
829
|
+
return { content: [{ type: "text" as const, text: JSON.stringify({ error: `AI symbol extraction failed: ${err.message?.slice(0, 200)}`, file: filePath }) }] };
|
|
830
|
+
}
|
|
829
831
|
|
|
830
832
|
const outputTokens = estimateTokens(result.content);
|
|
831
833
|
const symbolTokens = estimateTokens(JSON.stringify(symbols));
|