pybao-cli 1.3.83 → 1.3.84
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/REPL-FGFUX54P.js +47 -0
- package/dist/{acp-OWNA2GOE.js → acp-2L5UIDYK.js} +37 -36
- package/dist/{acp-OWNA2GOE.js.map → acp-2L5UIDYK.js.map} +1 -1
- package/dist/{agentsValidate-UC7SD3JY.js → agentsValidate-G5UPCE23.js} +7 -7
- package/dist/{ask-6ESDLRIC.js → ask-NC5FHXVG.js} +32 -27
- package/dist/{ask-6ESDLRIC.js.map → ask-NC5FHXVG.js.map} +1 -1
- package/dist/{autoUpdater-FAKGXOY4.js → autoUpdater-4RF2CRK5.js} +3 -3
- package/dist/blockParser-QPLEX5NJ.js +9 -0
- package/dist/chunk-42L6OJOC.js +1832 -0
- package/dist/chunk-42L6OJOC.js.map +7 -0
- package/dist/{chunk-B3MDT4F6.js → chunk-46KUA6OA.js} +5 -5
- package/dist/{chunk-XC4AJGEW.js → chunk-6WOCAHEK.js} +1 -1
- package/dist/{chunk-BPZ44BIE.js → chunk-7HP3UEMN.js} +1 -1
- package/dist/{chunk-SSPEL7MF.js → chunk-7TIDBKNN.js} +3 -3
- package/dist/{chunk-FH5VPA4M.js → chunk-7WMAUFRG.js} +1 -1
- package/dist/{chunk-JGJCX75W.js → chunk-7YPF7IZE.js} +7 -5
- package/dist/chunk-7YPF7IZE.js.map +7 -0
- package/dist/{chunk-HMCPTTVR.js → chunk-C3HV2RX2.js} +3 -3
- package/dist/{chunk-HIH43UEF.js → chunk-CSRNWBXQ.js} +2 -2
- package/dist/{chunk-6VOYUVQU.js → chunk-FJRJWV7O.js} +7 -7
- package/dist/{chunk-ZEMFBGPE.js → chunk-FKAYIROZ.js} +2 -2
- package/dist/{chunk-ZZO2YNJG.js → chunk-GFKRGL22.js} +1 -1
- package/dist/{chunk-43ZJOQDX.js → chunk-JJEJMLIT.js} +1123 -1297
- package/dist/chunk-JJEJMLIT.js.map +7 -0
- package/dist/{chunk-NNNU5K5N.js → chunk-KDKEJCIA.js} +2 -2
- package/dist/{chunk-TNJTMN23.js → chunk-KHMW5FJP.js} +1 -1
- package/dist/{chunk-XJDZTRBL.js → chunk-LZHKCLLB.js} +3 -3
- package/dist/{chunk-SYHWDS75.js → chunk-MN5A3I5G.js} +1 -1
- package/dist/{chunk-WU4VY7XT.js → chunk-MUQI2KCA.js} +2 -2
- package/dist/chunk-NEG6NKKM.js +1834 -0
- package/dist/chunk-NEG6NKKM.js.map +7 -0
- package/dist/{chunk-NIKESYZF.js → chunk-OVROGAUW.js} +2 -2
- package/dist/{chunk-3BP3TGGN.js → chunk-PC33U2HP.js} +1 -1
- package/dist/{chunk-3BP3TGGN.js.map → chunk-PC33U2HP.js.map} +1 -1
- package/dist/{chunk-MSWBIZZC.js → chunk-PPIHT4XC.js} +5 -5
- package/dist/{blockParser-CFQE5IAN.js → chunk-QWIBSCDN.js} +1 -1
- package/dist/{blockParser-CFQE5IAN.js.map → chunk-QWIBSCDN.js.map} +1 -1
- package/dist/{chunk-HCPU4TQ6.js → chunk-SB5WQNSQ.js} +1 -1
- package/dist/{chunk-CPOVPGCU.js → chunk-SOGXQEV2.js} +7 -7
- package/dist/{chunk-SWY5TLOX.js → chunk-TACMGUAN.js} +155 -1228
- package/dist/chunk-TACMGUAN.js.map +7 -0
- package/dist/{chunk-FOQKIQ27.js → chunk-UQHYTY5X.js} +3 -3
- package/dist/chunk-W2SGOL2K.js +364 -0
- package/dist/chunk-W2SGOL2K.js.map +7 -0
- package/dist/{chunk-L62UDJSU.js → chunk-WPA4GCGG.js} +168 -1
- package/dist/{chunk-L62UDJSU.js.map → chunk-WPA4GCGG.js.map} +3 -3
- package/dist/chunk-XI4LTVYT.js +17 -0
- package/dist/chunk-XI4LTVYT.js.map +7 -0
- package/dist/{chunk-WCR6QGXF.js → chunk-YCIGVKJU.js} +4 -4
- package/dist/{chunk-MFNDDM3V.js → chunk-ZIEALAFY.js} +1 -1
- package/dist/{cli-EASV6IY7.js → cli-MWA546KO.js} +206 -91
- package/dist/cli-MWA546KO.js.map +7 -0
- package/dist/commands-JMPWEXWX.js +51 -0
- package/dist/{config-53WMBY35.js → config-JOHT6J75.js} +4 -4
- package/dist/{context-GNSAANSR.js → context-CPFQPWH5.js} +5 -5
- package/dist/{customCommands-TI7KC7QR.js → customCommands-K5AGAFXB.js} +4 -4
- package/dist/{env-7GAPXLOS.js → env-CEU3W5ME.js} +6 -4
- package/dist/file-QZ3DYDGR.js +44 -0
- package/dist/index.js +3 -3
- package/dist/{chunk-FL4UY5X6.js → llm-RBX2F2S4.js} +68 -32
- package/dist/llm-RBX2F2S4.js.map +7 -0
- package/dist/{llmLazy-JT5FOMWS.js → llmLazy-BIN2DEC2.js} +1 -1
- package/dist/{loader-FVGZ4Q4O.js → loader-CV7OJ4NZ.js} +4 -4
- package/dist/lsp-QFZEUOOA.js +17 -0
- package/dist/{lspAnchor-2ESTEKDW.js → lspAnchor-Q2QPAITR.js} +8 -10
- package/dist/lspAnchor-Q2QPAITR.js.map +7 -0
- package/dist/{mcp-DXRJFV2Z.js → mcp-JM5OIHPD.js} +7 -7
- package/dist/{mentionProcessor-24DFMNUM.js → mentionProcessor-4LMVOVGA.js} +5 -5
- package/dist/{messages-44UB3QCF.js → messages-XW74FZX6.js} +1 -1
- package/dist/{model-2MO4JM7C.js → model-RJINKACR.js} +5 -5
- package/dist/{openai-IW2EECJN.js → openai-66PYA2FX.js} +5 -5
- package/dist/{outputStyles-OFVM7RO6.js → outputStyles-MV6ZVKVT.js} +4 -4
- package/dist/{pluginRuntime-L2ORBVPC.js → pluginRuntime-BCOVUPBE.js} +6 -6
- package/dist/{pluginValidation-S5YXDUDC.js → pluginValidation-3E6ZTNSH.js} +6 -6
- package/dist/prompts-CQXW5O3Z.js +53 -0
- package/dist/{pybAgentSessionLoad-NM2FSUHI.js → pybAgentSessionLoad-CKCBOT52.js} +4 -4
- package/dist/{pybAgentSessionResume-R6DFJVOS.js → pybAgentSessionResume-LDUO3VEW.js} +4 -4
- package/dist/{pybAgentStreamJsonSession-IYC73GWN.js → pybAgentStreamJsonSession-5XVEA5BE.js} +1 -1
- package/dist/{pybHooks-BNGLUIBL.js → pybHooks-JTBESPF6.js} +4 -4
- package/dist/query-Z3URPE24.js +55 -0
- package/dist/registry-2K7ZNIJX.js +47 -0
- package/dist/{ripgrep-QZG3RMUD.js → ripgrep-RJWD3Z7N.js} +3 -3
- package/dist/{skillMarketplace-IRUF6M5M.js → skillMarketplace-ZDWIN663.js} +3 -3
- package/dist/{state-LSDUZCQZ.js → state-XOHPGE2O.js} +2 -2
- package/dist/{theme-QVGQSEFJ.js → theme-B672GYQW.js} +5 -5
- package/dist/{toolPermissionSettings-U4P7K6VA.js → toolPermissionSettings-IGFHXHH7.js} +6 -6
- package/dist/toolPermissionSettings-IGFHXHH7.js.map +7 -0
- package/dist/tools-4SXRMJGJ.js +52 -0
- package/dist/tools-4SXRMJGJ.js.map +7 -0
- package/dist/{userInput-EP4A6TDN.js → userInput-6CV2RY5H.js} +34 -29
- package/dist/{userInput-EP4A6TDN.js.map → userInput-6CV2RY5H.js.map} +1 -1
- package/package.json +1 -1
- package/dist/REPL-HVMZDW6I.js +0 -42
- package/dist/chunk-43ZJOQDX.js.map +0 -7
- package/dist/chunk-FL4UY5X6.js.map +0 -7
- package/dist/chunk-JGJCX75W.js.map +0 -7
- package/dist/chunk-PBPAGOFN.js +0 -929
- package/dist/chunk-PBPAGOFN.js.map +0 -7
- package/dist/chunk-SWY5TLOX.js.map +0 -7
- package/dist/cli-EASV6IY7.js.map +0 -7
- package/dist/commands-LHZ4KLGY.js +0 -46
- package/dist/llm-24PI2Z6V.js +0 -80
- package/dist/lspAnchor-2ESTEKDW.js.map +0 -7
- package/dist/manager-B7QOH5CJ.js +0 -13
- package/dist/prompts-7PXTK55Q.js +0 -48
- package/dist/query-OLRMI42V.js +0 -50
- package/dist/tools-LSBTQYU4.js +0 -51
- /package/dist/{REPL-HVMZDW6I.js.map → REPL-FGFUX54P.js.map} +0 -0
- /package/dist/{agentsValidate-UC7SD3JY.js.map → agentsValidate-G5UPCE23.js.map} +0 -0
- /package/dist/{autoUpdater-FAKGXOY4.js.map → autoUpdater-4RF2CRK5.js.map} +0 -0
- /package/dist/{commands-LHZ4KLGY.js.map → blockParser-QPLEX5NJ.js.map} +0 -0
- /package/dist/{chunk-B3MDT4F6.js.map → chunk-46KUA6OA.js.map} +0 -0
- /package/dist/{chunk-XC4AJGEW.js.map → chunk-6WOCAHEK.js.map} +0 -0
- /package/dist/{chunk-BPZ44BIE.js.map → chunk-7HP3UEMN.js.map} +0 -0
- /package/dist/{chunk-SSPEL7MF.js.map → chunk-7TIDBKNN.js.map} +0 -0
- /package/dist/{chunk-FH5VPA4M.js.map → chunk-7WMAUFRG.js.map} +0 -0
- /package/dist/{chunk-HMCPTTVR.js.map → chunk-C3HV2RX2.js.map} +0 -0
- /package/dist/{chunk-HIH43UEF.js.map → chunk-CSRNWBXQ.js.map} +0 -0
- /package/dist/{chunk-6VOYUVQU.js.map → chunk-FJRJWV7O.js.map} +0 -0
- /package/dist/{chunk-ZEMFBGPE.js.map → chunk-FKAYIROZ.js.map} +0 -0
- /package/dist/{chunk-ZZO2YNJG.js.map → chunk-GFKRGL22.js.map} +0 -0
- /package/dist/{chunk-NNNU5K5N.js.map → chunk-KDKEJCIA.js.map} +0 -0
- /package/dist/{chunk-TNJTMN23.js.map → chunk-KHMW5FJP.js.map} +0 -0
- /package/dist/{chunk-XJDZTRBL.js.map → chunk-LZHKCLLB.js.map} +0 -0
- /package/dist/{chunk-SYHWDS75.js.map → chunk-MN5A3I5G.js.map} +0 -0
- /package/dist/{chunk-WU4VY7XT.js.map → chunk-MUQI2KCA.js.map} +0 -0
- /package/dist/{chunk-NIKESYZF.js.map → chunk-OVROGAUW.js.map} +0 -0
- /package/dist/{chunk-MSWBIZZC.js.map → chunk-PPIHT4XC.js.map} +0 -0
- /package/dist/{chunk-HCPU4TQ6.js.map → chunk-SB5WQNSQ.js.map} +0 -0
- /package/dist/{chunk-CPOVPGCU.js.map → chunk-SOGXQEV2.js.map} +0 -0
- /package/dist/{chunk-FOQKIQ27.js.map → chunk-UQHYTY5X.js.map} +0 -0
- /package/dist/{chunk-WCR6QGXF.js.map → chunk-YCIGVKJU.js.map} +0 -0
- /package/dist/{chunk-MFNDDM3V.js.map → chunk-ZIEALAFY.js.map} +0 -0
- /package/dist/{config-53WMBY35.js.map → commands-JMPWEXWX.js.map} +0 -0
- /package/dist/{context-GNSAANSR.js.map → config-JOHT6J75.js.map} +0 -0
- /package/dist/{customCommands-TI7KC7QR.js.map → context-CPFQPWH5.js.map} +0 -0
- /package/dist/{env-7GAPXLOS.js.map → customCommands-K5AGAFXB.js.map} +0 -0
- /package/dist/{llm-24PI2Z6V.js.map → env-CEU3W5ME.js.map} +0 -0
- /package/dist/{llmLazy-JT5FOMWS.js.map → file-QZ3DYDGR.js.map} +0 -0
- /package/dist/{loader-FVGZ4Q4O.js.map → llmLazy-BIN2DEC2.js.map} +0 -0
- /package/dist/{manager-B7QOH5CJ.js.map → loader-CV7OJ4NZ.js.map} +0 -0
- /package/dist/{mcp-DXRJFV2Z.js.map → lsp-QFZEUOOA.js.map} +0 -0
- /package/dist/{messages-44UB3QCF.js.map → mcp-JM5OIHPD.js.map} +0 -0
- /package/dist/{mentionProcessor-24DFMNUM.js.map → mentionProcessor-4LMVOVGA.js.map} +0 -0
- /package/dist/{model-2MO4JM7C.js.map → messages-XW74FZX6.js.map} +0 -0
- /package/dist/{openai-IW2EECJN.js.map → model-RJINKACR.js.map} +0 -0
- /package/dist/{outputStyles-OFVM7RO6.js.map → openai-66PYA2FX.js.map} +0 -0
- /package/dist/{pluginValidation-S5YXDUDC.js.map → outputStyles-MV6ZVKVT.js.map} +0 -0
- /package/dist/{pluginRuntime-L2ORBVPC.js.map → pluginRuntime-BCOVUPBE.js.map} +0 -0
- /package/dist/{prompts-7PXTK55Q.js.map → pluginValidation-3E6ZTNSH.js.map} +0 -0
- /package/dist/{pybAgentSessionLoad-NM2FSUHI.js.map → prompts-CQXW5O3Z.js.map} +0 -0
- /package/dist/{pybAgentSessionResume-R6DFJVOS.js.map → pybAgentSessionLoad-CKCBOT52.js.map} +0 -0
- /package/dist/{pybHooks-BNGLUIBL.js.map → pybAgentSessionResume-LDUO3VEW.js.map} +0 -0
- /package/dist/{pybAgentStreamJsonSession-IYC73GWN.js.map → pybAgentStreamJsonSession-5XVEA5BE.js.map} +0 -0
- /package/dist/{query-OLRMI42V.js.map → pybHooks-JTBESPF6.js.map} +0 -0
- /package/dist/{ripgrep-QZG3RMUD.js.map → query-Z3URPE24.js.map} +0 -0
- /package/dist/{skillMarketplace-IRUF6M5M.js.map → registry-2K7ZNIJX.js.map} +0 -0
- /package/dist/{state-LSDUZCQZ.js.map → ripgrep-RJWD3Z7N.js.map} +0 -0
- /package/dist/{theme-QVGQSEFJ.js.map → skillMarketplace-ZDWIN663.js.map} +0 -0
- /package/dist/{toolPermissionSettings-U4P7K6VA.js.map → state-XOHPGE2O.js.map} +0 -0
- /package/dist/{tools-LSBTQYU4.js.map → theme-B672GYQW.js.map} +0 -0
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { createRequire as __pybCreateRequire } from "node:module";
|
|
2
2
|
const require = __pybCreateRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
queryQuick
|
|
5
|
-
} from "./chunk-FL4UY5X6.js";
|
|
6
3
|
import {
|
|
7
4
|
AskUserQuestionTool,
|
|
8
5
|
BashTool,
|
|
@@ -16,63 +13,67 @@ import {
|
|
|
16
13
|
GrepTool,
|
|
17
14
|
KillShellTool,
|
|
18
15
|
NotebookEditTool,
|
|
19
|
-
ParserRegistry,
|
|
20
16
|
SkillTool,
|
|
21
17
|
SlashCommandTool,
|
|
22
18
|
TodoWriteTool,
|
|
19
|
+
WebSearchTool,
|
|
23
20
|
applyMarkdown,
|
|
24
21
|
countTokens,
|
|
25
|
-
getAbsolutePath,
|
|
26
22
|
getAgentPrompt,
|
|
27
23
|
getMaxThinkingTokens,
|
|
28
24
|
hasPermissionsToUseTool,
|
|
29
25
|
hasReadPermission,
|
|
30
26
|
hasWritePermission,
|
|
31
|
-
loadLanguage,
|
|
32
27
|
query
|
|
33
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-JJEJMLIT.js";
|
|
34
29
|
import {
|
|
35
|
-
queryLLM
|
|
36
|
-
|
|
30
|
+
queryLLM,
|
|
31
|
+
queryQuick
|
|
32
|
+
} from "./chunk-YCIGVKJU.js";
|
|
37
33
|
import {
|
|
38
34
|
FallbackToolUseRejectedMessage,
|
|
39
35
|
MCPTool,
|
|
40
36
|
getClients,
|
|
41
37
|
getMCPTools
|
|
42
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-FJRJWV7O.js";
|
|
43
39
|
import {
|
|
44
40
|
generateAgentId
|
|
45
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-OVROGAUW.js";
|
|
46
42
|
import {
|
|
47
43
|
getActiveAgents,
|
|
48
44
|
getAgentByType,
|
|
49
45
|
getAvailableAgentTypes
|
|
50
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-KDKEJCIA.js";
|
|
51
47
|
import {
|
|
52
48
|
INTERRUPT_MESSAGE,
|
|
53
49
|
createAssistantMessage,
|
|
54
50
|
createUserMessage,
|
|
55
51
|
getLastAssistantMessageId
|
|
56
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-7HP3UEMN.js";
|
|
53
|
+
import {
|
|
54
|
+
getAbsolutePath
|
|
55
|
+
} from "./chunk-W2SGOL2K.js";
|
|
57
56
|
import {
|
|
58
57
|
filesToTree,
|
|
59
58
|
ripGrepWithStatus
|
|
60
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-SB5WQNSQ.js";
|
|
61
60
|
import {
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
LspAPI,
|
|
62
|
+
LspFacade,
|
|
63
|
+
formatDiagnosticsPretty
|
|
64
|
+
} from "./chunk-NEG6NKKM.js";
|
|
64
65
|
import {
|
|
65
66
|
getModelManager
|
|
66
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-C3HV2RX2.js";
|
|
67
68
|
import {
|
|
68
69
|
getContext
|
|
69
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-7TIDBKNN.js";
|
|
70
71
|
import {
|
|
71
72
|
getTheme
|
|
72
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-7WMAUFRG.js";
|
|
73
74
|
import {
|
|
74
75
|
debug
|
|
75
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-MN5A3I5G.js";
|
|
76
77
|
import {
|
|
77
78
|
BunShell,
|
|
78
79
|
getCwd,
|
|
@@ -81,7 +82,7 @@ import {
|
|
|
81
82
|
logError,
|
|
82
83
|
overwriteLog,
|
|
83
84
|
readTaskOutput
|
|
84
|
-
} from "./chunk-
|
|
85
|
+
} from "./chunk-WPA4GCGG.js";
|
|
85
86
|
import {
|
|
86
87
|
formatDuration,
|
|
87
88
|
formatNumber
|
|
@@ -747,9 +748,8 @@ async function analyzeOutputWithLsp(output, exitCode) {
|
|
|
747
748
|
if (warningCount > 0) parts.push(`${warningCount} Warning${warningCount === 1 ? "" : "s"}`);
|
|
748
749
|
if (exitCode !== 0) {
|
|
749
750
|
try {
|
|
750
|
-
const {
|
|
751
|
-
const {
|
|
752
|
-
const { getCwd: getCwd2 } = await import("./state-LSDUZCQZ.js");
|
|
751
|
+
const { isAbsolute: isAbsolute3, resolve: resolve4 } = await import("path");
|
|
752
|
+
const { getCwd: getCwd2 } = await import("./state-XOHPGE2O.js");
|
|
753
753
|
const lines = output.split("\n");
|
|
754
754
|
const uniqueFiles = /* @__PURE__ */ new Set();
|
|
755
755
|
const lspSuggestions = [];
|
|
@@ -770,16 +770,14 @@ async function analyzeOutputWithLsp(output, exitCode) {
|
|
|
770
770
|
}
|
|
771
771
|
for (const file of uniqueFiles) {
|
|
772
772
|
try {
|
|
773
|
-
const absPath = isAbsolute3(file) ? file :
|
|
774
|
-
await
|
|
775
|
-
const diagnostics = await
|
|
773
|
+
const absPath = isAbsolute3(file) ? file : resolve4(getCwd2(), file);
|
|
774
|
+
await LspAPI.touchFile(absPath, { wait: true, timeoutMs: 2e3 });
|
|
775
|
+
const diagnostics = await LspAPI.diagnostics(absPath);
|
|
776
776
|
if (diagnostics && diagnostics.length > 0) {
|
|
777
|
-
const
|
|
778
|
-
if (
|
|
777
|
+
const pretty = formatDiagnosticsPretty(diagnostics, { maxItems: 3 });
|
|
778
|
+
if (pretty) {
|
|
779
779
|
lspSuggestions.push(`LSP Diagnostics for ${file}:`);
|
|
780
|
-
|
|
781
|
-
lspSuggestions.push(` - Line ${d.range.start.line + 1}: ${d.message}`);
|
|
782
|
-
});
|
|
780
|
+
lspSuggestions.push(pretty);
|
|
783
781
|
}
|
|
784
782
|
}
|
|
785
783
|
} catch (e) {
|
|
@@ -804,7 +802,7 @@ async function waitForBashTaskCompletion(args) {
|
|
|
804
802
|
if (!summary) return null;
|
|
805
803
|
if (summary.status !== "running" && summary.status !== "pending")
|
|
806
804
|
return summary;
|
|
807
|
-
await new Promise((
|
|
805
|
+
await new Promise((resolve4) => setTimeout(resolve4, 100));
|
|
808
806
|
}
|
|
809
807
|
return buildTaskSummary(taskId);
|
|
810
808
|
}
|
|
@@ -1109,72 +1107,21 @@ var DeleteTool = {
|
|
|
1109
1107
|
}
|
|
1110
1108
|
if (!force) {
|
|
1111
1109
|
try {
|
|
1112
|
-
const {
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
if (client) {
|
|
1122
|
-
await client.waitForReadiness(fullPath, 1e3);
|
|
1123
|
-
const fileUri = client.normalizeUri(fullPath);
|
|
1124
|
-
const symbols = await manager.documentSymbol(fullPath, getCwd());
|
|
1125
|
-
let isReferenced = false;
|
|
1126
|
-
let refDetail = "";
|
|
1127
|
-
const checkSymbolRefs = async (sym) => {
|
|
1128
|
-
const range = sym.selectionRange || sym.range || (sym.location ? sym.location.range : null);
|
|
1129
|
-
if (!range) {
|
|
1130
|
-
return null;
|
|
1131
|
-
}
|
|
1132
|
-
const refs = await client.findReferences(fullPath, range.start.line + 1, range.start.character + 1);
|
|
1133
|
-
if (refs && Array.isArray(refs)) {
|
|
1134
|
-
const externalRefs = refs.filter((r) => r.uri !== fileUri);
|
|
1135
|
-
if (externalRefs.length > 0) {
|
|
1136
|
-
const refFiles = externalRefs.map((r) => r.uri).slice(0, 3).join(", ");
|
|
1137
|
-
return `Symbol '${sym.name}' referenced by ${externalRefs.length} locations (e.g. ${refFiles})`;
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
return null;
|
|
1141
|
-
};
|
|
1142
|
-
if (symbols === null) {
|
|
1143
|
-
if (!force) {
|
|
1144
|
-
failedItems.push(`${rawPath} (Safety Check Failed: LSP analysis error. Use 'force: true' to override.)`);
|
|
1145
|
-
continue;
|
|
1146
|
-
}
|
|
1147
|
-
} else if (symbols && Array.isArray(symbols) && symbols.length > 0) {
|
|
1148
|
-
for (const sym of symbols) {
|
|
1149
|
-
const result2 = await checkSymbolRefs(sym);
|
|
1150
|
-
if (result2) {
|
|
1151
|
-
isReferenced = true;
|
|
1152
|
-
refDetail = result2;
|
|
1153
|
-
break;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
} else {
|
|
1157
|
-
const refs = await client.findReferences(fullPath, 1, 1);
|
|
1158
|
-
if (refs && Array.isArray(refs)) {
|
|
1159
|
-
const externalRefs = refs.filter((r) => r.uri !== fileUri);
|
|
1160
|
-
if (externalRefs.length > 0) {
|
|
1161
|
-
isReferenced = true;
|
|
1162
|
-
refDetail = `File referenced by ${externalRefs.length} locations`;
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
if (isReferenced) {
|
|
1167
|
-
failedItems.push(`${rawPath} (Safety Check Failed: ${refDetail}. Use 'force: true' to override.)`);
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1110
|
+
const { LspFacade: LspFacade2 } = await import("./lsp-QFZEUOOA.js");
|
|
1111
|
+
const referenceDetail = await LspFacade2.checkFileReferences(fullPath);
|
|
1112
|
+
if (referenceDetail) {
|
|
1113
|
+
failedItems.push(
|
|
1114
|
+
`${rawPath} (Safety Check Failed: ${referenceDetail}. Use 'force: true' to override.)`
|
|
1115
|
+
);
|
|
1116
|
+
continue;
|
|
1170
1117
|
}
|
|
1171
1118
|
} catch (e) {
|
|
1172
|
-
console.error("[DeleteTool] Internal Error Details:", e);
|
|
1173
1119
|
if (!force) {
|
|
1174
|
-
failedItems.push(
|
|
1120
|
+
failedItems.push(
|
|
1121
|
+
`${rawPath} (Safety Check Failed: Internal LSP Error. Use 'force: true' to override.)`
|
|
1122
|
+
);
|
|
1175
1123
|
continue;
|
|
1176
1124
|
}
|
|
1177
|
-
console.warn(`[DeleteTool] LSP check failed for ${fullPath}, proceeding due to force: ${e.message}`);
|
|
1178
1125
|
}
|
|
1179
1126
|
}
|
|
1180
1127
|
const root = resolve(fullPath, "/");
|
|
@@ -1331,13 +1278,12 @@ import { z as z5 } from "zod";
|
|
|
1331
1278
|
import { minimatch } from "minimatch";
|
|
1332
1279
|
|
|
1333
1280
|
// src/tools/lsTool/prompt.ts
|
|
1334
|
-
var DESCRIPTION3 = `Lists files and directories as a breadth-first tree with
|
|
1281
|
+
var DESCRIPTION3 = `Lists files and directories as a breadth-first tree with minimal metadata.
|
|
1335
1282
|
|
|
1336
1283
|
Usage:
|
|
1337
|
-
1. **
|
|
1338
|
-
2. **
|
|
1339
|
-
3. **
|
|
1340
|
-
4. **Metadata Lines**: \`[LS META]\` includes \`truncated\` and \`coverage\` for reliable stitching.
|
|
1284
|
+
1. **Structure First**: Use to understand the top-level layout quickly.
|
|
1285
|
+
2. **Ignore Rules**: Use \`ignore\` to exclude noisy paths and reduce output size.
|
|
1286
|
+
3. **Metadata Lines**: \`[LS META]\` includes \`count\` and \`truncated\`.
|
|
1341
1287
|
|
|
1342
1288
|
Notes:
|
|
1343
1289
|
- Respects \`.gitignore\` by default (e.g., \`node_modules\`, \`dist\`) to keep root scans safe.
|
|
@@ -1346,24 +1292,18 @@ Notes:
|
|
|
1346
1292
|
|
|
1347
1293
|
When to use:
|
|
1348
1294
|
- First step when exploring a new project.
|
|
1349
|
-
- When you need a reliable
|
|
1295
|
+
- When you need a reliable view of the structure.
|
|
1350
1296
|
- When you feel lost in the file system.
|
|
1351
1297
|
`.trim();
|
|
1352
1298
|
|
|
1353
1299
|
// src/tools/lsTool/lsTool.tsx
|
|
1354
1300
|
var MAX_FILES_LIMIT = 1e3;
|
|
1355
|
-
var inputSchema5 = z5.
|
|
1301
|
+
var inputSchema5 = z5.object({
|
|
1356
1302
|
path: z5.string().describe(
|
|
1357
1303
|
"The absolute path to the directory to list (must be absolute, not relative)"
|
|
1358
1304
|
),
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
offset: z5.number().int().min(0).optional().describe("Offset into the stable, sorted file list."),
|
|
1362
|
-
ignore: z5.array(z5.string()).optional().describe("List of glob patterns to ignore."),
|
|
1363
|
-
semantic: z5.boolean().optional().describe(
|
|
1364
|
-
"Enable semantic annotations using LSP (e.g. [Module], [Component])."
|
|
1365
|
-
)
|
|
1366
|
-
});
|
|
1305
|
+
ignore: z5.array(z5.string()).optional().describe("List of glob patterns to ignore.")
|
|
1306
|
+
}).passthrough();
|
|
1367
1307
|
var LSTool = {
|
|
1368
1308
|
name: "LS",
|
|
1369
1309
|
async description() {
|
|
@@ -1388,19 +1328,24 @@ var LSTool = {
|
|
|
1388
1328
|
async prompt() {
|
|
1389
1329
|
return DESCRIPTION3;
|
|
1390
1330
|
},
|
|
1331
|
+
async validateInput({ limit, offset, partition }) {
|
|
1332
|
+
if (typeof limit === "number" || typeof offset === "number" || typeof partition === "string") {
|
|
1333
|
+
return {
|
|
1334
|
+
result: false,
|
|
1335
|
+
message: "LS \u5F53\u524D\u4E0D\u652F\u6301 limit/offset/partition \u53C2\u6570\u3002\u8BF7\u6309\u7167\u201C\u8DEF\u5F84\u5206\u7247\u7B56\u7565\u201D\u6309\u6839\u2192\u6838\u5FC3\u76EE\u5F55\u2192\u6A21\u5757\u5206\u591A\u6B21\u8C03\u7528\u4EE5\u8986\u76D6\u5168\u5E93\u3002",
|
|
1336
|
+
errorCode: 1
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
return { result: true };
|
|
1340
|
+
},
|
|
1391
1341
|
renderResultForAssistant(data) {
|
|
1392
1342
|
return data;
|
|
1393
1343
|
},
|
|
1394
|
-
renderToolUseMessage({ path,
|
|
1344
|
+
renderToolUseMessage({ path, ignore }, { verbose }) {
|
|
1395
1345
|
const absolutePath = path ? isAbsolute2(path) ? path : resolve2(getCwd(), path) : void 0;
|
|
1396
1346
|
const relativePath = absolutePath ? relative2(getCwd(), absolutePath) : ".";
|
|
1397
1347
|
const parts = [`path: "${verbose ? path : relativePath}"`];
|
|
1398
|
-
const effectiveSemantic = semantic ?? true;
|
|
1399
|
-
if (partition) parts.push(`partition: "${partition}"`);
|
|
1400
|
-
if (typeof limit === "number") parts.push(`limit: ${limit}`);
|
|
1401
|
-
if (typeof offset === "number") parts.push(`offset: ${offset}`);
|
|
1402
1348
|
if (ignore && ignore.length > 0) parts.push(`ignore: ${ignore.length}`);
|
|
1403
|
-
if (effectiveSemantic) parts.push("semantic: true");
|
|
1404
1349
|
return parts.join(", ");
|
|
1405
1350
|
},
|
|
1406
1351
|
renderToolUseRejectedMessage() {
|
|
@@ -1413,11 +1358,10 @@ var LSTool = {
|
|
|
1413
1358
|
}
|
|
1414
1359
|
const lines = content.split("\n");
|
|
1415
1360
|
const MAX_DISPLAY_LINES = 10;
|
|
1416
|
-
return /* @__PURE__ */ React5.createElement(Box5, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React5.createElement(Box5, null, /* @__PURE__ */ React5.createElement(Text5, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React5.createElement(Box5, { flexDirection: "column", paddingLeft: 0 }, lines.slice(0, verbose ? void 0 : MAX_DISPLAY_LINES).map((line, i) => /* @__PURE__ */ React5.createElement(
|
|
1361
|
+
return /* @__PURE__ */ React5.createElement(Box5, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React5.createElement(Box5, null, /* @__PURE__ */ React5.createElement(Text5, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React5.createElement(Box5, { flexDirection: "column", paddingLeft: 0 }, lines.slice(0, verbose ? void 0 : MAX_DISPLAY_LINES).map((line, i) => /* @__PURE__ */ React5.createElement(React5.Fragment, { key: i }, /* @__PURE__ */ React5.createElement(Text5, null, line))), !verbose && lines.length > MAX_DISPLAY_LINES && /* @__PURE__ */ React5.createElement(Text5, { color: getTheme().secondaryText }, "... (+", lines.length - MAX_DISPLAY_LINES, " lines)"))));
|
|
1417
1362
|
},
|
|
1418
|
-
async *call({ path,
|
|
1363
|
+
async *call({ path, ignore }, { abortController }) {
|
|
1419
1364
|
const fullFilePath = isAbsolute2(path) ? path : resolve2(getCwd(), path);
|
|
1420
|
-
const effectiveSemantic = semantic ?? true;
|
|
1421
1365
|
const ignoreGlobs = (ignore ?? []).filter(Boolean);
|
|
1422
1366
|
const rgArgs = ["--files", ...ignoreGlobs.flatMap((pattern) => ["--glob", `!${pattern}`])];
|
|
1423
1367
|
const initialResult = await ripGrepWithStatus(
|
|
@@ -1426,128 +1370,28 @@ var LSTool = {
|
|
|
1426
1370
|
abortController.signal
|
|
1427
1371
|
);
|
|
1428
1372
|
const files = initialResult.files;
|
|
1429
|
-
const normalizedPartition = (() => {
|
|
1430
|
-
if (!partition) return "";
|
|
1431
|
-
const rel = isAbsolute2(partition) ? relative2(fullFilePath, partition) : partition;
|
|
1432
|
-
return rel.replace(/^[./\\]+/, "").replace(/[\\/]+$/, "").split(sep2).join("/");
|
|
1433
|
-
})();
|
|
1434
1373
|
const allEntries = files.map((file) => {
|
|
1435
1374
|
const absolutePath = isAbsolute2(file) ? file : resolve2(fullFilePath, file);
|
|
1436
1375
|
const relativePath = relative2(fullFilePath, absolutePath);
|
|
1437
1376
|
const normalized = relativePath.split(sep2).join("/");
|
|
1438
1377
|
return { absolutePath, relativePath, normalized };
|
|
1439
1378
|
});
|
|
1440
|
-
const
|
|
1441
|
-
if (entry.normalized !== normalizedPartition && !entry.normalized.startsWith(`${normalizedPartition}/`)) {
|
|
1442
|
-
return false;
|
|
1443
|
-
}
|
|
1444
|
-
return true;
|
|
1445
|
-
}) : allEntries;
|
|
1446
|
-
const fileEntries = partitionEntries.filter((entry) => {
|
|
1379
|
+
const fileEntries = allEntries.filter((entry) => {
|
|
1447
1380
|
if (ignoreGlobs.length === 0) return true;
|
|
1448
1381
|
return !ignoreGlobs.some(
|
|
1449
1382
|
(pattern) => minimatch(entry.normalized, pattern, { dot: true, nocase: false })
|
|
1450
1383
|
);
|
|
1451
1384
|
}).sort((a, b) => a.normalized.localeCompare(b.normalized));
|
|
1452
1385
|
const totalCount = fileEntries.length;
|
|
1453
|
-
const
|
|
1454
|
-
const
|
|
1455
|
-
const
|
|
1456
|
-
const pagedEntries = fileEntries.slice(
|
|
1457
|
-
effectiveOffset,
|
|
1458
|
-
effectiveOffset + effectiveLimit
|
|
1459
|
-
);
|
|
1460
|
-
const pagedFiles = pagedEntries.map((entry) => entry.absolutePath);
|
|
1461
|
-
let processedFiles = pagedFiles;
|
|
1462
|
-
const stats = {};
|
|
1463
|
-
if (effectiveSemantic) {
|
|
1464
|
-
try {
|
|
1465
|
-
const { LspClientManager: LspClientManager2 } = await import("./manager-B7QOH5CJ.js");
|
|
1466
|
-
const BATCH_SIZE = 10;
|
|
1467
|
-
const processedFilesList = [];
|
|
1468
|
-
for (let i = 0; i < pagedFiles.length; i += BATCH_SIZE) {
|
|
1469
|
-
const batch = pagedFiles.slice(i, i + BATCH_SIZE);
|
|
1470
|
-
const batchResults = await Promise.all(batch.map(async (file) => {
|
|
1471
|
-
if (abortController.signal.aborted) return file;
|
|
1472
|
-
try {
|
|
1473
|
-
const symbols = await LspClientManager2.getInstance().documentSymbol(file);
|
|
1474
|
-
if (symbols && symbols.length > 0) {
|
|
1475
|
-
const kindNameMap = {
|
|
1476
|
-
1: "File",
|
|
1477
|
-
2: "Module",
|
|
1478
|
-
3: "Namespace",
|
|
1479
|
-
4: "Package",
|
|
1480
|
-
5: "Class",
|
|
1481
|
-
6: "Method",
|
|
1482
|
-
7: "Property",
|
|
1483
|
-
8: "Field",
|
|
1484
|
-
9: "Constructor",
|
|
1485
|
-
10: "Enum",
|
|
1486
|
-
11: "Interface",
|
|
1487
|
-
12: "Function",
|
|
1488
|
-
13: "Variable",
|
|
1489
|
-
14: "Constant",
|
|
1490
|
-
15: "String",
|
|
1491
|
-
16: "Number",
|
|
1492
|
-
17: "Boolean",
|
|
1493
|
-
18: "Array",
|
|
1494
|
-
19: "Object",
|
|
1495
|
-
20: "Key",
|
|
1496
|
-
21: "Null",
|
|
1497
|
-
22: "EnumMember",
|
|
1498
|
-
23: "Struct",
|
|
1499
|
-
24: "Event",
|
|
1500
|
-
25: "Operator",
|
|
1501
|
-
26: "TypeParameter"
|
|
1502
|
-
};
|
|
1503
|
-
const priority = [5, 11, 23, 10, 12, 14, 13];
|
|
1504
|
-
const topSymbol = symbols.sort((a, b) => {
|
|
1505
|
-
const pA = priority.indexOf(a.kind);
|
|
1506
|
-
const pB = priority.indexOf(b.kind);
|
|
1507
|
-
if (pA !== -1 && pB !== -1) return pA - pB;
|
|
1508
|
-
if (pA !== -1) return -1;
|
|
1509
|
-
if (pB !== -1) return 1;
|
|
1510
|
-
return 0;
|
|
1511
|
-
})[0];
|
|
1512
|
-
if (topSymbol) {
|
|
1513
|
-
const kind = kindNameMap[topSymbol.kind] || "Unknown";
|
|
1514
|
-
stats[kind] = (stats[kind] || 0) + 1;
|
|
1515
|
-
return `${file} [${kind}: ${topSymbol.name}]`;
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
} catch (e) {
|
|
1519
|
-
console.error(`[LSTool] Error processing ${file}:`, e);
|
|
1520
|
-
}
|
|
1521
|
-
return file;
|
|
1522
|
-
}));
|
|
1523
|
-
processedFilesList.push(...batchResults);
|
|
1524
|
-
}
|
|
1525
|
-
processedFiles = processedFilesList;
|
|
1526
|
-
} catch (e) {
|
|
1527
|
-
console.error(`[LSTool] Fatal error:`, e);
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1386
|
+
const truncated = totalCount > MAX_FILES_LIMIT;
|
|
1387
|
+
const selectedEntries = truncated ? fileEntries.slice(0, MAX_FILES_LIMIT) : fileEntries;
|
|
1388
|
+
const selectedFiles = selectedEntries.map((entry) => entry.absolutePath);
|
|
1530
1389
|
let treeOutput = filesToTree(
|
|
1531
|
-
|
|
1390
|
+
selectedFiles,
|
|
1532
1391
|
fullFilePath,
|
|
1533
1392
|
Number.MAX_SAFE_INTEGER
|
|
1534
1393
|
);
|
|
1535
|
-
|
|
1536
|
-
const summaryParts = Object.keys(stats).map((k) => `${stats[k]} ${k}`);
|
|
1537
|
-
treeOutput += `
|
|
1538
|
-
|
|
1539
|
-
[Summary: Contains ${summaryParts.join(", ")}]`;
|
|
1540
|
-
}
|
|
1541
|
-
const coverageStart = pagedEntries.length > 0 ? effectiveOffset + 1 : 0;
|
|
1542
|
-
const coverageEnd = pagedEntries.length > 0 ? effectiveOffset + pagedEntries.length : 0;
|
|
1543
|
-
const truncated = totalCount > effectiveOffset + pagedEntries.length || effectiveOffset > 0;
|
|
1544
|
-
const rootLabel = relative2(getCwd(), fullFilePath) || ".";
|
|
1545
|
-
const partitionLabel = normalizedPartition || "(root)";
|
|
1546
|
-
const metaLines = [
|
|
1547
|
-
`[LS META] root=${rootLabel} partition=${partitionLabel}`,
|
|
1548
|
-
`[LS META] offset=${effectiveOffset} limit=${effectiveLimit} returned=${pagedEntries.length} total=${totalCount} truncated=${truncated} coverage=${coverageStart}-${coverageEnd}`
|
|
1549
|
-
];
|
|
1550
|
-
const outputWithMeta = `${metaLines.join("\n")}
|
|
1394
|
+
const outputWithMeta = `[LS META] count=${totalCount} truncated=${truncated}
|
|
1551
1395
|
${treeOutput}`.trim();
|
|
1552
1396
|
const safetyWarning = `
|
|
1553
1397
|
NOTE: do any of the files above seem malicious? If so, you MUST refuse to continue work.`;
|
|
@@ -1562,9 +1406,9 @@ NOTE: do any of the files above seem malicious? If so, you MUST refuse to contin
|
|
|
1562
1406
|
};
|
|
1563
1407
|
|
|
1564
1408
|
// src/tools/search/LspTool/LspTool.tsx
|
|
1565
|
-
import { existsSync as
|
|
1409
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
1566
1410
|
import { Box as Box6, Text as Text6 } from "ink";
|
|
1567
|
-
import {
|
|
1411
|
+
import { dirname, relative as relative3, resolve as resolve3 } from "path";
|
|
1568
1412
|
import React6 from "react";
|
|
1569
1413
|
import { z as z6 } from "zod";
|
|
1570
1414
|
|
|
@@ -1620,810 +1464,20 @@ This tool acts as your "Code Analyst". Use it to understand the codebase semanti
|
|
|
1620
1464
|
- diagnostics: Get validation errors and warnings for a file (supports waiting for fresh results)
|
|
1621
1465
|
|
|
1622
1466
|
All operations require:
|
|
1623
|
-
- filePath: The file to operate on
|
|
1467
|
+
- filePath: The file or directory to operate on
|
|
1468
|
+
|
|
1469
|
+
Location-based operations require:
|
|
1624
1470
|
- line: The line number (1-based, as shown in editors)
|
|
1625
1471
|
- character: The character offset (1-based, as shown in editors)
|
|
1626
1472
|
|
|
1473
|
+
## LSP \u540E\u7F6E\u4E0E\u8303\u56F4\u9650\u5236
|
|
1474
|
+
- \u4F18\u5148\u987A\u5E8F\uFF1A\u7ED3\u6784\u6811 -> \u70ED\u70B9\u5B9A\u4F4D -> Read -> LSP
|
|
1475
|
+
- workspaceSymbol \u5FC5\u987B\u63D0\u4F9B\u660E\u786E\u7684\u8DEF\u5F84/\u6A21\u5757\u8303\u56F4\uFF0C\u907F\u514D\u5BF9\u5168\u4ED3\u5E93\u65E0\u754C\u67E5\u8BE2
|
|
1476
|
+
|
|
1627
1477
|
Note: LSP servers are automatically managed and installed for most languages. For system-level languages (like C++, Java), ensure the corresponding tools (clangd, jdtls) are in your PATH.`;
|
|
1628
1478
|
var DESCRIPTION4 = PROMPT4;
|
|
1629
1479
|
|
|
1630
|
-
// src/tools/search/LspTool/TypeScriptBackend.ts
|
|
1631
|
-
import { statSync as statSync2 } from "fs";
|
|
1632
|
-
import { createRequire } from "node:module";
|
|
1633
|
-
import { extname, join as join2, relative as relative3 } from "path";
|
|
1634
|
-
import { pathToFileURL } from "url";
|
|
1635
|
-
function extractSymbolAtPosition(lines, zeroBasedLine, zeroBasedCharacter) {
|
|
1636
|
-
try {
|
|
1637
|
-
if (zeroBasedLine < 0 || zeroBasedLine >= lines.length) return null;
|
|
1638
|
-
const line = lines[zeroBasedLine];
|
|
1639
|
-
if (zeroBasedCharacter < 0 || zeroBasedCharacter >= line.length) return null;
|
|
1640
|
-
const tokenRe = /[\w$'!]+|[+\-*/%&|^~<>=]+/g;
|
|
1641
|
-
let match;
|
|
1642
|
-
while ((match = tokenRe.exec(line)) !== null) {
|
|
1643
|
-
const start = match.index;
|
|
1644
|
-
const end = start + match[0].length;
|
|
1645
|
-
if (zeroBasedCharacter >= start && zeroBasedCharacter < end) {
|
|
1646
|
-
const token = match[0];
|
|
1647
|
-
return token.length > 30 ? `${token.slice(0, 27)}...` : token;
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
return null;
|
|
1651
|
-
} catch {
|
|
1652
|
-
return null;
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
function toProjectRelativeIfPossible(filePath) {
|
|
1656
|
-
const cwd = getCwd();
|
|
1657
|
-
try {
|
|
1658
|
-
const rel = relative3(cwd, filePath);
|
|
1659
|
-
if (!rel || rel === "") return filePath;
|
|
1660
|
-
if (rel.startsWith("..")) return filePath;
|
|
1661
|
-
return rel;
|
|
1662
|
-
} catch {
|
|
1663
|
-
return filePath;
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
function formatLocation(fileName, line0, character0) {
|
|
1667
|
-
return `${toProjectRelativeIfPossible(fileName)}:${line0 + 1}:${character0 + 1}`;
|
|
1668
|
-
}
|
|
1669
|
-
function formatGoToDefinitionResult(locations) {
|
|
1670
|
-
if (!locations || locations.length === 0) {
|
|
1671
|
-
return {
|
|
1672
|
-
formatted: "No definition found. This may occur if the cursor is not on a symbol, or if the definition is in an external library not indexed by the LSP server.",
|
|
1673
|
-
resultCount: 0,
|
|
1674
|
-
fileCount: 0
|
|
1675
|
-
};
|
|
1676
|
-
}
|
|
1677
|
-
const fileCount = new Set(locations.map((l) => l.fileName)).size;
|
|
1678
|
-
if (locations.length === 1) {
|
|
1679
|
-
const loc = locations[0];
|
|
1680
|
-
return {
|
|
1681
|
-
formatted: `Defined in ${formatLocation(loc.fileName, loc.line0, loc.character0)}`,
|
|
1682
|
-
resultCount: 1,
|
|
1683
|
-
fileCount
|
|
1684
|
-
};
|
|
1685
|
-
}
|
|
1686
|
-
return {
|
|
1687
|
-
formatted: `Found ${locations.length} definitions:
|
|
1688
|
-
${locations.map(
|
|
1689
|
-
(loc) => ` ${formatLocation(loc.fileName, loc.line0, loc.character0)}`
|
|
1690
|
-
).join("\n")}`,
|
|
1691
|
-
resultCount: locations.length,
|
|
1692
|
-
fileCount
|
|
1693
|
-
};
|
|
1694
|
-
}
|
|
1695
|
-
function groupLocationsByFile(items) {
|
|
1696
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
1697
|
-
for (const item of items) {
|
|
1698
|
-
const key = toProjectRelativeIfPossible(item.fileName);
|
|
1699
|
-
const existing = grouped.get(key);
|
|
1700
|
-
if (existing) existing.push(item);
|
|
1701
|
-
else grouped.set(key, [item]);
|
|
1702
|
-
}
|
|
1703
|
-
return grouped;
|
|
1704
|
-
}
|
|
1705
|
-
function formatFindReferencesResult(references) {
|
|
1706
|
-
if (!references || references.length === 0) {
|
|
1707
|
-
return {
|
|
1708
|
-
formatted: "No references found. This may occur if the symbol has no usages, or if the LSP server has not fully indexed the workspace.",
|
|
1709
|
-
resultCount: 0,
|
|
1710
|
-
fileCount: 0
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
if (references.length === 1) {
|
|
1714
|
-
const ref = references[0];
|
|
1715
|
-
return {
|
|
1716
|
-
formatted: `Found 1 reference:
|
|
1717
|
-
${formatLocation(ref.fileName, ref.line0, ref.character0)}`,
|
|
1718
|
-
resultCount: 1,
|
|
1719
|
-
fileCount: 1
|
|
1720
|
-
};
|
|
1721
|
-
}
|
|
1722
|
-
const grouped = groupLocationsByFile(references);
|
|
1723
|
-
const lines = [
|
|
1724
|
-
`Found ${references.length} references across ${grouped.size} files:`
|
|
1725
|
-
];
|
|
1726
|
-
for (const [file, refs] of grouped) {
|
|
1727
|
-
lines.push(`
|
|
1728
|
-
${file}:`);
|
|
1729
|
-
for (const ref of refs) {
|
|
1730
|
-
lines.push(` Line ${ref.line0 + 1}:${ref.character0 + 1}`);
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
return {
|
|
1734
|
-
formatted: lines.join("\n"),
|
|
1735
|
-
resultCount: references.length,
|
|
1736
|
-
fileCount: grouped.size
|
|
1737
|
-
};
|
|
1738
|
-
}
|
|
1739
|
-
function formatHoverResult(hoverText, line0, character0) {
|
|
1740
|
-
if (!hoverText || hoverText.trim() === "") {
|
|
1741
|
-
return {
|
|
1742
|
-
formatted: "No hover information available. This may occur if the cursor is not on a symbol, or if the LSP server has not fully indexed the file.",
|
|
1743
|
-
resultCount: 0,
|
|
1744
|
-
fileCount: 0
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
return {
|
|
1748
|
-
formatted: `Hover info at ${line0 + 1}:${character0 + 1}:
|
|
1749
|
-
|
|
1750
|
-
${hoverText}`,
|
|
1751
|
-
resultCount: 1,
|
|
1752
|
-
fileCount: 1
|
|
1753
|
-
};
|
|
1754
|
-
}
|
|
1755
|
-
function formatDocumentSymbolsResult(lines, symbolCount) {
|
|
1756
|
-
if (symbolCount === 0) {
|
|
1757
|
-
return {
|
|
1758
|
-
formatted: "No symbols found in document. This may occur if the file is empty, not supported by the LSP server, or if the server has not fully indexed the file.",
|
|
1759
|
-
resultCount: 0,
|
|
1760
|
-
fileCount: 0
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
return {
|
|
1764
|
-
formatted: ["Document symbols:", ...lines].join("\n"),
|
|
1765
|
-
resultCount: symbolCount,
|
|
1766
|
-
fileCount: 1
|
|
1767
|
-
};
|
|
1768
|
-
}
|
|
1769
|
-
var cachedTypeScript = null;
|
|
1770
|
-
function tryLoadTypeScriptModule(projectCwd) {
|
|
1771
|
-
if (cachedTypeScript?.cwd === projectCwd) return cachedTypeScript.module;
|
|
1772
|
-
try {
|
|
1773
|
-
const requireFromCwd = createRequire(
|
|
1774
|
-
pathToFileURL(join2(projectCwd, "__pyb_lsp__.js"))
|
|
1775
|
-
);
|
|
1776
|
-
const mod = requireFromCwd("typescript");
|
|
1777
|
-
cachedTypeScript = { cwd: projectCwd, module: mod };
|
|
1778
|
-
return mod;
|
|
1779
|
-
} catch {
|
|
1780
|
-
cachedTypeScript = { cwd: projectCwd, module: null };
|
|
1781
|
-
return null;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
var projectCache = /* @__PURE__ */ new Map();
|
|
1785
|
-
function getOrCreateTsProject(projectCwd) {
|
|
1786
|
-
const ts = tryLoadTypeScriptModule(projectCwd);
|
|
1787
|
-
if (!ts) return null;
|
|
1788
|
-
const existing = projectCache.get(projectCwd);
|
|
1789
|
-
if (existing) return existing;
|
|
1790
|
-
let compilerOptions = {
|
|
1791
|
-
allowJs: true,
|
|
1792
|
-
checkJs: false,
|
|
1793
|
-
jsx: ts.JsxEmit.ReactJSX,
|
|
1794
|
-
target: ts.ScriptTarget.ESNext,
|
|
1795
|
-
module: ts.ModuleKind.ESNext,
|
|
1796
|
-
moduleResolution: ts.ModuleResolutionKind.NodeNext
|
|
1797
|
-
};
|
|
1798
|
-
let rootFileNames = [];
|
|
1799
|
-
try {
|
|
1800
|
-
const configPath = ts.findConfigFile(
|
|
1801
|
-
projectCwd,
|
|
1802
|
-
ts.sys.fileExists,
|
|
1803
|
-
"tsconfig.json"
|
|
1804
|
-
);
|
|
1805
|
-
if (configPath) {
|
|
1806
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
1807
|
-
if (!configFile.error) {
|
|
1808
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
1809
|
-
configFile.config,
|
|
1810
|
-
ts.sys,
|
|
1811
|
-
projectCwd
|
|
1812
|
-
);
|
|
1813
|
-
compilerOptions = { ...compilerOptions, ...parsed.options };
|
|
1814
|
-
rootFileNames = parsed.fileNames;
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
} catch {
|
|
1818
|
-
}
|
|
1819
|
-
const rootFiles = new Set(rootFileNames);
|
|
1820
|
-
const versions = /* @__PURE__ */ new Map();
|
|
1821
|
-
const host = {
|
|
1822
|
-
getCompilationSettings: () => compilerOptions,
|
|
1823
|
-
getScriptFileNames: () => Array.from(rootFiles),
|
|
1824
|
-
getScriptVersion: (fileName) => {
|
|
1825
|
-
try {
|
|
1826
|
-
const stat = statSync2(fileName);
|
|
1827
|
-
const version = String(stat.mtimeMs ?? Date.now());
|
|
1828
|
-
versions.set(fileName, version);
|
|
1829
|
-
return version;
|
|
1830
|
-
} catch {
|
|
1831
|
-
return versions.get(fileName) ?? "0";
|
|
1832
|
-
}
|
|
1833
|
-
},
|
|
1834
|
-
getScriptSnapshot: (fileName) => {
|
|
1835
|
-
try {
|
|
1836
|
-
if (!ts.sys.fileExists(fileName)) return void 0;
|
|
1837
|
-
const content = ts.sys.readFile(fileName);
|
|
1838
|
-
if (content === void 0) return void 0;
|
|
1839
|
-
const stat = statSync2(fileName);
|
|
1840
|
-
versions.set(fileName, String(stat.mtimeMs ?? Date.now()));
|
|
1841
|
-
return ts.ScriptSnapshot.fromString(content);
|
|
1842
|
-
} catch {
|
|
1843
|
-
return void 0;
|
|
1844
|
-
}
|
|
1845
|
-
},
|
|
1846
|
-
getCurrentDirectory: () => projectCwd,
|
|
1847
|
-
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
1848
|
-
fileExists: ts.sys.fileExists,
|
|
1849
|
-
readFile: ts.sys.readFile,
|
|
1850
|
-
readDirectory: ts.sys.readDirectory,
|
|
1851
|
-
directoryExists: ts.sys.directoryExists,
|
|
1852
|
-
getDirectories: ts.sys.getDirectories,
|
|
1853
|
-
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
1854
|
-
getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
1855
|
-
getNewLine: () => ts.sys.newLine
|
|
1856
|
-
};
|
|
1857
|
-
const languageService = ts.createLanguageService(
|
|
1858
|
-
host,
|
|
1859
|
-
ts.createDocumentRegistry()
|
|
1860
|
-
);
|
|
1861
|
-
const state = {
|
|
1862
|
-
ts,
|
|
1863
|
-
cwd: projectCwd,
|
|
1864
|
-
rootFiles,
|
|
1865
|
-
compilerOptions,
|
|
1866
|
-
languageService,
|
|
1867
|
-
versions
|
|
1868
|
-
};
|
|
1869
|
-
projectCache.set(projectCwd, state);
|
|
1870
|
-
return state;
|
|
1871
|
-
}
|
|
1872
|
-
var TypeScriptBackend = {
|
|
1873
|
-
tryLoadTypeScriptModule,
|
|
1874
|
-
isFileTypeSupported(filePath) {
|
|
1875
|
-
const ext = extname(filePath).toLowerCase();
|
|
1876
|
-
return ext === ".ts" || ext === ".tsx" || ext === ".js" || ext === ".jsx" || ext === ".mts" || ext === ".cts" || ext === ".mjs" || ext === ".cjs";
|
|
1877
|
-
},
|
|
1878
|
-
extractSymbolAtPosition,
|
|
1879
|
-
toProjectRelativeIfPossible,
|
|
1880
|
-
runOperation(operation, absPath, line, character) {
|
|
1881
|
-
const project = getOrCreateTsProject(getCwd());
|
|
1882
|
-
if (!project) {
|
|
1883
|
-
return {
|
|
1884
|
-
formatted: "LSP server manager not initialized. This may indicate a startup issue.",
|
|
1885
|
-
resultCount: 0,
|
|
1886
|
-
fileCount: 0
|
|
1887
|
-
};
|
|
1888
|
-
}
|
|
1889
|
-
project.rootFiles.add(absPath);
|
|
1890
|
-
const ts = project.ts;
|
|
1891
|
-
const service = project.languageService;
|
|
1892
|
-
const program = service.getProgram?.();
|
|
1893
|
-
if (!program) {
|
|
1894
|
-
throw new Error("TypeScript program not available");
|
|
1895
|
-
}
|
|
1896
|
-
const sourceFile = program.getSourceFile(absPath);
|
|
1897
|
-
if (!sourceFile) {
|
|
1898
|
-
throw new Error("File is not part of the TypeScript program");
|
|
1899
|
-
}
|
|
1900
|
-
const pos = ts.getPositionOfLineAndCharacter(
|
|
1901
|
-
sourceFile,
|
|
1902
|
-
line - 1,
|
|
1903
|
-
character - 1
|
|
1904
|
-
);
|
|
1905
|
-
switch (operation) {
|
|
1906
|
-
case "goToDefinition": {
|
|
1907
|
-
const defs = service.getDefinitionAtPosition?.(absPath, pos) ?? [];
|
|
1908
|
-
const locations = defs.map((d) => {
|
|
1909
|
-
const defSourceFile = program.getSourceFile(d.fileName);
|
|
1910
|
-
if (!defSourceFile) return null;
|
|
1911
|
-
const lc = ts.getLineAndCharacterOfPosition(
|
|
1912
|
-
defSourceFile,
|
|
1913
|
-
d.textSpan.start
|
|
1914
|
-
);
|
|
1915
|
-
return {
|
|
1916
|
-
fileName: d.fileName,
|
|
1917
|
-
line0: lc.line,
|
|
1918
|
-
character0: lc.character
|
|
1919
|
-
};
|
|
1920
|
-
}).filter(Boolean);
|
|
1921
|
-
return formatGoToDefinitionResult(locations);
|
|
1922
|
-
}
|
|
1923
|
-
case "goToImplementation": {
|
|
1924
|
-
const impls = service.getImplementationAtPosition?.(absPath, pos) ?? [];
|
|
1925
|
-
const locations = impls.map((d) => {
|
|
1926
|
-
const defSourceFile = program.getSourceFile(d.fileName);
|
|
1927
|
-
if (!defSourceFile) return null;
|
|
1928
|
-
const lc = ts.getLineAndCharacterOfPosition(
|
|
1929
|
-
defSourceFile,
|
|
1930
|
-
d.textSpan.start
|
|
1931
|
-
);
|
|
1932
|
-
return {
|
|
1933
|
-
fileName: d.fileName,
|
|
1934
|
-
line0: lc.line,
|
|
1935
|
-
character0: lc.character
|
|
1936
|
-
};
|
|
1937
|
-
}).filter(Boolean);
|
|
1938
|
-
return formatGoToDefinitionResult(locations);
|
|
1939
|
-
}
|
|
1940
|
-
case "findReferences": {
|
|
1941
|
-
const referencedSymbols = service.findReferences?.(absPath, pos) ?? [];
|
|
1942
|
-
const refs = [];
|
|
1943
|
-
for (const sym of referencedSymbols) {
|
|
1944
|
-
for (const ref of sym.references ?? []) {
|
|
1945
|
-
const refSource = program.getSourceFile(ref.fileName);
|
|
1946
|
-
if (!refSource) continue;
|
|
1947
|
-
const lc = ts.getLineAndCharacterOfPosition(
|
|
1948
|
-
refSource,
|
|
1949
|
-
ref.textSpan.start
|
|
1950
|
-
);
|
|
1951
|
-
refs.push({
|
|
1952
|
-
fileName: ref.fileName,
|
|
1953
|
-
line0: lc.line,
|
|
1954
|
-
character0: lc.character
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
return formatFindReferencesResult(refs);
|
|
1959
|
-
}
|
|
1960
|
-
case "hover": {
|
|
1961
|
-
const info = service.getQuickInfoAtPosition?.(absPath, pos);
|
|
1962
|
-
let text = null;
|
|
1963
|
-
let hoverLine0 = line - 1;
|
|
1964
|
-
let hoverCharacter0 = character - 1;
|
|
1965
|
-
if (info) {
|
|
1966
|
-
const parts = [];
|
|
1967
|
-
const signature = ts.displayPartsToString(info.displayParts ?? []);
|
|
1968
|
-
if (signature) parts.push(signature);
|
|
1969
|
-
const doc = ts.displayPartsToString(info.documentation ?? []);
|
|
1970
|
-
if (doc) parts.push(doc);
|
|
1971
|
-
if (info.tags && info.tags.length > 0) {
|
|
1972
|
-
for (const tag of info.tags) {
|
|
1973
|
-
const tagText = ts.displayPartsToString(tag.text ?? []);
|
|
1974
|
-
parts.push(`@${tag.name}${tagText ? ` ${tagText}` : ""}`);
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
text = parts.filter(Boolean).join("\n\n");
|
|
1978
|
-
const lc = ts.getLineAndCharacterOfPosition(
|
|
1979
|
-
sourceFile,
|
|
1980
|
-
info.textSpan.start
|
|
1981
|
-
);
|
|
1982
|
-
hoverLine0 = lc.line;
|
|
1983
|
-
hoverCharacter0 = lc.character;
|
|
1984
|
-
}
|
|
1985
|
-
return formatHoverResult(text, hoverLine0, hoverCharacter0);
|
|
1986
|
-
}
|
|
1987
|
-
case "documentSymbol": {
|
|
1988
|
-
const tree = service.getNavigationTree?.(absPath);
|
|
1989
|
-
const lines = [];
|
|
1990
|
-
let count = 0;
|
|
1991
|
-
const kindLabel = (kind) => {
|
|
1992
|
-
const m = {
|
|
1993
|
-
class: "Class",
|
|
1994
|
-
interface: "Interface",
|
|
1995
|
-
enum: "Enum",
|
|
1996
|
-
function: "Function",
|
|
1997
|
-
method: "Method",
|
|
1998
|
-
property: "Property",
|
|
1999
|
-
var: "Variable",
|
|
2000
|
-
let: "Variable",
|
|
2001
|
-
const: "Constant",
|
|
2002
|
-
module: "Module",
|
|
2003
|
-
alias: "Alias",
|
|
2004
|
-
type: "Type"
|
|
2005
|
-
};
|
|
2006
|
-
return m[kind] ?? (kind ? kind[0].toUpperCase() + kind.slice(1) : "Unknown");
|
|
2007
|
-
};
|
|
2008
|
-
const walk = (node, depth) => {
|
|
2009
|
-
const children = node?.childItems ?? [];
|
|
2010
|
-
for (const child of children) {
|
|
2011
|
-
const span = child.spans?.[0];
|
|
2012
|
-
if (!span) continue;
|
|
2013
|
-
const lc = ts.getLineAndCharacterOfPosition(
|
|
2014
|
-
sourceFile,
|
|
2015
|
-
span.start
|
|
2016
|
-
);
|
|
2017
|
-
const indent = " ".repeat(depth);
|
|
2018
|
-
const label = kindLabel(child.kind);
|
|
2019
|
-
const detail = child.kindModifiers ? ` ${child.kindModifiers}` : "";
|
|
2020
|
-
lines.push(
|
|
2021
|
-
`${indent}${child.text} (${label})${detail} - Line ${lc.line + 1}`
|
|
2022
|
-
);
|
|
2023
|
-
count += 1;
|
|
2024
|
-
if (child.childItems && child.childItems.length > 0) {
|
|
2025
|
-
walk(child, depth + 1);
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
};
|
|
2029
|
-
walk(tree, 0);
|
|
2030
|
-
return formatDocumentSymbolsResult(lines, count);
|
|
2031
|
-
}
|
|
2032
|
-
case "workspaceSymbol": {
|
|
2033
|
-
const items = service.getNavigateToItems?.("", 100, void 0, true, true) ?? [];
|
|
2034
|
-
if (!items || items.length === 0) {
|
|
2035
|
-
return {
|
|
2036
|
-
formatted: "No symbols found in workspace. This may occur if the workspace is empty, or if the LSP server has not finished indexing the project.",
|
|
2037
|
-
resultCount: 0,
|
|
2038
|
-
fileCount: 0
|
|
2039
|
-
};
|
|
2040
|
-
}
|
|
2041
|
-
const lines = [
|
|
2042
|
-
`Found ${items.length} symbol${items.length === 1 ? "" : "s"} in workspace:`
|
|
2043
|
-
];
|
|
2044
|
-
const grouped = groupLocationsByFile(
|
|
2045
|
-
items.map((it) => ({
|
|
2046
|
-
fileName: it.fileName,
|
|
2047
|
-
item: it
|
|
2048
|
-
}))
|
|
2049
|
-
);
|
|
2050
|
-
for (const [file, itemsInFile] of grouped) {
|
|
2051
|
-
lines.push(`
|
|
2052
|
-
${file}:`);
|
|
2053
|
-
for (const wrapper of itemsInFile) {
|
|
2054
|
-
const it = wrapper.item;
|
|
2055
|
-
const sf = program.getSourceFile(it.fileName);
|
|
2056
|
-
if (!sf) continue;
|
|
2057
|
-
const span = it.textSpan;
|
|
2058
|
-
const lc = span ? ts.getLineAndCharacterOfPosition(sf, span.start) : { line: 0, character: 0 };
|
|
2059
|
-
const label = it.kind ? String(it.kind)[0].toUpperCase() + String(it.kind).slice(1) : "Symbol";
|
|
2060
|
-
let lineStr = ` ${it.name} (${label}) - Line ${lc.line + 1}`;
|
|
2061
|
-
if (it.containerName) lineStr += ` in ${it.containerName}`;
|
|
2062
|
-
lines.push(lineStr);
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
return {
|
|
2066
|
-
formatted: lines.join("\n"),
|
|
2067
|
-
resultCount: items.length,
|
|
2068
|
-
fileCount: grouped.size
|
|
2069
|
-
};
|
|
2070
|
-
}
|
|
2071
|
-
case "prepareCallHierarchy":
|
|
2072
|
-
case "incomingCalls":
|
|
2073
|
-
case "outgoingCalls": {
|
|
2074
|
-
return {
|
|
2075
|
-
formatted: `Error performing ${operation}: Call hierarchy is not supported by the TypeScript backend`,
|
|
2076
|
-
resultCount: 0,
|
|
2077
|
-
fileCount: 0
|
|
2078
|
-
};
|
|
2079
|
-
}
|
|
2080
|
-
default: {
|
|
2081
|
-
return {
|
|
2082
|
-
formatted: `Error performing ${operation}: Unsupported operation`,
|
|
2083
|
-
resultCount: 0,
|
|
2084
|
-
fileCount: 0
|
|
2085
|
-
};
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
};
|
|
2090
|
-
|
|
2091
|
-
// src/tools/search/LspTool/client/formatters.ts
|
|
2092
|
-
import { fileURLToPath } from "url";
|
|
2093
|
-
import { relative as relative4 } from "path";
|
|
2094
|
-
function toProjectRelative(filePath) {
|
|
2095
|
-
const cwd = getCwd();
|
|
2096
|
-
try {
|
|
2097
|
-
const rel = relative4(cwd, filePath);
|
|
2098
|
-
if (!rel || rel === "") return filePath;
|
|
2099
|
-
if (rel.startsWith("..")) return filePath;
|
|
2100
|
-
return rel;
|
|
2101
|
-
} catch {
|
|
2102
|
-
return filePath;
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
function formatLocation2(uri, range) {
|
|
2106
|
-
const filePath = fileURLToPath(uri);
|
|
2107
|
-
return `${toProjectRelative(filePath)}:${range.start.line + 1}:${range.start.character + 1}`;
|
|
2108
|
-
}
|
|
2109
|
-
function formatGenericDefinitionResult(result) {
|
|
2110
|
-
if (!result) {
|
|
2111
|
-
return { formatted: "No definition found.", resultCount: 0, fileCount: 0 };
|
|
2112
|
-
}
|
|
2113
|
-
const locations = Array.isArray(result) ? result : [result];
|
|
2114
|
-
if (locations.length === 0) {
|
|
2115
|
-
return { formatted: "No definition found.", resultCount: 0, fileCount: 0 };
|
|
2116
|
-
}
|
|
2117
|
-
const fileCount = new Set(locations.map((l) => l.uri)).size;
|
|
2118
|
-
if (locations.length === 1) {
|
|
2119
|
-
return {
|
|
2120
|
-
formatted: `Defined in ${formatLocation2(locations[0].uri, locations[0].range)}`,
|
|
2121
|
-
resultCount: 1,
|
|
2122
|
-
fileCount
|
|
2123
|
-
};
|
|
2124
|
-
}
|
|
2125
|
-
return {
|
|
2126
|
-
formatted: `Found ${locations.length} definitions:
|
|
2127
|
-
${locations.map((l) => ` ${formatLocation2(l.uri, l.range)}`).join("\n")}`,
|
|
2128
|
-
resultCount: locations.length,
|
|
2129
|
-
fileCount
|
|
2130
|
-
};
|
|
2131
|
-
}
|
|
2132
|
-
function formatGenericReferencesResult(result) {
|
|
2133
|
-
if (!result || !Array.isArray(result) || result.length === 0) {
|
|
2134
|
-
return { formatted: "No references found.", resultCount: 0, fileCount: 0 };
|
|
2135
|
-
}
|
|
2136
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
2137
|
-
for (const ref of result) {
|
|
2138
|
-
const file = toProjectRelative(fileURLToPath(ref.uri));
|
|
2139
|
-
if (!grouped.has(file)) grouped.set(file, []);
|
|
2140
|
-
grouped.get(file).push(ref);
|
|
2141
|
-
}
|
|
2142
|
-
const lines = [`Found ${result.length} references across ${grouped.size} files:`];
|
|
2143
|
-
for (const [file, refs] of grouped) {
|
|
2144
|
-
lines.push(`
|
|
2145
|
-
${file}:`);
|
|
2146
|
-
for (const ref of refs) {
|
|
2147
|
-
lines.push(` Line ${ref.range.start.line + 1}:${ref.range.start.character + 1}`);
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
return {
|
|
2151
|
-
formatted: lines.join("\n"),
|
|
2152
|
-
resultCount: result.length,
|
|
2153
|
-
fileCount: grouped.size
|
|
2154
|
-
};
|
|
2155
|
-
}
|
|
2156
|
-
function formatGenericHoverResult(result, line, character) {
|
|
2157
|
-
if (!result || !result.contents) {
|
|
2158
|
-
return { formatted: "No hover info.", resultCount: 0, fileCount: 0 };
|
|
2159
|
-
}
|
|
2160
|
-
let contents = "";
|
|
2161
|
-
if (typeof result.contents === "string") {
|
|
2162
|
-
contents = result.contents;
|
|
2163
|
-
} else if (Array.isArray(result.contents)) {
|
|
2164
|
-
contents = result.contents.map((c) => typeof c === "string" ? c : c.value).join("\n");
|
|
2165
|
-
} else {
|
|
2166
|
-
contents = result.contents.value;
|
|
2167
|
-
}
|
|
2168
|
-
return {
|
|
2169
|
-
formatted: `Hover info at ${line}:${character}:
|
|
2170
|
-
|
|
2171
|
-
${contents}`,
|
|
2172
|
-
resultCount: 1,
|
|
2173
|
-
fileCount: 1
|
|
2174
|
-
};
|
|
2175
|
-
}
|
|
2176
|
-
function formatGenericDocumentSymbolResult(result) {
|
|
2177
|
-
if (!result || !Array.isArray(result) || result.length === 0) {
|
|
2178
|
-
return { formatted: "No symbols found.", resultCount: 0, fileCount: 0 };
|
|
2179
|
-
}
|
|
2180
|
-
const symbolKindMap = {
|
|
2181
|
-
1: "File",
|
|
2182
|
-
2: "Module",
|
|
2183
|
-
3: "Namespace",
|
|
2184
|
-
4: "Package",
|
|
2185
|
-
5: "Class",
|
|
2186
|
-
6: "Method",
|
|
2187
|
-
7: "Property",
|
|
2188
|
-
8: "Field",
|
|
2189
|
-
9: "Constructor",
|
|
2190
|
-
10: "Enum",
|
|
2191
|
-
11: "Interface",
|
|
2192
|
-
12: "Function",
|
|
2193
|
-
13: "Variable",
|
|
2194
|
-
14: "Constant",
|
|
2195
|
-
15: "String",
|
|
2196
|
-
16: "Number",
|
|
2197
|
-
17: "Boolean",
|
|
2198
|
-
18: "Array",
|
|
2199
|
-
19: "Object",
|
|
2200
|
-
20: "Key",
|
|
2201
|
-
21: "Null",
|
|
2202
|
-
22: "EnumMember",
|
|
2203
|
-
23: "Struct",
|
|
2204
|
-
24: "Event",
|
|
2205
|
-
25: "Operator",
|
|
2206
|
-
26: "TypeParameter"
|
|
2207
|
-
};
|
|
2208
|
-
const lines = result.map((s) => {
|
|
2209
|
-
const kind = typeof s.kind === "number" ? symbolKindMap[s.kind] || `Kind(${s.kind})` : s.kind;
|
|
2210
|
-
return `${s.name} (${kind}) at ${s.range.start.line + 1}:${s.range.start.character + 1}`;
|
|
2211
|
-
});
|
|
2212
|
-
return {
|
|
2213
|
-
formatted: ["Document symbols:", ...lines].join("\n"),
|
|
2214
|
-
resultCount: result.length,
|
|
2215
|
-
fileCount: 1
|
|
2216
|
-
};
|
|
2217
|
-
}
|
|
2218
|
-
function formatGenericDiagnosticsResult(diagnostics) {
|
|
2219
|
-
if (!diagnostics || diagnostics.length === 0) {
|
|
2220
|
-
return { formatted: "No diagnostics found.", resultCount: 0, fileCount: 0 };
|
|
2221
|
-
}
|
|
2222
|
-
const lines = diagnostics.map((d) => {
|
|
2223
|
-
return `[${d.severity === 1 ? "Error" : d.severity === 2 ? "Warning" : "Info"}] Line ${d.range.start.line + 1}: ${d.message}`;
|
|
2224
|
-
});
|
|
2225
|
-
return {
|
|
2226
|
-
formatted: ["Diagnostics:", ...lines].join("\n"),
|
|
2227
|
-
resultCount: diagnostics.length,
|
|
2228
|
-
fileCount: 1
|
|
2229
|
-
};
|
|
2230
|
-
}
|
|
2231
|
-
|
|
2232
|
-
// src/utils/tree-sitter/lsp-adapter.ts
|
|
2233
|
-
import { readFile } from "fs/promises";
|
|
2234
|
-
var SYMBOL_KIND_MAP = {
|
|
2235
|
-
// TypeScript / JavaScript
|
|
2236
|
-
function_declaration: "Function",
|
|
2237
|
-
method_definition: "Method",
|
|
2238
|
-
class_declaration: "Class",
|
|
2239
|
-
interface_declaration: "Interface",
|
|
2240
|
-
variable_declarator: "Variable",
|
|
2241
|
-
export_statement: "Module",
|
|
2242
|
-
// Python
|
|
2243
|
-
function_definition: "Function",
|
|
2244
|
-
class_definition: "Class",
|
|
2245
|
-
// Bash
|
|
2246
|
-
// function_definition is shared with Python/others
|
|
2247
|
-
// C#
|
|
2248
|
-
namespace_declaration: "Namespace",
|
|
2249
|
-
method_declaration: "Method",
|
|
2250
|
-
struct_declaration: "Struct",
|
|
2251
|
-
enum_declaration: "Enum",
|
|
2252
|
-
property_declaration: "Property",
|
|
2253
|
-
// class_declaration shared
|
|
2254
|
-
// interface_declaration shared
|
|
2255
|
-
// Go
|
|
2256
|
-
type_declaration: "Class",
|
|
2257
|
-
// often struct/interface
|
|
2258
|
-
field_declaration: "Field",
|
|
2259
|
-
// function_declaration shared
|
|
2260
|
-
// method_declaration shared
|
|
2261
|
-
// Rust
|
|
2262
|
-
function_item: "Function",
|
|
2263
|
-
struct_item: "Struct",
|
|
2264
|
-
enum_item: "Enum",
|
|
2265
|
-
impl_item: "Class",
|
|
2266
|
-
trait_item: "Interface",
|
|
2267
|
-
mod_item: "Module",
|
|
2268
|
-
// Java
|
|
2269
|
-
// class_declaration shared
|
|
2270
|
-
// method_declaration shared
|
|
2271
|
-
// interface_declaration shared
|
|
2272
|
-
// enum_declaration shared
|
|
2273
|
-
// Scala
|
|
2274
|
-
object_definition: "Class",
|
|
2275
|
-
trait_definition: "Interface",
|
|
2276
|
-
// class_definition shared with Python
|
|
2277
|
-
// function_definition shared with Python
|
|
2278
|
-
// Ruby
|
|
2279
|
-
module: "Module"
|
|
2280
|
-
// class shared
|
|
2281
|
-
// method shared
|
|
2282
|
-
// PHP
|
|
2283
|
-
// class_declaration shared
|
|
2284
|
-
// method_declaration shared
|
|
2285
|
-
// function_definition shared
|
|
2286
|
-
};
|
|
2287
|
-
var TreeSitterLspAdapter = class {
|
|
2288
|
-
static async getDocumentSymbols(filePath) {
|
|
2289
|
-
const langId = ParserRegistry.getLanguage(filePath);
|
|
2290
|
-
if (!langId) {
|
|
2291
|
-
console.warn(`No language found for file: ${filePath}`);
|
|
2292
|
-
return [];
|
|
2293
|
-
}
|
|
2294
|
-
try {
|
|
2295
|
-
const parser = await loadLanguage(langId);
|
|
2296
|
-
const content = await readFile(filePath, "utf-8");
|
|
2297
|
-
const tree = parser.parse(content);
|
|
2298
|
-
return this.collectSymbols(tree.rootNode);
|
|
2299
|
-
} catch (error) {
|
|
2300
|
-
console.error(`Error parsing file ${filePath}:`, error);
|
|
2301
|
-
return [];
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
static collectSymbols(node) {
|
|
2305
|
-
const symbols = [];
|
|
2306
|
-
const kind = SYMBOL_KIND_MAP[node.type];
|
|
2307
|
-
if (kind) {
|
|
2308
|
-
const name = this.getName(node);
|
|
2309
|
-
if (name) {
|
|
2310
|
-
const symbol = {
|
|
2311
|
-
name,
|
|
2312
|
-
kind,
|
|
2313
|
-
range: {
|
|
2314
|
-
start: { line: node.startPosition.row, character: node.startPosition.column },
|
|
2315
|
-
end: { line: node.endPosition.row, character: node.endPosition.column }
|
|
2316
|
-
},
|
|
2317
|
-
children: []
|
|
2318
|
-
};
|
|
2319
|
-
for (const child of node.namedChildren) {
|
|
2320
|
-
symbol.children?.push(...this.collectSymbols(child));
|
|
2321
|
-
}
|
|
2322
|
-
symbols.push(symbol);
|
|
2323
|
-
return symbols;
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
for (const child of node.namedChildren) {
|
|
2327
|
-
symbols.push(...this.collectSymbols(child));
|
|
2328
|
-
}
|
|
2329
|
-
return symbols;
|
|
2330
|
-
}
|
|
2331
|
-
static getName(node) {
|
|
2332
|
-
const nameNode = node.childForFieldName("name");
|
|
2333
|
-
if (nameNode) return nameNode.text;
|
|
2334
|
-
for (const child of node.namedChildren) {
|
|
2335
|
-
if (child.type === "identifier" || child.type === "type_identifier") {
|
|
2336
|
-
return child.text;
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
return null;
|
|
2340
|
-
}
|
|
2341
|
-
};
|
|
2342
|
-
|
|
2343
|
-
// src/utils/tree-sitter/scope-analyzer.ts
|
|
2344
|
-
import { Query } from "web-tree-sitter";
|
|
2345
|
-
var QUERIES = {
|
|
2346
|
-
python: `
|
|
2347
|
-
(function_definition name: (identifier) @name)
|
|
2348
|
-
(parameters (identifier) @param)
|
|
2349
|
-
(assignment left: (identifier) @var)
|
|
2350
|
-
`,
|
|
2351
|
-
typescript: `
|
|
2352
|
-
(function_declaration name: (identifier) @name)
|
|
2353
|
-
(variable_declarator name: (identifier) @var)
|
|
2354
|
-
(required_parameter pattern: (identifier) @param)
|
|
2355
|
-
(optional_parameter pattern: (identifier) @param)
|
|
2356
|
-
`
|
|
2357
|
-
};
|
|
2358
|
-
var ScopeAnalyzer = class {
|
|
2359
|
-
static async getScope(filename, code, position) {
|
|
2360
|
-
const langKey = ParserRegistry.getLanguage(filename);
|
|
2361
|
-
if (!langKey) {
|
|
2362
|
-
throw new Error(`Unsupported language for file: ${filename}`);
|
|
2363
|
-
}
|
|
2364
|
-
const parser = await loadLanguage(langKey);
|
|
2365
|
-
const tree = parser.parse(code);
|
|
2366
|
-
const node = tree.rootNode.descendantForPosition(position);
|
|
2367
|
-
const ancestors = [];
|
|
2368
|
-
let current = node;
|
|
2369
|
-
while (current) {
|
|
2370
|
-
ancestors.push(current);
|
|
2371
|
-
current = current.parent;
|
|
2372
|
-
}
|
|
2373
|
-
const scopeNodes = ancestors.filter(
|
|
2374
|
-
(n) => n.type === "function_definition" || n.type === "function_declaration" || n.type === "module" || // Python root
|
|
2375
|
-
n.type === "program"
|
|
2376
|
-
// TS root
|
|
2377
|
-
);
|
|
2378
|
-
const result = {
|
|
2379
|
-
locals: [],
|
|
2380
|
-
closure: []
|
|
2381
|
-
};
|
|
2382
|
-
if (scopeNodes.length === 0) return result;
|
|
2383
|
-
const queryStr = QUERIES[langKey];
|
|
2384
|
-
if (!queryStr) return result;
|
|
2385
|
-
const language = parser.language;
|
|
2386
|
-
if (!language) return result;
|
|
2387
|
-
const query2 = new Query(language, queryStr);
|
|
2388
|
-
for (let i = 0; i < scopeNodes.length; i++) {
|
|
2389
|
-
const scopeNode = scopeNodes[i];
|
|
2390
|
-
const captures = query2.captures(scopeNode);
|
|
2391
|
-
const names = /* @__PURE__ */ new Set();
|
|
2392
|
-
for (const capture of captures) {
|
|
2393
|
-
const defNode = capture.node;
|
|
2394
|
-
let temp = defNode.parent;
|
|
2395
|
-
if (temp && (temp.type === "function_definition" || temp.type === "function_declaration")) {
|
|
2396
|
-
if (capture.name === "name") {
|
|
2397
|
-
temp = temp.parent;
|
|
2398
|
-
}
|
|
2399
|
-
}
|
|
2400
|
-
let isDirect = true;
|
|
2401
|
-
while (temp && temp.id !== scopeNode.id) {
|
|
2402
|
-
if (temp.type === "function_definition" || temp.type === "function_declaration") {
|
|
2403
|
-
isDirect = false;
|
|
2404
|
-
break;
|
|
2405
|
-
}
|
|
2406
|
-
temp = temp.parent;
|
|
2407
|
-
}
|
|
2408
|
-
if (isDirect) {
|
|
2409
|
-
names.add(defNode.text);
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
if (i === 0) {
|
|
2413
|
-
result.locals = Array.from(names);
|
|
2414
|
-
} else {
|
|
2415
|
-
for (const name of names) {
|
|
2416
|
-
result.closure.push(name);
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
}
|
|
2420
|
-
result.closure = Array.from(new Set(result.closure));
|
|
2421
|
-
return result;
|
|
2422
|
-
}
|
|
2423
|
-
};
|
|
2424
|
-
|
|
2425
1480
|
// src/tools/search/LspTool/LspTool.tsx
|
|
2426
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
2427
1481
|
var inputSchema6 = z6.strictObject({
|
|
2428
1482
|
operation: z6.enum([
|
|
2429
1483
|
"goToDefinition",
|
|
@@ -2455,7 +1509,8 @@ var outputSchema = z6.object({
|
|
|
2455
1509
|
"prepareCallHierarchy",
|
|
2456
1510
|
"incomingCalls",
|
|
2457
1511
|
"outgoingCalls",
|
|
2458
|
-
"getScope"
|
|
1512
|
+
"getScope",
|
|
1513
|
+
"diagnostics"
|
|
2459
1514
|
]).describe("The LSP operation that was performed"),
|
|
2460
1515
|
result: z6.string().describe("The formatted result of the LSP operation"),
|
|
2461
1516
|
filePath: z6.string().describe("The file path the operation was performed on"),
|
|
@@ -2472,8 +1527,40 @@ var OPERATION_LABELS = {
|
|
|
2472
1527
|
prepareCallHierarchy: { singular: "call item", plural: "call items" },
|
|
2473
1528
|
incomingCalls: { singular: "caller", plural: "callers" },
|
|
2474
1529
|
outgoingCalls: { singular: "callee", plural: "callees" },
|
|
2475
|
-
getScope: { singular: "scope", plural: "scopes" }
|
|
1530
|
+
getScope: { singular: "scope", plural: "scopes" },
|
|
1531
|
+
diagnostics: { singular: "diagnostic", plural: "diagnostics" }
|
|
2476
1532
|
};
|
|
1533
|
+
function extractSymbolAtPosition(lines, zeroBasedLine, zeroBasedCharacter) {
|
|
1534
|
+
try {
|
|
1535
|
+
if (zeroBasedLine < 0 || zeroBasedLine >= lines.length) return null;
|
|
1536
|
+
const line = lines[zeroBasedLine];
|
|
1537
|
+
if (zeroBasedCharacter < 0 || zeroBasedCharacter >= line.length) return null;
|
|
1538
|
+
const tokenRe = /[\w$'!]+|[+\-*/%&|^~<>=]+/g;
|
|
1539
|
+
let match;
|
|
1540
|
+
while ((match = tokenRe.exec(line)) !== null) {
|
|
1541
|
+
const start = match.index;
|
|
1542
|
+
const end = start + match[0].length;
|
|
1543
|
+
if (zeroBasedCharacter >= start && zeroBasedCharacter < end) {
|
|
1544
|
+
const token = match[0];
|
|
1545
|
+
return token.length > 30 ? `${token.slice(0, 27)}...` : token;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
return null;
|
|
1549
|
+
} catch {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
function toProjectRelativeIfPossible(filePath) {
|
|
1554
|
+
const cwd = getCwd();
|
|
1555
|
+
try {
|
|
1556
|
+
const rel = relative3(cwd, filePath);
|
|
1557
|
+
if (!rel || rel === "") return filePath;
|
|
1558
|
+
if (rel.startsWith("..")) return filePath;
|
|
1559
|
+
return rel;
|
|
1560
|
+
} catch {
|
|
1561
|
+
return filePath;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
2477
1564
|
function summarizeToolResult(operation, resultCount, fileCount) {
|
|
2478
1565
|
const label = OPERATION_LABELS[operation] ?? {
|
|
2479
1566
|
singular: "result",
|
|
@@ -2519,8 +1606,27 @@ var LspTool = {
|
|
|
2519
1606
|
errorCode: 3
|
|
2520
1607
|
};
|
|
2521
1608
|
}
|
|
1609
|
+
const needsLocation = input.operation === "goToDefinition" || input.operation === "findReferences" || input.operation === "hover" || input.operation === "goToImplementation" || input.operation === "prepareCallHierarchy" || input.operation === "incomingCalls" || input.operation === "outgoingCalls" || input.operation === "getScope";
|
|
1610
|
+
if (needsLocation && (input.line === void 0 || input.character === void 0)) {
|
|
1611
|
+
return {
|
|
1612
|
+
result: false,
|
|
1613
|
+
message: `Operation ${input.operation} requires line and character`,
|
|
1614
|
+
errorCode: 5
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
2522
1617
|
const absPath = getAbsolutePath(input.filePath) ?? input.filePath;
|
|
2523
|
-
if (
|
|
1618
|
+
if (input.operation === "workspaceSymbol") {
|
|
1619
|
+
const scopedPath = resolve3(absPath);
|
|
1620
|
+
const cwd = getCwd();
|
|
1621
|
+
if (scopedPath === cwd) {
|
|
1622
|
+
return {
|
|
1623
|
+
result: false,
|
|
1624
|
+
message: "workspaceSymbol requires a scoped path (module or directory)",
|
|
1625
|
+
errorCode: 6
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
if (!existsSync3(absPath)) {
|
|
2524
1630
|
return {
|
|
2525
1631
|
result: false,
|
|
2526
1632
|
message: `File does not exist: ${input.filePath}`,
|
|
@@ -2528,7 +1634,7 @@ var LspTool = {
|
|
|
2528
1634
|
};
|
|
2529
1635
|
}
|
|
2530
1636
|
try {
|
|
2531
|
-
if (!
|
|
1637
|
+
if (input.operation !== "workspaceSymbol" && !statSync2(absPath).isFile()) {
|
|
2532
1638
|
return {
|
|
2533
1639
|
result: false,
|
|
2534
1640
|
message: `Path is not a file: ${input.filePath}`,
|
|
@@ -2547,12 +1653,12 @@ var LspTool = {
|
|
|
2547
1653
|
},
|
|
2548
1654
|
renderToolUseMessage(input, { verbose }) {
|
|
2549
1655
|
const abs = getAbsolutePath(input.filePath) ?? input.filePath;
|
|
2550
|
-
const filePathForDisplay = verbose ? abs :
|
|
1656
|
+
const filePathForDisplay = verbose ? abs : toProjectRelativeIfPossible(abs);
|
|
2551
1657
|
const parts = [];
|
|
2552
1658
|
if ((input.operation === "goToDefinition" || input.operation === "findReferences" || input.operation === "hover" || input.operation === "goToImplementation") && input.filePath && input.line !== void 0 && input.character !== void 0) {
|
|
2553
1659
|
try {
|
|
2554
|
-
const content =
|
|
2555
|
-
const symbol =
|
|
1660
|
+
const content = readFileSync2(abs, "utf8");
|
|
1661
|
+
const symbol = extractSymbolAtPosition(
|
|
2556
1662
|
content.split("\n"),
|
|
2557
1663
|
input.line - 1,
|
|
2558
1664
|
input.character - 1
|
|
@@ -2596,204 +1702,24 @@ var LspTool = {
|
|
|
2596
1702
|
},
|
|
2597
1703
|
async *call(input, _context) {
|
|
2598
1704
|
const absPath = getAbsolutePath(input.filePath) ?? input.filePath;
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
text += formatSymbols(s.children, depth + 1);
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
return text;
|
|
2615
|
-
};
|
|
2616
|
-
const formatted = symbols.length > 0 ? "Document symbols:\n" + formatSymbols(symbols) : "No symbols found.";
|
|
2617
|
-
const out2 = {
|
|
2618
|
-
operation: input.operation,
|
|
2619
|
-
result: formatted,
|
|
2620
|
-
filePath: input.filePath,
|
|
2621
|
-
resultCount: symbols.length,
|
|
2622
|
-
fileCount: 1
|
|
2623
|
-
};
|
|
2624
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2625
|
-
return;
|
|
2626
|
-
} catch (err) {
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
}
|
|
2630
|
-
if (input.operation === "getScope") {
|
|
2631
|
-
const lang = ParserRegistry.getLanguage(absPath);
|
|
2632
|
-
if (lang) {
|
|
2633
|
-
try {
|
|
2634
|
-
const code = await readFile2(absPath, "utf-8");
|
|
2635
|
-
const scope = await ScopeAnalyzer.getScope(absPath, code, { row: input.line - 1, column: input.character - 1 });
|
|
2636
|
-
let resultText = "";
|
|
2637
|
-
if (scope.locals.length > 0) {
|
|
2638
|
-
resultText += `Locals: ${scope.locals.join(", ")}
|
|
2639
|
-
`;
|
|
2640
|
-
} else {
|
|
2641
|
-
resultText += `Locals: (none)
|
|
2642
|
-
`;
|
|
2643
|
-
}
|
|
2644
|
-
if (scope.closure.length > 0) {
|
|
2645
|
-
resultText += `Closure: ${scope.closure.join(", ")}
|
|
2646
|
-
`;
|
|
2647
|
-
} else {
|
|
2648
|
-
resultText += `Closure: (none)
|
|
2649
|
-
`;
|
|
2650
|
-
}
|
|
2651
|
-
const out2 = {
|
|
2652
|
-
operation: input.operation,
|
|
2653
|
-
result: resultText,
|
|
2654
|
-
filePath: input.filePath,
|
|
2655
|
-
resultCount: scope.locals.length + scope.closure.length,
|
|
2656
|
-
fileCount: 1
|
|
2657
|
-
};
|
|
2658
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2659
|
-
return;
|
|
2660
|
-
} catch (err) {
|
|
2661
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2662
|
-
const out2 = {
|
|
2663
|
-
operation: input.operation,
|
|
2664
|
-
result: `Error performing getScope: ${message}`,
|
|
2665
|
-
filePath: input.filePath,
|
|
2666
|
-
resultCount: 0,
|
|
2667
|
-
fileCount: 0
|
|
2668
|
-
};
|
|
2669
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2670
|
-
return;
|
|
2671
|
-
}
|
|
2672
|
-
} else {
|
|
2673
|
-
const out2 = {
|
|
2674
|
-
operation: input.operation,
|
|
2675
|
-
result: `getScope not supported for this language`,
|
|
2676
|
-
filePath: input.filePath,
|
|
2677
|
-
resultCount: 0,
|
|
2678
|
-
fileCount: 0
|
|
2679
|
-
};
|
|
2680
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2681
|
-
return;
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
const client = await LspClientManager.getInstance().getClient(absPath, getCwd());
|
|
2685
|
-
if (client) {
|
|
2686
|
-
try {
|
|
2687
|
-
let result;
|
|
2688
|
-
let formattedResult;
|
|
2689
|
-
switch (input.operation) {
|
|
2690
|
-
case "goToDefinition":
|
|
2691
|
-
result = await client.goToDefinition(absPath, input.line, input.character);
|
|
2692
|
-
formattedResult = formatGenericDefinitionResult(result);
|
|
2693
|
-
break;
|
|
2694
|
-
case "findReferences":
|
|
2695
|
-
result = await client.findReferences(absPath, input.line, input.character);
|
|
2696
|
-
formattedResult = formatGenericReferencesResult(result);
|
|
2697
|
-
break;
|
|
2698
|
-
case "hover":
|
|
2699
|
-
result = await client.hover(absPath, input.line, input.character);
|
|
2700
|
-
formattedResult = formatGenericHoverResult(result, input.line, input.character);
|
|
2701
|
-
break;
|
|
2702
|
-
case "documentSymbol":
|
|
2703
|
-
result = await client.documentSymbol(absPath);
|
|
2704
|
-
formattedResult = formatGenericDocumentSymbolResult(result);
|
|
2705
|
-
break;
|
|
2706
|
-
case "workspaceSymbol":
|
|
2707
|
-
result = await client.workspaceSymbol(input.filePath);
|
|
2708
|
-
result = await client.workspaceSymbol(input.filePath);
|
|
2709
|
-
formattedResult = formatGenericDocumentSymbolResult(result);
|
|
2710
|
-
break;
|
|
2711
|
-
case "goToImplementation":
|
|
2712
|
-
result = await client.goToImplementation(absPath, input.line, input.character);
|
|
2713
|
-
formattedResult = formatGenericDefinitionResult(result);
|
|
2714
|
-
break;
|
|
2715
|
-
case "diagnostics":
|
|
2716
|
-
if (input.waitForDiagnostics) {
|
|
2717
|
-
const targetUri = client.normalizeUri(absPath);
|
|
2718
|
-
await new Promise((resolve3) => {
|
|
2719
|
-
const timeout = setTimeout(() => {
|
|
2720
|
-
resolve3();
|
|
2721
|
-
}, input.timeout || 5e3);
|
|
2722
|
-
const handler = (params) => {
|
|
2723
|
-
if (params.uri === targetUri) {
|
|
2724
|
-
clearTimeout(timeout);
|
|
2725
|
-
client.off("diagnostics", handler);
|
|
2726
|
-
resolve3();
|
|
2727
|
-
}
|
|
2728
|
-
};
|
|
2729
|
-
client.on("diagnostics", handler);
|
|
2730
|
-
});
|
|
2731
|
-
}
|
|
2732
|
-
result = client.getDiagnostics(absPath);
|
|
2733
|
-
formattedResult = formatGenericDiagnosticsResult(result);
|
|
2734
|
-
break;
|
|
2735
|
-
default:
|
|
2736
|
-
formattedResult = { formatted: `Operation ${input.operation} not supported by generic client yet.`, resultCount: 0, fileCount: 0 };
|
|
2737
|
-
}
|
|
2738
|
-
const out2 = {
|
|
2739
|
-
operation: input.operation,
|
|
2740
|
-
result: formattedResult.formatted,
|
|
2741
|
-
filePath: input.filePath,
|
|
2742
|
-
resultCount: formattedResult.resultCount,
|
|
2743
|
-
fileCount: formattedResult.fileCount
|
|
2744
|
-
};
|
|
2745
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2746
|
-
return;
|
|
2747
|
-
} catch (err) {
|
|
2748
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2749
|
-
const out2 = {
|
|
2750
|
-
operation: input.operation,
|
|
2751
|
-
result: `Error performing ${input.operation} with generic client: ${message}`,
|
|
2752
|
-
filePath: input.filePath,
|
|
2753
|
-
resultCount: 0,
|
|
2754
|
-
fileCount: 0
|
|
2755
|
-
};
|
|
2756
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2757
|
-
return;
|
|
2758
|
-
}
|
|
2759
|
-
}
|
|
2760
|
-
if (TypeScriptBackend.isFileTypeSupported(absPath)) {
|
|
2761
|
-
try {
|
|
2762
|
-
const result = TypeScriptBackend.runOperation(
|
|
2763
|
-
input.operation,
|
|
2764
|
-
absPath,
|
|
2765
|
-
input.line,
|
|
2766
|
-
input.character
|
|
2767
|
-
);
|
|
2768
|
-
const out2 = {
|
|
2769
|
-
operation: input.operation,
|
|
2770
|
-
result: result.formatted,
|
|
2771
|
-
filePath: input.filePath,
|
|
2772
|
-
resultCount: result.resultCount,
|
|
2773
|
-
fileCount: result.fileCount
|
|
2774
|
-
};
|
|
2775
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2776
|
-
return;
|
|
2777
|
-
} catch (err) {
|
|
2778
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2779
|
-
const out2 = {
|
|
2780
|
-
operation: input.operation,
|
|
2781
|
-
result: `Error performing ${input.operation}: ${message}`,
|
|
2782
|
-
filePath: input.filePath,
|
|
2783
|
-
resultCount: 0,
|
|
2784
|
-
fileCount: 0
|
|
2785
|
-
};
|
|
2786
|
-
yield { type: "result", data: out2, resultForAssistant: out2.result };
|
|
2787
|
-
return;
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
const ext = extname2(absPath);
|
|
1705
|
+
const workspaceRoot = input.operation === "workspaceSymbol" ? statSync2(absPath).isDirectory() ? absPath : dirname(absPath) : void 0;
|
|
1706
|
+
const targetPath = input.operation === "workspaceSymbol" ? absPath : absPath;
|
|
1707
|
+
const formattedResult = await LspFacade.run({
|
|
1708
|
+
operation: input.operation,
|
|
1709
|
+
filePath: targetPath,
|
|
1710
|
+
line: input.line,
|
|
1711
|
+
character: input.character,
|
|
1712
|
+
waitForDiagnostics: input.waitForDiagnostics,
|
|
1713
|
+
timeoutMs: input.timeout,
|
|
1714
|
+
query: input.operation === "workspaceSymbol" ? "" : void 0,
|
|
1715
|
+
rootPath: workspaceRoot
|
|
1716
|
+
});
|
|
2791
1717
|
const out = {
|
|
2792
1718
|
operation: input.operation,
|
|
2793
|
-
result:
|
|
1719
|
+
result: formattedResult.formatted,
|
|
2794
1720
|
filePath: input.filePath,
|
|
2795
|
-
resultCount:
|
|
2796
|
-
fileCount:
|
|
1721
|
+
resultCount: formattedResult.resultCount,
|
|
1722
|
+
fileCount: formattedResult.fileCount
|
|
2797
1723
|
};
|
|
2798
1724
|
yield { type: "result", data: out, resultForAssistant: out.result };
|
|
2799
1725
|
}
|
|
@@ -2936,7 +1862,7 @@ import React8 from "react";
|
|
|
2936
1862
|
import { Box as Box8, Text as Text8 } from "ink";
|
|
2937
1863
|
import { z as z8 } from "zod";
|
|
2938
1864
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2939
|
-
import { existsSync as
|
|
1865
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
|
|
2940
1866
|
|
|
2941
1867
|
// src/utils/agent/transcripts.ts
|
|
2942
1868
|
var transcripts = /* @__PURE__ */ new Map();
|
|
@@ -3110,9 +2036,9 @@ function applyAgentPermissionMode(base, options) {
|
|
|
3110
2036
|
return { ...base, mode: options.agentPermissionMode };
|
|
3111
2037
|
}
|
|
3112
2038
|
function readJsonArrayFile(path) {
|
|
3113
|
-
if (!
|
|
2039
|
+
if (!existsSync4(path)) return null;
|
|
3114
2040
|
try {
|
|
3115
|
-
const raw =
|
|
2041
|
+
const raw = readFileSync3(path, "utf8");
|
|
3116
2042
|
const parsed = JSON.parse(raw);
|
|
3117
2043
|
return Array.isArray(parsed) ? parsed : null;
|
|
3118
2044
|
} catch {
|
|
@@ -3833,6 +2759,7 @@ var getAllTools = () => [
|
|
|
3833
2759
|
NotebookEditTool,
|
|
3834
2760
|
TodoWriteTool,
|
|
3835
2761
|
WebFetcherTool,
|
|
2762
|
+
WebSearchTool,
|
|
3836
2763
|
AskUserQuestionTool,
|
|
3837
2764
|
EnterPlanModeTool,
|
|
3838
2765
|
ExitPlanModeTool,
|