pybao-cli 1.3.97 → 1.3.99
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-35WMIAEP.js +47 -0
- package/dist/{acp-Y5GVEAK5.js → acp-XZAGDT3N.js} +30 -30
- package/dist/{agentsValidate-HVG4G32H.js → agentsValidate-ZPLW7S35.js} +7 -7
- package/dist/{ask-Q4D437ZY.js → ask-ROXENA55.js} +31 -31
- package/dist/{autoUpdater-2HZ5MXSY.js → autoUpdater-NDX26QV7.js} +3 -3
- package/dist/{chunk-DFGDXB5I.js → chunk-2ULPCMQN.js} +2 -2
- package/dist/{chunk-VCS4L3LA.js → chunk-2WVYPGFK.js} +2 -2
- package/dist/{chunk-D7EHET2A.js → chunk-3HVYGUQ7.js} +3 -3
- package/dist/{chunk-4C2BJ5TH.js → chunk-44DDEUXT.js} +488 -696
- package/dist/chunk-44DDEUXT.js.map +7 -0
- package/dist/{chunk-IGEQR5ET.js → chunk-47PFBKB5.js} +3 -3
- package/dist/{chunk-7ZK32QRX.js → chunk-4NRDC2MN.js} +2 -2
- package/dist/{chunk-DSHUCMWX.js → chunk-5ON6SGBK.js} +1 -1
- package/dist/{chunk-DSHUCMWX.js.map → chunk-5ON6SGBK.js.map} +1 -1
- package/dist/{chunk-VU4GCLM2.js → chunk-B6YMKCYD.js} +2 -2
- package/dist/{chunk-W7CPW6S2.js → chunk-BXOS6YEB.js} +3 -3
- package/dist/{chunk-LGG56SIC.js → chunk-CGHZ2VAY.js} +1 -1
- package/dist/{chunk-4UESJIJZ.js → chunk-CMQGXFRW.js} +1 -1
- package/dist/{chunk-TQAQR7CB.js → chunk-EY2TENGG.js} +1 -1
- package/dist/{chunk-FMZTGW27.js → chunk-HN63ZGCX.js} +4 -4
- package/dist/{chunk-5SWRWOXZ.js → chunk-I23P7CAV.js} +3 -3
- package/dist/{chunk-SHKXEYZX.js → chunk-JFW7GGFH.js} +162 -53
- package/dist/chunk-JFW7GGFH.js.map +7 -0
- package/dist/{chunk-JQ7U4FNJ.js → chunk-L5MUGKPW.js} +3 -3
- package/dist/{chunk-HZQ5D4KE.js → chunk-M2J4YYEX.js} +428 -500
- package/dist/chunk-M2J4YYEX.js.map +7 -0
- package/dist/{chunk-T6MZIN3Y.js → chunk-Q6XLF2PE.js} +1 -1
- package/dist/{chunk-CJ5J54UV.js → chunk-QX6FKMRR.js} +6 -3
- package/dist/chunk-QX6FKMRR.js.map +7 -0
- package/dist/{chunk-IBMWS4VP.js → chunk-T4EFAH55.js} +1 -1
- package/dist/{chunk-GVQW5V5E.js → chunk-U5J6MTAO.js} +2 -2
- package/dist/{chunk-T4CDNQDK.js → chunk-VWENSRU2.js} +4 -7
- package/dist/chunk-VWENSRU2.js.map +7 -0
- package/dist/{chunk-X7NKBF4S.js → chunk-VYINZ75I.js} +1110 -162
- package/dist/chunk-VYINZ75I.js.map +7 -0
- package/dist/{chunk-SRPG24JR.js → chunk-W3RWB5JG.js} +9 -10
- package/dist/{chunk-SRPG24JR.js.map → chunk-W3RWB5JG.js.map} +2 -2
- package/dist/{chunk-ILVR3OKO.js → chunk-WWYDMHKU.js} +1 -1
- package/dist/{chunk-BNTZKC47.js → chunk-X6KY4AMW.js} +2 -2
- package/dist/{chunk-WHWTXVZ4.js → chunk-XLOFU6ZK.js} +1 -1
- package/dist/{chunk-GW4FHFLN.js → chunk-YOK3FML7.js} +1 -1
- package/dist/{chunk-T7MGCO5Q.js → chunk-ZFDSP2ES.js} +2 -2
- package/dist/{chunk-VBDYRFAI.js → chunk-ZI6CKPRG.js} +3 -6
- package/dist/chunk-ZI6CKPRG.js.map +7 -0
- package/dist/{cli-YWSRHJXF.js → cli-W6BTK6IG.js} +88 -88
- package/dist/commands-OGUECGBR.js +51 -0
- package/dist/{config-XEZZSNSO.js → config-MJPE676F.js} +4 -4
- package/dist/{context-O7XDPBZM.js → context-XLNMR7UJ.js} +12 -9
- package/dist/{customCommands-T227ND56.js → customCommands-NJWIPIRB.js} +4 -4
- package/dist/{env-LGLECBD2.js → env-UNJ7A6Y6.js} +2 -2
- package/dist/{file-LRWOIEO2.js → file-CYIU2LVL.js} +4 -4
- package/dist/index.js +3 -3
- package/dist/{llm-KH33MHA2.js → llm-XG5AIU4E.js} +32 -32
- package/dist/{llmLazy-QDJLCLFB.js → llmLazy-7HIZGF35.js} +1 -1
- package/dist/{loader-DOLDAFSG.js → loader-3PAJ74VN.js} +4 -4
- package/dist/{lsp-F2AYEHJW.js → lsp-S2GYO6LP.js} +16 -8
- package/dist/{lspAnchor-LDTVHYPK.js → lspAnchor-VZAH2A7D.js} +6 -6
- package/dist/{mcp-3SENV5JM.js → mcp-36TM4EWY.js} +7 -7
- package/dist/{mentionProcessor-AES6QJFQ.js → mentionProcessor-YIBFG2BE.js} +5 -5
- package/dist/{messages-A77FBKUD.js → messages-GMVNWQYB.js} +1 -1
- package/dist/{model-T5FSSEGT.js → model-QA5R6ZTQ.js} +5 -5
- package/dist/{openai-4Z5HQAPJ.js → openai-AISJCDRB.js} +5 -5
- package/dist/{outputStyles-NPZ5JCX4.js → outputStyles-UNF5PJDX.js} +4 -4
- package/dist/{pluginRuntime-ESATQIVZ.js → pluginRuntime-OPB7TGEW.js} +6 -6
- package/dist/{pluginValidation-ZIDSORKU.js → pluginValidation-GNC62BIO.js} +6 -6
- package/dist/prompts-H6FALR72.js +53 -0
- package/dist/{pybAgentSessionLoad-INUFKXJY.js → pybAgentSessionLoad-FZKVG353.js} +4 -4
- package/dist/{pybAgentSessionResume-QW7NW3GM.js → pybAgentSessionResume-HHSBJMUF.js} +4 -4
- package/dist/{pybAgentStreamJsonSession-GKZPRQGC.js → pybAgentStreamJsonSession-UZOLZ2EE.js} +1 -1
- package/dist/{pybHooks-HD3YL2EO.js → pybHooks-BDHY2ZPR.js} +4 -4
- package/dist/query-XTV7VLUK.js +55 -0
- package/dist/{registry-VYHW665M.js → registry-YC7VJDV4.js} +5 -5
- package/dist/{ripgrep-RUMV7DUX.js → ripgrep-HXHIAV7L.js} +3 -3
- package/dist/{skillMarketplace-TEDBVTRN.js → skillMarketplace-4F6MUJZA.js} +3 -3
- package/dist/{state-BESFSMYW.js → state-BVQ44522.js} +2 -2
- package/dist/{theme-O5XJ5B2X.js → theme-VG4SDCTS.js} +5 -5
- package/dist/{toolPermissionSettings-N4VMBCRF.js → toolPermissionSettings-V4VXC5RQ.js} +6 -6
- package/dist/tools-WZEQJIS5.js +52 -0
- package/dist/{userInput-65GMTCNY.js → userInput-4FUGSRKW.js} +31 -31
- package/package.json +1 -1
- package/dist/REPL-4UQT2JYD.js +0 -47
- package/dist/chunk-4C2BJ5TH.js.map +0 -7
- package/dist/chunk-CJ5J54UV.js.map +0 -7
- package/dist/chunk-HZQ5D4KE.js.map +0 -7
- package/dist/chunk-SHKXEYZX.js.map +0 -7
- package/dist/chunk-T4CDNQDK.js.map +0 -7
- package/dist/chunk-VBDYRFAI.js.map +0 -7
- package/dist/chunk-X7NKBF4S.js.map +0 -7
- package/dist/commands-KRK3MO6Q.js +0 -51
- package/dist/prompts-VSJKN5BB.js +0 -53
- package/dist/query-F5YSMI7D.js +0 -61
- package/dist/tools-V5NSQILS.js +0 -52
- /package/dist/{REPL-4UQT2JYD.js.map → REPL-35WMIAEP.js.map} +0 -0
- /package/dist/{acp-Y5GVEAK5.js.map → acp-XZAGDT3N.js.map} +0 -0
- /package/dist/{agentsValidate-HVG4G32H.js.map → agentsValidate-ZPLW7S35.js.map} +0 -0
- /package/dist/{ask-Q4D437ZY.js.map → ask-ROXENA55.js.map} +0 -0
- /package/dist/{autoUpdater-2HZ5MXSY.js.map → autoUpdater-NDX26QV7.js.map} +0 -0
- /package/dist/{chunk-DFGDXB5I.js.map → chunk-2ULPCMQN.js.map} +0 -0
- /package/dist/{chunk-VCS4L3LA.js.map → chunk-2WVYPGFK.js.map} +0 -0
- /package/dist/{chunk-D7EHET2A.js.map → chunk-3HVYGUQ7.js.map} +0 -0
- /package/dist/{chunk-IGEQR5ET.js.map → chunk-47PFBKB5.js.map} +0 -0
- /package/dist/{chunk-7ZK32QRX.js.map → chunk-4NRDC2MN.js.map} +0 -0
- /package/dist/{chunk-VU4GCLM2.js.map → chunk-B6YMKCYD.js.map} +0 -0
- /package/dist/{chunk-W7CPW6S2.js.map → chunk-BXOS6YEB.js.map} +0 -0
- /package/dist/{chunk-LGG56SIC.js.map → chunk-CGHZ2VAY.js.map} +0 -0
- /package/dist/{chunk-4UESJIJZ.js.map → chunk-CMQGXFRW.js.map} +0 -0
- /package/dist/{chunk-TQAQR7CB.js.map → chunk-EY2TENGG.js.map} +0 -0
- /package/dist/{chunk-FMZTGW27.js.map → chunk-HN63ZGCX.js.map} +0 -0
- /package/dist/{chunk-5SWRWOXZ.js.map → chunk-I23P7CAV.js.map} +0 -0
- /package/dist/{chunk-JQ7U4FNJ.js.map → chunk-L5MUGKPW.js.map} +0 -0
- /package/dist/{chunk-T6MZIN3Y.js.map → chunk-Q6XLF2PE.js.map} +0 -0
- /package/dist/{chunk-IBMWS4VP.js.map → chunk-T4EFAH55.js.map} +0 -0
- /package/dist/{chunk-GVQW5V5E.js.map → chunk-U5J6MTAO.js.map} +0 -0
- /package/dist/{chunk-ILVR3OKO.js.map → chunk-WWYDMHKU.js.map} +0 -0
- /package/dist/{chunk-BNTZKC47.js.map → chunk-X6KY4AMW.js.map} +0 -0
- /package/dist/{chunk-WHWTXVZ4.js.map → chunk-XLOFU6ZK.js.map} +0 -0
- /package/dist/{chunk-GW4FHFLN.js.map → chunk-YOK3FML7.js.map} +0 -0
- /package/dist/{chunk-T7MGCO5Q.js.map → chunk-ZFDSP2ES.js.map} +0 -0
- /package/dist/{cli-YWSRHJXF.js.map → cli-W6BTK6IG.js.map} +0 -0
- /package/dist/{commands-KRK3MO6Q.js.map → commands-OGUECGBR.js.map} +0 -0
- /package/dist/{config-XEZZSNSO.js.map → config-MJPE676F.js.map} +0 -0
- /package/dist/{context-O7XDPBZM.js.map → context-XLNMR7UJ.js.map} +0 -0
- /package/dist/{customCommands-T227ND56.js.map → customCommands-NJWIPIRB.js.map} +0 -0
- /package/dist/{env-LGLECBD2.js.map → env-UNJ7A6Y6.js.map} +0 -0
- /package/dist/{file-LRWOIEO2.js.map → file-CYIU2LVL.js.map} +0 -0
- /package/dist/{llm-KH33MHA2.js.map → llm-XG5AIU4E.js.map} +0 -0
- /package/dist/{llmLazy-QDJLCLFB.js.map → llmLazy-7HIZGF35.js.map} +0 -0
- /package/dist/{loader-DOLDAFSG.js.map → loader-3PAJ74VN.js.map} +0 -0
- /package/dist/{lsp-F2AYEHJW.js.map → lsp-S2GYO6LP.js.map} +0 -0
- /package/dist/{lspAnchor-LDTVHYPK.js.map → lspAnchor-VZAH2A7D.js.map} +0 -0
- /package/dist/{mcp-3SENV5JM.js.map → mcp-36TM4EWY.js.map} +0 -0
- /package/dist/{mentionProcessor-AES6QJFQ.js.map → mentionProcessor-YIBFG2BE.js.map} +0 -0
- /package/dist/{messages-A77FBKUD.js.map → messages-GMVNWQYB.js.map} +0 -0
- /package/dist/{model-T5FSSEGT.js.map → model-QA5R6ZTQ.js.map} +0 -0
- /package/dist/{openai-4Z5HQAPJ.js.map → openai-AISJCDRB.js.map} +0 -0
- /package/dist/{outputStyles-NPZ5JCX4.js.map → outputStyles-UNF5PJDX.js.map} +0 -0
- /package/dist/{pluginRuntime-ESATQIVZ.js.map → pluginRuntime-OPB7TGEW.js.map} +0 -0
- /package/dist/{pluginValidation-ZIDSORKU.js.map → pluginValidation-GNC62BIO.js.map} +0 -0
- /package/dist/{prompts-VSJKN5BB.js.map → prompts-H6FALR72.js.map} +0 -0
- /package/dist/{pybAgentSessionLoad-INUFKXJY.js.map → pybAgentSessionLoad-FZKVG353.js.map} +0 -0
- /package/dist/{pybAgentSessionResume-QW7NW3GM.js.map → pybAgentSessionResume-HHSBJMUF.js.map} +0 -0
- /package/dist/{pybAgentStreamJsonSession-GKZPRQGC.js.map → pybAgentStreamJsonSession-UZOLZ2EE.js.map} +0 -0
- /package/dist/{pybHooks-HD3YL2EO.js.map → pybHooks-BDHY2ZPR.js.map} +0 -0
- /package/dist/{query-F5YSMI7D.js.map → query-XTV7VLUK.js.map} +0 -0
- /package/dist/{registry-VYHW665M.js.map → registry-YC7VJDV4.js.map} +0 -0
- /package/dist/{ripgrep-RUMV7DUX.js.map → ripgrep-HXHIAV7L.js.map} +0 -0
- /package/dist/{skillMarketplace-TEDBVTRN.js.map → skillMarketplace-4F6MUJZA.js.map} +0 -0
- /package/dist/{state-BESFSMYW.js.map → state-BVQ44522.js.map} +0 -0
- /package/dist/{theme-O5XJ5B2X.js.map → theme-VG4SDCTS.js.map} +0 -0
- /package/dist/{toolPermissionSettings-N4VMBCRF.js.map → toolPermissionSettings-V4VXC5RQ.js.map} +0 -0
- /package/dist/{tools-V5NSQILS.js.map → tools-WZEQJIS5.js.map} +0 -0
- /package/dist/{userInput-65GMTCNY.js.map → userInput-4FUGSRKW.js.map} +0 -0
|
@@ -25,62 +25,59 @@ import {
|
|
|
25
25
|
hasReadPermission,
|
|
26
26
|
hasWritePermission,
|
|
27
27
|
query
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-M2J4YYEX.js";
|
|
29
29
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
runPostToolUseHooks,
|
|
34
|
-
runPreToolUseHooks
|
|
35
|
-
} from "./chunk-D7EHET2A.js";
|
|
36
|
-
import {
|
|
37
|
-
queryLLM
|
|
38
|
-
} from "./chunk-FMZTGW27.js";
|
|
30
|
+
queryLLM,
|
|
31
|
+
queryQuick
|
|
32
|
+
} from "./chunk-HN63ZGCX.js";
|
|
39
33
|
import {
|
|
40
34
|
FallbackToolUseRejectedMessage,
|
|
41
35
|
MCPTool,
|
|
42
36
|
getClients,
|
|
43
37
|
getMCPTools
|
|
44
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-W3RWB5JG.js";
|
|
45
39
|
import {
|
|
46
40
|
generateAgentId
|
|
47
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-2ULPCMQN.js";
|
|
48
42
|
import {
|
|
49
43
|
getActiveAgents,
|
|
50
44
|
getAgentByType,
|
|
51
45
|
getAvailableAgentTypes
|
|
52
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-X6KY4AMW.js";
|
|
53
47
|
import {
|
|
54
48
|
INTERRUPT_MESSAGE,
|
|
55
49
|
createAssistantMessage,
|
|
56
50
|
createUserMessage,
|
|
57
51
|
getLastAssistantMessageId
|
|
58
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-WWYDMHKU.js";
|
|
59
53
|
import {
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
formatDuration,
|
|
55
|
+
formatNumber
|
|
56
|
+
} from "./chunk-OUXHGDLH.js";
|
|
62
57
|
import {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} from "./chunk-T4CDNQDK.js";
|
|
58
|
+
getAbsolutePath
|
|
59
|
+
} from "./chunk-ZFDSP2ES.js";
|
|
66
60
|
import {
|
|
67
61
|
LspAPI,
|
|
68
62
|
LspFacade,
|
|
69
63
|
formatDiagnosticsPretty
|
|
70
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-VYINZ75I.js";
|
|
71
65
|
import {
|
|
72
66
|
getModelManager
|
|
73
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-L5MUGKPW.js";
|
|
68
|
+
import {
|
|
69
|
+
getContext
|
|
70
|
+
} from "./chunk-JFW7GGFH.js";
|
|
74
71
|
import {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} from "./chunk-
|
|
72
|
+
filesToTree,
|
|
73
|
+
ripGrepWithStatus
|
|
74
|
+
} from "./chunk-VWENSRU2.js";
|
|
78
75
|
import {
|
|
79
76
|
getTheme
|
|
80
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-Q6XLF2PE.js";
|
|
81
78
|
import {
|
|
82
79
|
debug
|
|
83
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-T4EFAH55.js";
|
|
84
81
|
import {
|
|
85
82
|
BunShell,
|
|
86
83
|
getCwd,
|
|
@@ -90,11 +87,7 @@ import {
|
|
|
90
87
|
overwriteLog,
|
|
91
88
|
readTaskOutput,
|
|
92
89
|
resolveXdgDataPath
|
|
93
|
-
} from "./chunk-
|
|
94
|
-
import {
|
|
95
|
-
formatDuration,
|
|
96
|
-
formatNumber
|
|
97
|
-
} from "./chunk-OUXHGDLH.js";
|
|
90
|
+
} from "./chunk-CMQGXFRW.js";
|
|
98
91
|
|
|
99
92
|
// src/tools/index.ts
|
|
100
93
|
import { memoize as memoize2 } from "lodash-es";
|
|
@@ -563,478 +556,11 @@ Please check your model configuration with /model command.`
|
|
|
563
556
|
}
|
|
564
557
|
};
|
|
565
558
|
|
|
566
|
-
// src/tools/system/
|
|
559
|
+
// src/tools/system/TaskOutputTool/TaskOutputTool.tsx
|
|
567
560
|
import { Box as Box2, Text as Text2 } from "ink";
|
|
568
|
-
import
|
|
561
|
+
import React2 from "react";
|
|
569
562
|
import { z as z2 } from "zod";
|
|
570
563
|
|
|
571
|
-
// src/tools/system/BatchTool/prompt.ts
|
|
572
|
-
var TOOL_NAME_FOR_PROMPT = "Batch";
|
|
573
|
-
var DESCRIPTION = `Execute multiple independent tool calls in parallel with a single request.
|
|
574
|
-
Only readonly and concurrency-safe tools should be batched.
|
|
575
|
-
MCP tools and marketplace skills must be called directly, not through batch.
|
|
576
|
-
Soft limits:
|
|
577
|
-
- Maximum of 10 tool calls per batch (11th+ are rejected)
|
|
578
|
-
- Do NOT use batch within batch
|
|
579
|
-
Keep using Batch for eligible tool groups to reduce latency.`;
|
|
580
|
-
var PROMPT = `Use this tool to execute a batch of tool calls for parallel execution.
|
|
581
|
-
|
|
582
|
-
Rules:
|
|
583
|
-
- Only readonly and concurrency-safe tools are allowed in batch
|
|
584
|
-
- MCP tools and marketplace skills are excluded and must be called directly
|
|
585
|
-
- Maximum 10 tool calls per batch (11th+ are rejected)
|
|
586
|
-
- Do NOT use batch within batch
|
|
587
|
-
- Prefer Batch when you have multiple eligible calls with no dependencies
|
|
588
|
-
|
|
589
|
-
Input format:
|
|
590
|
-
{
|
|
591
|
-
"tool_calls": [
|
|
592
|
-
{ "tool": "LS", "parameters": { "path": "D:/repo/docs" } },
|
|
593
|
-
{ "tool": "Read", "parameters": { "file_path": "/abs/path.txt" } },
|
|
594
|
-
{ "tool": "Grep", "parameters": { "pattern": "foo" } }
|
|
595
|
-
]
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
Good examples:
|
|
599
|
-
- Read multiple files + Grep in parallel
|
|
600
|
-
- Multiple independent Grep searches
|
|
601
|
-
|
|
602
|
-
Avoid:
|
|
603
|
-
- Calls that depend on previous outputs
|
|
604
|
-
- Any non-readonly or non-concurrency-safe tools`;
|
|
605
|
-
|
|
606
|
-
// src/tools/system/BatchTool/BatchTool.tsx
|
|
607
|
-
var toolCallSchema = z2.strictObject({
|
|
608
|
-
tool: z2.string().describe("The name of the tool to execute"),
|
|
609
|
-
parameters: z2.object({}).passthrough().describe("Parameters for the tool")
|
|
610
|
-
});
|
|
611
|
-
var inputSchema2 = z2.strictObject({
|
|
612
|
-
tool_calls: z2.preprocess(
|
|
613
|
-
(value) => value === void 0 ? [] : value,
|
|
614
|
-
z2.array(toolCallSchema).min(1, "Provide at least one tool call").describe("Array of tool calls to evaluate for batch execution")
|
|
615
|
-
)
|
|
616
|
-
});
|
|
617
|
-
var MAX_BATCH_TOOLS = 10;
|
|
618
|
-
var MAX_BATCH_LIST_ITEMS = 6;
|
|
619
|
-
var MAX_PARAM_FIELDS = 6;
|
|
620
|
-
var MAX_PARAM_LENGTH = 60;
|
|
621
|
-
var SENSITIVE_PARAM_PATTERN = /(token|secret|password|api[_-]?key|credential|bearer)/i;
|
|
622
|
-
function isBatchToolName(name) {
|
|
623
|
-
return name.trim().toLowerCase() === "batch";
|
|
624
|
-
}
|
|
625
|
-
function isMcpToolName(name) {
|
|
626
|
-
const trimmed = name.trim();
|
|
627
|
-
return trimmed === "mcp" || trimmed.startsWith("mcp__");
|
|
628
|
-
}
|
|
629
|
-
function isMarketplaceToolName(name) {
|
|
630
|
-
return name.trim().startsWith("marketplace__");
|
|
631
|
-
}
|
|
632
|
-
function isSkillToolName(name) {
|
|
633
|
-
return name.trim() === "Skill";
|
|
634
|
-
}
|
|
635
|
-
function formatBatchToolList(toolCalls, limit = MAX_BATCH_LIST_ITEMS) {
|
|
636
|
-
if (!Array.isArray(toolCalls)) return "";
|
|
637
|
-
const names = toolCalls.map((call) => call.tool).filter((name) => typeof name === "string" && name.length > 0);
|
|
638
|
-
if (names.length === 0) return "";
|
|
639
|
-
const visible = names.slice(0, limit);
|
|
640
|
-
const remaining = names.length - visible.length;
|
|
641
|
-
if (remaining > 0) {
|
|
642
|
-
return `${visible.join(", ")}, \u2026+${remaining}`;
|
|
643
|
-
}
|
|
644
|
-
return visible.join(", ");
|
|
645
|
-
}
|
|
646
|
-
function truncateValue(value) {
|
|
647
|
-
if (value.length <= MAX_PARAM_LENGTH) return value;
|
|
648
|
-
return `${value.slice(0, MAX_PARAM_LENGTH)}\u2026`;
|
|
649
|
-
}
|
|
650
|
-
function formatParamValue(key, value) {
|
|
651
|
-
if (SENSITIVE_PARAM_PATTERN.test(key)) return "[redacted]";
|
|
652
|
-
if (value === null) return "null";
|
|
653
|
-
if (typeof value === "string") return `"${truncateValue(value)}"`;
|
|
654
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
655
|
-
return String(value);
|
|
656
|
-
if (Array.isArray(value)) return `[Array(${value.length})]`;
|
|
657
|
-
if (typeof value === "object") return "{\u2026}";
|
|
658
|
-
return truncateValue(String(value));
|
|
659
|
-
}
|
|
660
|
-
function formatBatchParamSummary(parameters) {
|
|
661
|
-
const entries = Object.entries(parameters ?? {}).filter(
|
|
662
|
-
([, value]) => value !== void 0
|
|
663
|
-
);
|
|
664
|
-
if (entries.length === 0) return "{}";
|
|
665
|
-
const parts = [];
|
|
666
|
-
const max = Math.min(entries.length, MAX_PARAM_FIELDS);
|
|
667
|
-
for (let i = 0; i < max; i += 1) {
|
|
668
|
-
const [key, value] = entries[i];
|
|
669
|
-
parts.push(`${key}: ${formatParamValue(key, value)}`);
|
|
670
|
-
}
|
|
671
|
-
const remaining = entries.length - max;
|
|
672
|
-
if (remaining > 0) {
|
|
673
|
-
parts.push(`\u2026+${remaining}`);
|
|
674
|
-
}
|
|
675
|
-
return `{ ${parts.join(", ")} }`;
|
|
676
|
-
}
|
|
677
|
-
function formatBatchSummary(output) {
|
|
678
|
-
const lines = [];
|
|
679
|
-
lines.push(`Batch evaluation: ${output.success}/${output.total} successful`);
|
|
680
|
-
if (output.notes.length > 0) {
|
|
681
|
-
lines.push(...output.notes);
|
|
682
|
-
}
|
|
683
|
-
if (output.total > 0) {
|
|
684
|
-
lines.push("Tip: Keep using Batch for independent, read-only tool calls.");
|
|
685
|
-
}
|
|
686
|
-
for (const result of output.results) {
|
|
687
|
-
const reason = result.error ? ` (${result.error})` : "";
|
|
688
|
-
lines.push(
|
|
689
|
-
`- ${result.tool}: ${result.success ? "success" : "error"}${reason}`
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
return lines.join("\n");
|
|
693
|
-
}
|
|
694
|
-
function preprocessToolInputForBatch(tool, input) {
|
|
695
|
-
if (tool.name === "TaskOutput") {
|
|
696
|
-
const task_id = typeof input.task_id === "string" && input.task_id || typeof input.agentId === "string" && String(input.agentId) || typeof input.bash_id === "string" && String(input.bash_id) || "";
|
|
697
|
-
const block = typeof input.block === "boolean" ? input.block : true;
|
|
698
|
-
const timeout = typeof input.timeout === "number" ? input.timeout : typeof input.wait_up_to === "number" ? Number(input.wait_up_to) * 1e3 : void 0;
|
|
699
|
-
return {
|
|
700
|
-
task_id,
|
|
701
|
-
block,
|
|
702
|
-
...timeout !== void 0 ? { timeout } : {}
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
return input;
|
|
706
|
-
}
|
|
707
|
-
function normalizeToolInputForBatch(tool, input) {
|
|
708
|
-
if (tool.name === "Bash") {
|
|
709
|
-
const parsed = tool.inputSchema.parse(input);
|
|
710
|
-
const {
|
|
711
|
-
command,
|
|
712
|
-
timeout,
|
|
713
|
-
description,
|
|
714
|
-
run_in_background,
|
|
715
|
-
dangerouslyDisableSandbox
|
|
716
|
-
} = parsed;
|
|
717
|
-
return {
|
|
718
|
-
command: String(command).replace(`cd ${getCwd()} && `, "").replace(/\\\\;/g, "\\;"),
|
|
719
|
-
...timeout !== void 0 ? { timeout } : {},
|
|
720
|
-
...description ? { description } : {},
|
|
721
|
-
...run_in_background ? { run_in_background } : {},
|
|
722
|
-
...dangerouslyDisableSandbox ? { dangerouslyDisableSandbox } : {}
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
return input;
|
|
726
|
-
}
|
|
727
|
-
async function executeToolCall({
|
|
728
|
-
tool,
|
|
729
|
-
toolName,
|
|
730
|
-
parameters,
|
|
731
|
-
paramSummary,
|
|
732
|
-
context,
|
|
733
|
-
toolUseId
|
|
734
|
-
}) {
|
|
735
|
-
const preprocessedInput = preprocessToolInputForBatch(tool, parameters);
|
|
736
|
-
const parsedInput = tool.inputSchema.safeParse(preprocessedInput);
|
|
737
|
-
if (!parsedInput.success) {
|
|
738
|
-
return {
|
|
739
|
-
tool: toolName,
|
|
740
|
-
success: false,
|
|
741
|
-
error: `InputValidationError: ${parsedInput.error.message}`,
|
|
742
|
-
paramSummary
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
let normalizedInput = normalizeToolInputForBatch(
|
|
746
|
-
tool,
|
|
747
|
-
parsedInput.data
|
|
748
|
-
);
|
|
749
|
-
if (tool.validateInput) {
|
|
750
|
-
const validated = await tool.validateInput(
|
|
751
|
-
normalizedInput,
|
|
752
|
-
context
|
|
753
|
-
);
|
|
754
|
-
if (validated?.result === false) {
|
|
755
|
-
return {
|
|
756
|
-
tool: toolName,
|
|
757
|
-
success: false,
|
|
758
|
-
error: validated.message,
|
|
759
|
-
paramSummary
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
const hookOutcome = await runPreToolUseHooks({
|
|
764
|
-
toolName: tool.name,
|
|
765
|
-
toolInput: normalizedInput,
|
|
766
|
-
toolUseId,
|
|
767
|
-
permissionMode: context.options?.toolPermissionContext?.mode,
|
|
768
|
-
cwd: getCwd(),
|
|
769
|
-
transcriptPath: getHookTranscriptPath(context),
|
|
770
|
-
safeMode: context.options?.safeMode ?? false,
|
|
771
|
-
signal: context.abortController?.signal
|
|
772
|
-
});
|
|
773
|
-
if (hookOutcome.kind === "block") {
|
|
774
|
-
return {
|
|
775
|
-
tool: toolName,
|
|
776
|
-
success: false,
|
|
777
|
-
error: hookOutcome.message,
|
|
778
|
-
paramSummary
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
if (hookOutcome.systemMessages && hookOutcome.systemMessages.length > 0) {
|
|
782
|
-
queueHookSystemMessages(context, hookOutcome.systemMessages);
|
|
783
|
-
}
|
|
784
|
-
if (hookOutcome.additionalContexts && hookOutcome.additionalContexts.length > 0) {
|
|
785
|
-
queueHookAdditionalContexts(context, hookOutcome.additionalContexts);
|
|
786
|
-
}
|
|
787
|
-
if (hookOutcome.updatedInput) {
|
|
788
|
-
const merged = { ...normalizedInput, ...hookOutcome.updatedInput };
|
|
789
|
-
const parsed = tool.inputSchema.safeParse(merged);
|
|
790
|
-
if (!parsed.success) {
|
|
791
|
-
return {
|
|
792
|
-
tool: toolName,
|
|
793
|
-
success: false,
|
|
794
|
-
error: `Hook updatedInput failed validation: ${parsed.error.message}`,
|
|
795
|
-
paramSummary
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
normalizedInput = normalizeToolInputForBatch(
|
|
799
|
-
tool,
|
|
800
|
-
parsed.data
|
|
801
|
-
);
|
|
802
|
-
const isValidUpdate = await tool.validateInput?.(
|
|
803
|
-
normalizedInput,
|
|
804
|
-
context
|
|
805
|
-
);
|
|
806
|
-
if (isValidUpdate?.result === false) {
|
|
807
|
-
return {
|
|
808
|
-
tool: toolName,
|
|
809
|
-
success: false,
|
|
810
|
-
error: isValidUpdate.message,
|
|
811
|
-
paramSummary
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
const hookPermissionDecision = hookOutcome.kind === "allow" ? hookOutcome.permissionDecision : void 0;
|
|
816
|
-
const effectiveShouldSkipPermissionCheck = hookPermissionDecision === "allow" ? true : hookPermissionDecision === "ask" ? false : false;
|
|
817
|
-
const permissionContextForCall = hookPermissionDecision === "ask" && context.options?.toolPermissionContext && context.options.toolPermissionContext.mode !== "default" ? {
|
|
818
|
-
...context,
|
|
819
|
-
options: {
|
|
820
|
-
...context.options,
|
|
821
|
-
toolPermissionContext: {
|
|
822
|
-
...context.options.toolPermissionContext,
|
|
823
|
-
mode: "default"
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
} : context;
|
|
827
|
-
const permissionResult = effectiveShouldSkipPermissionCheck ? { result: true } : await hasPermissionsToUseTool(
|
|
828
|
-
tool,
|
|
829
|
-
normalizedInput,
|
|
830
|
-
{ ...permissionContextForCall, toolUseId },
|
|
831
|
-
{}
|
|
832
|
-
);
|
|
833
|
-
if (permissionResult.result === false) {
|
|
834
|
-
return {
|
|
835
|
-
tool: toolName,
|
|
836
|
-
success: false,
|
|
837
|
-
error: permissionResult.message,
|
|
838
|
-
paramSummary
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
try {
|
|
842
|
-
const generator = tool.call(normalizedInput, {
|
|
843
|
-
...context,
|
|
844
|
-
toolUseId
|
|
845
|
-
});
|
|
846
|
-
let data;
|
|
847
|
-
let resultForAssistant;
|
|
848
|
-
for await (const step of generator) {
|
|
849
|
-
if (step.type === "result") {
|
|
850
|
-
data = step.data;
|
|
851
|
-
resultForAssistant = step.resultForAssistant;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
if (data === void 0) {
|
|
855
|
-
return {
|
|
856
|
-
tool: toolName,
|
|
857
|
-
success: false,
|
|
858
|
-
error: "Tool returned no result",
|
|
859
|
-
paramSummary
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
const postOutcome = await runPostToolUseHooks({
|
|
863
|
-
toolName: tool.name,
|
|
864
|
-
toolInput: normalizedInput,
|
|
865
|
-
toolResult: data,
|
|
866
|
-
toolUseId,
|
|
867
|
-
permissionMode: context.options?.toolPermissionContext?.mode,
|
|
868
|
-
cwd: getCwd(),
|
|
869
|
-
transcriptPath: getHookTranscriptPath(context),
|
|
870
|
-
safeMode: context.options?.safeMode ?? false,
|
|
871
|
-
signal: context.abortController?.signal
|
|
872
|
-
});
|
|
873
|
-
if (postOutcome.systemMessages.length > 0) {
|
|
874
|
-
queueHookSystemMessages(context, postOutcome.systemMessages);
|
|
875
|
-
}
|
|
876
|
-
if (postOutcome.additionalContexts.length > 0) {
|
|
877
|
-
queueHookAdditionalContexts(context, postOutcome.additionalContexts);
|
|
878
|
-
}
|
|
879
|
-
return {
|
|
880
|
-
tool: toolName,
|
|
881
|
-
success: true,
|
|
882
|
-
data,
|
|
883
|
-
paramSummary,
|
|
884
|
-
...resultForAssistant ? { resultForAssistant } : { resultForAssistant: tool.renderResultForAssistant(data) }
|
|
885
|
-
};
|
|
886
|
-
} catch (error) {
|
|
887
|
-
return {
|
|
888
|
-
tool: toolName,
|
|
889
|
-
success: false,
|
|
890
|
-
error: error instanceof Error ? error.message : String(error),
|
|
891
|
-
paramSummary
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
var BatchTool = {
|
|
896
|
-
name: TOOL_NAME_FOR_PROMPT,
|
|
897
|
-
async description() {
|
|
898
|
-
return DESCRIPTION;
|
|
899
|
-
},
|
|
900
|
-
userFacingName() {
|
|
901
|
-
return "Batch";
|
|
902
|
-
},
|
|
903
|
-
inputSchema: inputSchema2,
|
|
904
|
-
isReadOnly() {
|
|
905
|
-
return false;
|
|
906
|
-
},
|
|
907
|
-
isConcurrencySafe() {
|
|
908
|
-
return false;
|
|
909
|
-
},
|
|
910
|
-
async isEnabled() {
|
|
911
|
-
return true;
|
|
912
|
-
},
|
|
913
|
-
needsPermissions() {
|
|
914
|
-
return false;
|
|
915
|
-
},
|
|
916
|
-
async prompt() {
|
|
917
|
-
return PROMPT;
|
|
918
|
-
},
|
|
919
|
-
renderToolUseMessage({ tool_calls }) {
|
|
920
|
-
const list = formatBatchToolList(tool_calls);
|
|
921
|
-
return list ? `Batch running: ${list}` : `Batch ${tool_calls.length} tool call(s)`;
|
|
922
|
-
},
|
|
923
|
-
renderToolUseRejectedMessage() {
|
|
924
|
-
return /* @__PURE__ */ React2.createElement(FallbackToolUseRejectedMessage, null);
|
|
925
|
-
},
|
|
926
|
-
renderToolResultMessage(output) {
|
|
927
|
-
return /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column" }, /* @__PURE__ */ React2.createElement(Text2, null, "Batch evaluation: ", output.success, "/", output.total, " successful"), output.notes.map((note, index) => /* @__PURE__ */ React2.createElement(React2.Fragment, { key: `${note}-${index}` }, /* @__PURE__ */ React2.createElement(Text2, null, note))), output.results.map((result, index) => /* @__PURE__ */ React2.createElement(React2.Fragment, { key: `${result.tool}-${index}` }, /* @__PURE__ */ React2.createElement(Text2, null, `- ${result.tool}${result.paramSummary ? `: ${result.paramSummary}` : ""}`))));
|
|
928
|
-
},
|
|
929
|
-
renderResultForAssistant(output) {
|
|
930
|
-
return formatBatchSummary(output);
|
|
931
|
-
},
|
|
932
|
-
async validateInput({ tool_calls }) {
|
|
933
|
-
const hasNestedBatch = tool_calls.some((call) => isBatchToolName(call.tool));
|
|
934
|
-
if (hasNestedBatch) {
|
|
935
|
-
return {
|
|
936
|
-
result: false,
|
|
937
|
-
message: "Do NOT use batch within batch",
|
|
938
|
-
errorCode: 1
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
return { result: true };
|
|
942
|
-
},
|
|
943
|
-
async *call({ tool_calls }, context) {
|
|
944
|
-
const toolMap = new Map(
|
|
945
|
-
(context.options?.tools ?? []).map((tool) => [tool.name, tool])
|
|
946
|
-
);
|
|
947
|
-
const notes = [];
|
|
948
|
-
const allowedCalls = tool_calls.slice(0, MAX_BATCH_TOOLS);
|
|
949
|
-
const extraCalls = tool_calls.slice(MAX_BATCH_TOOLS);
|
|
950
|
-
let sawExcluded = false;
|
|
951
|
-
if (allowedCalls.length > 0) {
|
|
952
|
-
const list = formatBatchToolList(allowedCalls);
|
|
953
|
-
yield {
|
|
954
|
-
type: "progress",
|
|
955
|
-
content: createAssistantMessage(
|
|
956
|
-
`<tool-progress>Batch running: ${list}</tool-progress>`
|
|
957
|
-
)
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
const executionResults = await Promise.all(
|
|
961
|
-
allowedCalls.map(async (call, index) => {
|
|
962
|
-
const name = call.tool;
|
|
963
|
-
const toolUseId = `${context.toolUseId ?? "batch"}:${index + 1}`;
|
|
964
|
-
const paramSummary = formatBatchParamSummary(call.parameters ?? {});
|
|
965
|
-
if (isMcpToolName(name) || isMarketplaceToolName(name) || isSkillToolName(name)) {
|
|
966
|
-
sawExcluded = true;
|
|
967
|
-
return {
|
|
968
|
-
tool: name,
|
|
969
|
-
success: false,
|
|
970
|
-
error: "Excluded MCP/marketplace/Skill tools",
|
|
971
|
-
paramSummary
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
const tool = toolMap.get(name);
|
|
975
|
-
if (!tool) {
|
|
976
|
-
return {
|
|
977
|
-
tool: name,
|
|
978
|
-
success: false,
|
|
979
|
-
error: "Tool not in registry",
|
|
980
|
-
paramSummary
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
if (!tool.isReadOnly() || !tool.isConcurrencySafe()) {
|
|
984
|
-
return {
|
|
985
|
-
tool: name,
|
|
986
|
-
success: false,
|
|
987
|
-
error: "Tool is not read-only or concurrency-safe",
|
|
988
|
-
paramSummary
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
return executeToolCall({
|
|
992
|
-
tool,
|
|
993
|
-
toolName: name,
|
|
994
|
-
parameters: call.parameters ?? {},
|
|
995
|
-
paramSummary,
|
|
996
|
-
context,
|
|
997
|
-
toolUseId
|
|
998
|
-
});
|
|
999
|
-
})
|
|
1000
|
-
);
|
|
1001
|
-
const results = [...executionResults];
|
|
1002
|
-
if (extraCalls.length > 0) {
|
|
1003
|
-
for (const call of extraCalls) {
|
|
1004
|
-
results.push({
|
|
1005
|
-
tool: call.tool,
|
|
1006
|
-
success: false,
|
|
1007
|
-
error: "Maximum of 10 tools allowed in batch",
|
|
1008
|
-
paramSummary: formatBatchParamSummary(call.parameters ?? {})
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
notes.push("Maximum of 10 tools allowed in batch");
|
|
1012
|
-
}
|
|
1013
|
-
if (sawExcluded) {
|
|
1014
|
-
notes.push("Excluded MCP/marketplace/Skill tools");
|
|
1015
|
-
}
|
|
1016
|
-
const success = results.filter((r) => r.success).length;
|
|
1017
|
-
const failed = results.length - success;
|
|
1018
|
-
const output = {
|
|
1019
|
-
total: tool_calls.length,
|
|
1020
|
-
success,
|
|
1021
|
-
failed,
|
|
1022
|
-
results,
|
|
1023
|
-
notes
|
|
1024
|
-
};
|
|
1025
|
-
yield {
|
|
1026
|
-
type: "result",
|
|
1027
|
-
data: output,
|
|
1028
|
-
resultForAssistant: this.renderResultForAssistant(output)
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
};
|
|
1032
|
-
|
|
1033
|
-
// src/tools/system/TaskOutputTool/TaskOutputTool.tsx
|
|
1034
|
-
import { Box as Box3, Text as Text3 } from "ink";
|
|
1035
|
-
import React3 from "react";
|
|
1036
|
-
import { z as z3 } from "zod";
|
|
1037
|
-
|
|
1038
564
|
// src/utils/session/backgroundTasks.ts
|
|
1039
565
|
var backgroundTasks = /* @__PURE__ */ new Map();
|
|
1040
566
|
function getBackgroundAgentTaskSnapshot(agentId) {
|
|
@@ -1148,9 +674,9 @@ function maybeTruncateVerboseToolOutput(text, options) {
|
|
|
1148
674
|
}
|
|
1149
675
|
|
|
1150
676
|
// src/tools/system/TaskOutputTool/prompt.ts
|
|
1151
|
-
var
|
|
1152
|
-
var
|
|
1153
|
-
var
|
|
677
|
+
var TOOL_NAME_FOR_PROMPT = "TaskOutput";
|
|
678
|
+
var DESCRIPTION = "Retrieves output from a running or completed task";
|
|
679
|
+
var PROMPT = `- Retrieves output from a running or completed task (background shell, agent, or remote session)
|
|
1154
680
|
- Takes a task_id parameter identifying the task
|
|
1155
681
|
- Returns the task output along with status information
|
|
1156
682
|
- Use block=true (default) to wait for task completion
|
|
@@ -1159,11 +685,11 @@ var PROMPT2 = `- Retrieves output from a running or completed task (background s
|
|
|
1159
685
|
- Works with all task types: background shells, async agents, and remote sessions`;
|
|
1160
686
|
|
|
1161
687
|
// src/tools/system/TaskOutputTool/TaskOutputTool.tsx
|
|
1162
|
-
var
|
|
1163
|
-
task_id:
|
|
1164
|
-
block:
|
|
1165
|
-
timeout:
|
|
1166
|
-
analyze:
|
|
688
|
+
var inputSchema2 = z2.strictObject({
|
|
689
|
+
task_id: z2.string().describe("The task ID to get output from"),
|
|
690
|
+
block: z2.boolean().optional().default(true).describe("Whether to wait for completion"),
|
|
691
|
+
timeout: z2.number().min(0).max(6e5).optional().default(3e4).describe("Max wait time in ms"),
|
|
692
|
+
analyze: z2.boolean().optional().describe("Analyze the output for errors and warnings")
|
|
1167
693
|
});
|
|
1168
694
|
function normalizeTaskOutputInput(input) {
|
|
1169
695
|
const task_id = typeof input.task_id === "string" && input.task_id || typeof input.agentId === "string" && String(input.agentId) || typeof input.bash_id === "string" && String(input.bash_id) || "";
|
|
@@ -1223,7 +749,7 @@ async function analyzeOutputWithLsp(output, exitCode) {
|
|
|
1223
749
|
if (exitCode !== 0) {
|
|
1224
750
|
try {
|
|
1225
751
|
const { isAbsolute: isAbsolute3, resolve: resolve4 } = await import("path");
|
|
1226
|
-
const { getCwd: getCwd2 } = await import("./state-
|
|
752
|
+
const { getCwd: getCwd2 } = await import("./state-BVQ44522.js");
|
|
1227
753
|
const lines = output.split("\n");
|
|
1228
754
|
const uniqueFiles = /* @__PURE__ */ new Set();
|
|
1229
755
|
const lspSuggestions = [];
|
|
@@ -1281,14 +807,14 @@ async function waitForBashTaskCompletion(args) {
|
|
|
1281
807
|
return buildTaskSummary(taskId);
|
|
1282
808
|
}
|
|
1283
809
|
var TaskOutputTool = {
|
|
1284
|
-
name:
|
|
810
|
+
name: TOOL_NAME_FOR_PROMPT,
|
|
1285
811
|
async description() {
|
|
1286
|
-
return
|
|
812
|
+
return DESCRIPTION;
|
|
1287
813
|
},
|
|
1288
814
|
userFacingName() {
|
|
1289
815
|
return "Task Output";
|
|
1290
816
|
},
|
|
1291
|
-
inputSchema:
|
|
817
|
+
inputSchema: inputSchema2,
|
|
1292
818
|
isReadOnly() {
|
|
1293
819
|
return true;
|
|
1294
820
|
},
|
|
@@ -1302,7 +828,7 @@ var TaskOutputTool = {
|
|
|
1302
828
|
return false;
|
|
1303
829
|
},
|
|
1304
830
|
async prompt() {
|
|
1305
|
-
return
|
|
831
|
+
return PROMPT;
|
|
1306
832
|
},
|
|
1307
833
|
renderToolUseMessage(input) {
|
|
1308
834
|
const normalized = normalizeTaskOutputInput(input);
|
|
@@ -1315,26 +841,26 @@ var TaskOutputTool = {
|
|
|
1315
841
|
renderToolResultMessage(output, { verbose }) {
|
|
1316
842
|
const theme = getTheme();
|
|
1317
843
|
if (output.retrieval_status === "timeout" || output.retrieval_status === "not_ready") {
|
|
1318
|
-
return /* @__PURE__ */
|
|
844
|
+
return /* @__PURE__ */ React2.createElement(Box2, null, /* @__PURE__ */ React2.createElement(Text2, { color: theme.secondaryText }, "Task is still running\u2026"));
|
|
1319
845
|
}
|
|
1320
846
|
if (!output.task) {
|
|
1321
|
-
return /* @__PURE__ */
|
|
847
|
+
return /* @__PURE__ */ React2.createElement(Box2, null, /* @__PURE__ */ React2.createElement(Text2, { color: theme.secondaryText }, "No task output available"));
|
|
1322
848
|
}
|
|
1323
849
|
if (output.task.task_type === "local_agent") {
|
|
1324
850
|
const lines = output.task.result ? output.task.result.split("\n").length : 0;
|
|
1325
851
|
if (!verbose) {
|
|
1326
|
-
return /* @__PURE__ */
|
|
852
|
+
return /* @__PURE__ */ React2.createElement(Box2, null, /* @__PURE__ */ React2.createElement(Text2, { color: theme.secondaryText }, "Read output (ctrl+o to expand)"));
|
|
1327
853
|
}
|
|
1328
|
-
return /* @__PURE__ */
|
|
854
|
+
return /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column" }, /* @__PURE__ */ React2.createElement(Text2, null, output.task.description, " (", lines, " lines)"), output.task.prompt ? /* @__PURE__ */ React2.createElement(Box2, { paddingLeft: 2 }, /* @__PURE__ */ React2.createElement(Text2, { color: theme.secondaryText }, output.task.prompt)) : null, output.task.result ? /* @__PURE__ */ React2.createElement(Box2, { paddingLeft: 2, marginTop: 1 }, /* @__PURE__ */ React2.createElement(Text2, null, maybeTruncateVerboseToolOutput(output.task.result, {
|
|
1329
855
|
maxLines: 200,
|
|
1330
856
|
maxChars: 4e4
|
|
1331
|
-
}).text)) : null, output.task.error ? /* @__PURE__ */
|
|
857
|
+
}).text)) : null, output.task.error ? /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", marginTop: 1, paddingLeft: 2 }, /* @__PURE__ */ React2.createElement(Text2, { color: theme.error, bold: true }, "Error:"), /* @__PURE__ */ React2.createElement(Text2, { color: theme.error }, output.task.error)) : null);
|
|
1332
858
|
}
|
|
1333
859
|
const content = output.task.output?.trimEnd() ?? "";
|
|
1334
860
|
if (!verbose) {
|
|
1335
|
-
return /* @__PURE__ */
|
|
861
|
+
return /* @__PURE__ */ React2.createElement(Box2, null, /* @__PURE__ */ React2.createElement(Text2, { color: theme.secondaryText }, content.length > 0 ? "Read output (ctrl+o to expand)" : "(No content)"));
|
|
1336
862
|
}
|
|
1337
|
-
return /* @__PURE__ */
|
|
863
|
+
return /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column" }, /* @__PURE__ */ React2.createElement(Text2, { color: theme.secondaryText }, output.task.description), content ? /* @__PURE__ */ React2.createElement(Box2, { paddingLeft: 2, marginTop: 1 }, /* @__PURE__ */ React2.createElement(Text2, null, maybeTruncateVerboseToolOutput(content, {
|
|
1338
864
|
maxLines: 200,
|
|
1339
865
|
maxChars: 4e4
|
|
1340
866
|
}).text)) : null);
|
|
@@ -1463,13 +989,13 @@ ${output.task.output.trimEnd()}
|
|
|
1463
989
|
|
|
1464
990
|
// src/tools/filesystem/DeleteTool/DeleteTool.tsx
|
|
1465
991
|
import { rmSync, existsSync as existsSync2, statSync } from "fs";
|
|
1466
|
-
import { Box as
|
|
1467
|
-
import * as
|
|
1468
|
-
import { z as
|
|
992
|
+
import { Box as Box3, Text as Text3 } from "ink";
|
|
993
|
+
import * as React3 from "react";
|
|
994
|
+
import { z as z3 } from "zod";
|
|
1469
995
|
import { isAbsolute, relative, resolve } from "path";
|
|
1470
996
|
|
|
1471
997
|
// src/tools/filesystem/DeleteTool/prompt.ts
|
|
1472
|
-
var
|
|
998
|
+
var PROMPT2 = `You can use this tool to delete files (regular file or directory), you can delete multi files in one toolcall, and you MUST make sure the files is exist before deleting.
|
|
1473
999
|
When you need to delete file, you MUST use this tool to delete file instead of using shell.
|
|
1474
1000
|
|
|
1475
1001
|
Usage:
|
|
@@ -1517,11 +1043,11 @@ Delete({
|
|
|
1517
1043
|
`;
|
|
1518
1044
|
|
|
1519
1045
|
// src/tools/filesystem/DeleteTool/DeleteTool.tsx
|
|
1520
|
-
var
|
|
1521
|
-
file_paths:
|
|
1046
|
+
var inputSchema3 = z3.strictObject({
|
|
1047
|
+
file_paths: z3.array(z3.string()).describe(
|
|
1522
1048
|
"The list of file paths you want to delete, you MUST set file path to absolute path."
|
|
1523
1049
|
),
|
|
1524
|
-
force:
|
|
1050
|
+
force: z3.boolean().optional().describe(
|
|
1525
1051
|
"Force deletion even if the file is referenced by other files (LSP check)."
|
|
1526
1052
|
)
|
|
1527
1053
|
});
|
|
@@ -1532,9 +1058,9 @@ var DeleteTool = {
|
|
|
1532
1058
|
},
|
|
1533
1059
|
userFacingName: () => "Delete",
|
|
1534
1060
|
async prompt() {
|
|
1535
|
-
return
|
|
1061
|
+
return PROMPT2;
|
|
1536
1062
|
},
|
|
1537
|
-
inputSchema:
|
|
1063
|
+
inputSchema: inputSchema3,
|
|
1538
1064
|
async isEnabled() {
|
|
1539
1065
|
return true;
|
|
1540
1066
|
},
|
|
@@ -1554,7 +1080,7 @@ var DeleteTool = {
|
|
|
1554
1080
|
return `Deleting: ${paths}`;
|
|
1555
1081
|
},
|
|
1556
1082
|
renderToolResultMessage(output) {
|
|
1557
|
-
return /* @__PURE__ */
|
|
1083
|
+
return /* @__PURE__ */ React3.createElement(Box3, { flexDirection: "column" }, output.deleted.length > 0 && /* @__PURE__ */ React3.createElement(Text3, null, "Deleted: ", output.deleted.join(", ")), output.failed.length > 0 && /* @__PURE__ */ React3.createElement(Text3, { color: getTheme().warning }, "Failed to delete: ", output.failed.join(", ")));
|
|
1558
1084
|
},
|
|
1559
1085
|
renderResultForAssistant(output) {
|
|
1560
1086
|
const parts = [];
|
|
@@ -1564,9 +1090,9 @@ var DeleteTool = {
|
|
|
1564
1090
|
},
|
|
1565
1091
|
renderToolUseRejectedMessage({ file_paths } = {}, { columns, verbose } = {}) {
|
|
1566
1092
|
if (!file_paths || file_paths.length === 0) {
|
|
1567
|
-
return /* @__PURE__ */
|
|
1093
|
+
return /* @__PURE__ */ React3.createElement(FallbackToolUseRejectedMessage, null);
|
|
1568
1094
|
}
|
|
1569
|
-
return /* @__PURE__ */
|
|
1095
|
+
return /* @__PURE__ */ React3.createElement(Box3, { flexDirection: "column" }, /* @__PURE__ */ React3.createElement(Text3, null, " ", "\u23BF", " ", /* @__PURE__ */ React3.createElement(Text3, { color: getTheme().error }, "User rejected deletion of ", file_paths.length, " items")));
|
|
1570
1096
|
},
|
|
1571
1097
|
async *call({ file_paths, force }, context) {
|
|
1572
1098
|
const verbose = context.options?.verbose || false;
|
|
@@ -1581,7 +1107,7 @@ var DeleteTool = {
|
|
|
1581
1107
|
}
|
|
1582
1108
|
if (!force) {
|
|
1583
1109
|
try {
|
|
1584
|
-
const { LspFacade: LspFacade2 } = await import("./lsp-
|
|
1110
|
+
const { LspFacade: LspFacade2 } = await import("./lsp-S2GYO6LP.js");
|
|
1585
1111
|
const referenceDetail = await LspFacade2.checkFileReferences(fullPath);
|
|
1586
1112
|
if (referenceDetail) {
|
|
1587
1113
|
failedItems.push(
|
|
@@ -1627,20 +1153,20 @@ var DeleteTool = {
|
|
|
1627
1153
|
};
|
|
1628
1154
|
|
|
1629
1155
|
// src/tools/mcp/ListMcpResourcesTool/ListMcpResourcesTool.tsx
|
|
1630
|
-
import { Box as
|
|
1631
|
-
import
|
|
1632
|
-
import { z as
|
|
1156
|
+
import { Box as Box4, Text as Text4 } from "ink";
|
|
1157
|
+
import React4 from "react";
|
|
1158
|
+
import { z as z4 } from "zod";
|
|
1633
1159
|
import { ListResourcesResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
1634
1160
|
|
|
1635
1161
|
// src/tools/mcp/ListMcpResourcesTool/prompt.ts
|
|
1636
1162
|
var TOOL_NAME = "ListMcpResourcesTool";
|
|
1637
|
-
var
|
|
1163
|
+
var DESCRIPTION2 = `Lists available resources from configured MCP servers.
|
|
1638
1164
|
Each resource object includes a 'server' field indicating which server it's from.
|
|
1639
1165
|
|
|
1640
1166
|
Usage examples:
|
|
1641
1167
|
- List all resources from all servers: \`listMcpResources\`
|
|
1642
1168
|
- List resources from a specific server: \`listMcpResources({ server: "myserver" })\``;
|
|
1643
|
-
var
|
|
1169
|
+
var PROMPT3 = `List available resources from configured MCP servers.
|
|
1644
1170
|
Each returned resource will include all standard MCP resource fields plus a 'server' field
|
|
1645
1171
|
indicating which server the resource belongs to.
|
|
1646
1172
|
|
|
@@ -1649,18 +1175,18 @@ Parameters:
|
|
|
1649
1175
|
resources from all servers will be returned.`;
|
|
1650
1176
|
|
|
1651
1177
|
// src/tools/mcp/ListMcpResourcesTool/ListMcpResourcesTool.tsx
|
|
1652
|
-
var
|
|
1653
|
-
server:
|
|
1178
|
+
var inputSchema4 = z4.strictObject({
|
|
1179
|
+
server: z4.string().optional().describe("Optional server name to filter resources by")
|
|
1654
1180
|
});
|
|
1655
1181
|
var ListMcpResourcesTool = {
|
|
1656
1182
|
name: TOOL_NAME,
|
|
1657
1183
|
async description() {
|
|
1658
|
-
return
|
|
1184
|
+
return DESCRIPTION2;
|
|
1659
1185
|
},
|
|
1660
1186
|
async prompt() {
|
|
1661
|
-
return
|
|
1187
|
+
return PROMPT3;
|
|
1662
1188
|
},
|
|
1663
|
-
inputSchema:
|
|
1189
|
+
inputSchema: inputSchema4,
|
|
1664
1190
|
userFacingName() {
|
|
1665
1191
|
return "listMcpResources";
|
|
1666
1192
|
},
|
|
@@ -1693,10 +1219,10 @@ var ListMcpResourcesTool = {
|
|
|
1693
1219
|
return server ? `List MCP resources from server "${server}"` : "List all MCP resources";
|
|
1694
1220
|
},
|
|
1695
1221
|
renderToolUseRejectedMessage() {
|
|
1696
|
-
return /* @__PURE__ */
|
|
1222
|
+
return /* @__PURE__ */ React4.createElement(FallbackToolUseRejectedMessage, null);
|
|
1697
1223
|
},
|
|
1698
1224
|
renderToolResultMessage(output) {
|
|
1699
|
-
return /* @__PURE__ */
|
|
1225
|
+
return /* @__PURE__ */ React4.createElement(Box4, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React4.createElement(Box4, { flexDirection: "row" }, /* @__PURE__ */ React4.createElement(Text4, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React4.createElement(Text4, { bold: true }, output.length), /* @__PURE__ */ React4.createElement(Text4, null, " resources")), /* @__PURE__ */ React4.createElement(Cost, { costUSD: 0, durationMs: 0, debug: false }));
|
|
1700
1226
|
},
|
|
1701
1227
|
renderResultForAssistant(output) {
|
|
1702
1228
|
return JSON.stringify(output);
|
|
@@ -1744,35 +1270,36 @@ var ListMcpResourcesTool = {
|
|
|
1744
1270
|
}
|
|
1745
1271
|
};
|
|
1746
1272
|
|
|
1747
|
-
// src/tools/
|
|
1748
|
-
import { Box as
|
|
1749
|
-
import { isAbsolute as isAbsolute2, relative as relative2, resolve as resolve2, sep as sep2 } from "path";
|
|
1273
|
+
// src/tools/lsTool/lsTool.tsx
|
|
1274
|
+
import { Box as Box5, Text as Text5 } from "ink";
|
|
1275
|
+
import { basename, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve2, sep as sep2 } from "path";
|
|
1750
1276
|
import { readdirSync } from "fs";
|
|
1751
|
-
import * as
|
|
1752
|
-
import { z as
|
|
1277
|
+
import * as React5 from "react";
|
|
1278
|
+
import { z as z5 } from "zod";
|
|
1279
|
+
import { minimatch } from "minimatch";
|
|
1753
1280
|
|
|
1754
|
-
// src/tools/
|
|
1755
|
-
var
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
1.
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
-
|
|
1767
|
-
-
|
|
1768
|
-
-
|
|
1281
|
+
// src/tools/lsTool/prompt.ts
|
|
1282
|
+
var DESCRIPTION3 = `\u5217\u51FA\u6307\u5B9A\u76EE\u5F55\u4E2D\u6240\u6709\u6587\u4EF6\u4E0E\u76EE\u5F55\u6811\u5F62\u7ED3\u6784\u89C6\u56FE\u548C\u7EDF\u8BA1\u660E\u7EC6\u4FE1\u606F\u3002
|
|
1283
|
+
|
|
1284
|
+
\u7528\u6CD5\uFF1A
|
|
1285
|
+
1. **\u5FFD\u7565\u89C4\u5219**\uFF1A\u4F7F\u7528 \`ignore\` \u6392\u9664\u566A\u97F3\u8DEF\u5F84\u4EE5\u51CF\u5C11\u8F93\u51FA\u3002\u9ED8\u8BA4\u5FFD\u7565\u5E38\u89C1\u975E\u6838\u5FC3\u76EE\u5F55/\u6784\u5EFA\u4EA7\u7269/\u4F9D\u8D56\u7F13\u5B58\uFF08\u5982 node_modules\u3001dist\uFF09\u3002
|
|
1286
|
+
2. **\u76EE\u5F55\u7ED3\u6784\u4FE1\u606F**\uFF1A\u8F93\u51FA\u6307\u5B9A\u76EE\u5F55\u7ED3\u6784\u4E0E\u5305\u542B [\u76EE\u5F55\u7ED3\u6784\u4FE1\u606F] + [\u76EE\u5F55\u9876\u5C42\u7ED3\u6784\u89C6\u56FE] + [\u76EE\u5F55\u6838\u5FC3\u7ED3\u6784\u6811\u89C6\u56FE]\u7684\u4FE1\u606F\u3002
|
|
1287
|
+
|
|
1288
|
+
\u8BF4\u660E\uFF1A
|
|
1289
|
+
- BFS \u4F1A\u4F18\u5148\u5C55\u793A\u9876\u5C42\uFF08\u6839\u76EE\u5F55\uFF09\u7ED3\u6784\uFF0C\u5373\u4F7F\u8F93\u51FA\u88AB\u622A\u65AD\u3002
|
|
1290
|
+
- path \u53C2\u6570\u5FC5\u987B\u4E3A\u7EDD\u5BF9\u8DEF\u5F84\u3002
|
|
1291
|
+
|
|
1292
|
+
\u9002\u7528\u573A\u666F\uFF1A
|
|
1293
|
+
- \u5FEB\u901F\u4E86\u89E3\u9879\u76EE\u6216\u6307\u5B9A\u76EE\u5F55\u7684\u9876\u5C42\uFF08\u6839\u76EE\u5F55\uFF09\u7ED3\u6784\u4FE1\u606F\u548C\u76EE\u5F55\u6811\u7ED3\u6784\u4FE1\u606F
|
|
1294
|
+
- \u9700\u8981\u6DF1\u5165\u5206\u6790\u4EE3\u7801\u5E93\u6216\u529F\u80FD\u7B49\u65F6\u4F5C\u4E3A\u91CD\u8981\u7684\u5E7F\u5EA6\u4F18\u5148\u7684\u76EE\u5F55\u7ED3\u6784\u5206\u6790\u5DE5\u5177\u3002
|
|
1295
|
+
- \u521D\u6B21\u63A2\u7D22\u65B0\u9879\u76EE\u65F6\u3002
|
|
1296
|
+
- \u5728\u6587\u4EF6\u7CFB\u7EDF\u4E2D\u8FF7\u5931\u65B9\u5411\u65F6\u3002
|
|
1769
1297
|
`.trim();
|
|
1770
1298
|
|
|
1771
|
-
// src/tools/
|
|
1772
|
-
var MAX_FILES_LIMIT =
|
|
1299
|
+
// src/tools/lsTool/lsTool.tsx
|
|
1300
|
+
var MAX_FILES_LIMIT = 100;
|
|
1773
1301
|
var TOP_LEVEL_LIMIT = 2e3;
|
|
1774
|
-
var
|
|
1775
|
-
var DISPLAY_LINE_LIMIT = 10;
|
|
1302
|
+
var DISPLAY_LINE_LIMIT = 15;
|
|
1776
1303
|
var DEFAULT_IGNORE_PATTERNS = [
|
|
1777
1304
|
"node_modules/",
|
|
1778
1305
|
"__pycache__/",
|
|
@@ -1799,39 +1326,18 @@ var DEFAULT_IGNORE_PATTERNS = [
|
|
|
1799
1326
|
"venv/",
|
|
1800
1327
|
"env/"
|
|
1801
1328
|
];
|
|
1802
|
-
var
|
|
1803
|
-
path:
|
|
1329
|
+
var inputSchema5 = z5.object({
|
|
1330
|
+
path: z5.string().describe(
|
|
1804
1331
|
"The absolute path to the directory to list (must be absolute, not relative)"
|
|
1805
1332
|
),
|
|
1806
|
-
ignore:
|
|
1333
|
+
ignore: z5.array(z5.string()).optional().describe("List of glob patterns to ignore.")
|
|
1807
1334
|
}).passthrough();
|
|
1808
|
-
var buildTopLevelTree = (fullFilePath) => {
|
|
1809
|
-
const entries = readdirSync(fullFilePath, { withFileTypes: true });
|
|
1810
|
-
const directories = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
1811
|
-
const files = entries.filter((entry) => !entry.isDirectory()).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
1812
|
-
const items = [
|
|
1813
|
-
...directories.map((name) => ({ name, isDir: true })),
|
|
1814
|
-
...files.map((name) => ({ name, isDir: false }))
|
|
1815
|
-
];
|
|
1816
|
-
const totalCount = items.length;
|
|
1817
|
-
const truncated = totalCount > TOP_LEVEL_LIMIT;
|
|
1818
|
-
const limitedItems = truncated ? items.slice(0, TOP_LEVEL_LIMIT) : items;
|
|
1819
|
-
const limitedDirectories = limitedItems.filter((item) => item.isDir).map((item) => item.name);
|
|
1820
|
-
const limitedFiles = limitedItems.filter((item) => !item.isDir).map((item) => item.name);
|
|
1821
|
-
const rootLabel = fullFilePath.endsWith(sep2) ? fullFilePath : `${fullFilePath}${sep2}`;
|
|
1822
|
-
const treeOutput = renderTopLevelTree(
|
|
1823
|
-
rootLabel,
|
|
1824
|
-
limitedDirectories,
|
|
1825
|
-
limitedFiles
|
|
1826
|
-
);
|
|
1827
|
-
return { treeOutput, totalCount, truncated };
|
|
1828
|
-
};
|
|
1829
1335
|
var LSTool = {
|
|
1830
1336
|
name: "LS",
|
|
1831
1337
|
async description() {
|
|
1832
|
-
return
|
|
1338
|
+
return DESCRIPTION3;
|
|
1833
1339
|
},
|
|
1834
|
-
inputSchema:
|
|
1340
|
+
inputSchema: inputSchema5,
|
|
1835
1341
|
userFacingName() {
|
|
1836
1342
|
return "LS";
|
|
1837
1343
|
},
|
|
@@ -1848,7 +1354,7 @@ var LSTool = {
|
|
|
1848
1354
|
return !hasReadPermission(path);
|
|
1849
1355
|
},
|
|
1850
1356
|
async prompt() {
|
|
1851
|
-
return
|
|
1357
|
+
return DESCRIPTION3;
|
|
1852
1358
|
},
|
|
1853
1359
|
async validateInput({
|
|
1854
1360
|
limit,
|
|
@@ -1860,7 +1366,7 @@ var LSTool = {
|
|
|
1860
1366
|
if (typeof limit === "number" || typeof offset === "number" || typeof partition === "string") {
|
|
1861
1367
|
return {
|
|
1862
1368
|
result: false,
|
|
1863
|
-
message: "LS \u5F53\u524D\u4E0D\u652F\u6301 limit/offset/partition \u8DEF\u5F84\u5206\u7247\
|
|
1369
|
+
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",
|
|
1864
1370
|
errorCode: 1
|
|
1865
1371
|
};
|
|
1866
1372
|
}
|
|
@@ -1884,7 +1390,7 @@ var LSTool = {
|
|
|
1884
1390
|
return parts.join(", ");
|
|
1885
1391
|
},
|
|
1886
1392
|
renderToolUseRejectedMessage() {
|
|
1887
|
-
return /* @__PURE__ */
|
|
1393
|
+
return /* @__PURE__ */ React5.createElement(FallbackToolUseRejectedMessage, null);
|
|
1888
1394
|
},
|
|
1889
1395
|
renderToolResultMessage(content) {
|
|
1890
1396
|
const verbose = false;
|
|
@@ -1892,17 +1398,25 @@ var LSTool = {
|
|
|
1892
1398
|
return null;
|
|
1893
1399
|
}
|
|
1894
1400
|
const lines = content.split("\n");
|
|
1895
|
-
return /* @__PURE__ */
|
|
1401
|
+
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 : DISPLAY_LINE_LIMIT).map((line, i) => /* @__PURE__ */ React5.createElement(React5.Fragment, { key: i }, /* @__PURE__ */ React5.createElement(Text5, null, line))), !verbose && lines.length > DISPLAY_LINE_LIMIT && /* @__PURE__ */ React5.createElement(Text5, { color: getTheme().secondaryText }, "... (+", lines.length - DISPLAY_LINE_LIMIT, " lines)"))));
|
|
1896
1402
|
},
|
|
1897
1403
|
async *call({ path, ignore }, { abortController }) {
|
|
1898
1404
|
const fullFilePath = isAbsolute2(path) ? path : resolve2(getCwd(), path);
|
|
1899
|
-
const
|
|
1900
|
-
const
|
|
1405
|
+
const userIgnore = (ignore ?? []).filter(Boolean);
|
|
1406
|
+
const ignorePatterns = DEFAULT_IGNORE_PATTERNS.concat(userIgnore).filter(
|
|
1407
|
+
Boolean
|
|
1408
|
+
);
|
|
1409
|
+
const rgIgnoreGlobs = DEFAULT_IGNORE_PATTERNS.map(
|
|
1410
|
+
(pattern) => `!${pattern}*`
|
|
1411
|
+
).concat(userIgnore.map((pattern) => `!${pattern}`)).filter(Boolean);
|
|
1412
|
+
const rgArgs = [
|
|
1413
|
+
"--files",
|
|
1414
|
+
...rgIgnoreGlobs.flatMap((pattern) => ["--glob", pattern])
|
|
1415
|
+
];
|
|
1901
1416
|
const initialResult = await ripGrepWithStatus(
|
|
1902
1417
|
rgArgs,
|
|
1903
|
-
|
|
1904
|
-
abortController.signal
|
|
1905
|
-
{ cwd: fullFilePath }
|
|
1418
|
+
fullFilePath,
|
|
1419
|
+
abortController.signal
|
|
1906
1420
|
);
|
|
1907
1421
|
const files = initialResult.files;
|
|
1908
1422
|
const allEntries = files.map((file) => {
|
|
@@ -1911,50 +1425,79 @@ var LSTool = {
|
|
|
1911
1425
|
const normalized = relativePath.split(sep2).join("/");
|
|
1912
1426
|
return { absolutePath, relativePath, normalized };
|
|
1913
1427
|
});
|
|
1914
|
-
const
|
|
1428
|
+
const matchIgnorePatterns = ignorePatterns.map(
|
|
1429
|
+
(pattern) => pattern.endsWith("/") ? `${pattern}**` : pattern
|
|
1430
|
+
);
|
|
1431
|
+
const fileEntries = allEntries.filter((entry) => {
|
|
1432
|
+
if (matchIgnorePatterns.length === 0) return true;
|
|
1433
|
+
return !matchIgnorePatterns.some(
|
|
1434
|
+
(pattern) => minimatch(entry.normalized, pattern, { dot: true, nocase: false })
|
|
1435
|
+
);
|
|
1436
|
+
}).sort((a, b) => a.normalized.localeCompare(b.normalized));
|
|
1915
1437
|
const totalCount = fileEntries.length;
|
|
1916
1438
|
const truncated = totalCount > MAX_FILES_LIMIT;
|
|
1917
1439
|
const selectedEntries = truncated ? fileEntries.slice(0, MAX_FILES_LIMIT) : fileEntries;
|
|
1440
|
+
const excludedEntries = truncated ? fileEntries.slice(MAX_FILES_LIMIT) : [];
|
|
1918
1441
|
const selectedFiles = selectedEntries.map((entry) => entry.absolutePath);
|
|
1919
1442
|
let treeOutput = filesToTree(
|
|
1920
1443
|
selectedFiles,
|
|
1921
1444
|
fullFilePath,
|
|
1922
1445
|
Number.MAX_SAFE_INTEGER
|
|
1923
1446
|
);
|
|
1924
|
-
const
|
|
1925
|
-
|
|
1447
|
+
const topLevelResult = buildTopLevelTree(fullFilePath);
|
|
1448
|
+
const { totalDirectories, maxDepth } = getDirectoryStats(
|
|
1449
|
+
fileEntries.map((entry) => entry.normalized)
|
|
1450
|
+
);
|
|
1451
|
+
const selectedDirectories = getDirectorySet(
|
|
1452
|
+
selectedEntries.map((entry) => entry.normalized)
|
|
1453
|
+
);
|
|
1454
|
+
const excludedDirectories = getDirectorySet(
|
|
1455
|
+
excludedEntries.map((entry) => entry.normalized)
|
|
1456
|
+
);
|
|
1457
|
+
const notShownDirectoryCount = Array.from(excludedDirectories).filter(
|
|
1458
|
+
(dir) => !selectedDirectories.has(dir)
|
|
1459
|
+
).length;
|
|
1460
|
+
const notShownFileCount = truncated ? totalCount - selectedEntries.length : 0;
|
|
1461
|
+
const ratioText = totalCount === 0 ? "0.00" : (totalDirectories / totalCount).toFixed(2);
|
|
1462
|
+
const structureInfo = `[\u76EE\u5F55\u7ED3\u6784\u4FE1\u606F]\u9876\u5C42\u76EE\u5F55\u6570\uFF1A${topLevelResult.directoryCount}\u4E2A\uFF0C\u9876\u5C42\u6587\u4EF6\u6570\uFF1A${topLevelResult.fileCount}\u4E2A\uFF0C\u603B\u76EE\u5F55\u6570\uFF1A${totalDirectories}\u4E2A\uFF0C\u603B\u6587\u4EF6\u6570\uFF1A${totalCount}\u4E2A\uFF0C\u603B\u76EE\u5F55/\u603B\u6587\u4EF6\u6BD4\u4F8B=${ratioText}\uFF0C\u6700\u6DF1\u76EE\u5F55\u5C42\u7EA7=${maxDepth}\u3002\uFF08\u7EDF\u8BA1\u6570\u636E\u4E0D\u5305\u542B\u7A7A\u76EE\u5F55\u4EE5\u53CA\u5E38\u89C1\u975E\u6838\u5FC3\u76EE\u5F55/\u6784\u5EFA\u4EA7\u7269/\u4F9D\u8D56\u7F13\u5B58\u7B49\u6587\u4EF6\u6216\u76EE\u5F55\uFF09`;
|
|
1926
1463
|
const treeLines = treeOutput ? treeOutput.split("\n") : [];
|
|
1927
1464
|
const omittedLines = Math.max(0, treeLines.length - DISPLAY_LINE_LIMIT);
|
|
1928
1465
|
const warnings = [];
|
|
1929
1466
|
if (truncated) {
|
|
1930
1467
|
warnings.push(
|
|
1931
|
-
`
|
|
1468
|
+
`[\u76EE\u5F55\u6811\u622A\u65AD\u63D0\u9192]\u5F53\u524D\u76EE\u5F55\u7ED3\u6784\u56E0\u8D85\u8FC7\u5C55\u793A\u9600\u503C\u88AB\u622A\u65AD\uFF0C\u672A\u5C55\u793A\u6587\u4EF6\u6570=${notShownFileCount}\uFF0C\u672A\u663E\u793A\u76EE\u5F55\u6570=${notShownDirectoryCount}\uFF0C\u672A\u663E\u793A\u884C\u6570=${omittedLines} lines\uFF08\u7EDF\u8BA1\u6570\u636E\u4E0D\u5305\u542B\u7A7A\u76EE\u5F55\u4EE5\u53CA\u5E38\u89C1\u975E\u6838\u5FC3\u76EE\u5F55/\u6784\u5EFA\u4EA7\u7269/\u4F9D\u8D56\u7F13\u5B58\u7B49\u6587\u4EF6\u6216\u76EE\u5F55\uFF09\u3002\u8BE5\u8F93\u51FA\u4E3A\u90E8\u5206\u89C6\u56FE\uFF0C\u672A\u51FA\u73B0\u8DEF\u5F84\u4E0D\u5F97\u7528\u4E8E\u5B9A\u4F4D\u3002\u4F9D\u636E\u5F53\u524D\u9879\u76EE\u7ED3\u6784\u7EDF\u8BA1\u6570\u636E\uFF0C\u53EF\u521D\u6B65\u8FDB\u884C\u9879\u76EE\u7ED3\u6784\u590D\u6742\u5EA6\u5206\u6790\uFF1A1 \u603B\u76EE\u5F55/\u603B\u6587\u4EF6\u6BD4\u4F8B\u9AD8 \u2192 \u7ED3\u6784\u66F4\u788E\u3001\u5C42\u7EA7\u53EF\u80FD\u66F4\u7EC6\uFF0C\u590D\u6742\u5EA6\u503E\u5411\u66F4\u9AD8\u30022 \u6700\u6DF1\u5C42\u7EA7\u5927 \u2192 \u6DF1\u5C42\u5D4C\u5957\u660E\u663E\uFF0C\u5BFC\u822A\u4E0E\u5B9A\u4F4D\u6210\u672C\u66F4\u9AD8\u30023 \u9876\u5C42\u76EE\u5F55\u6570\u591A \u2192 \u6A21\u5757\u5165\u53E3\u5206\u6563\uFF0C\u9700\u66F4\u4E25\u683C\u5206\u5C42\u786E\u8BA4\u30024 \u6587\u4EF6\u603B\u91CF\u5927 \u2192 \u66F4\u5BB9\u6613\u89E6\u53D1\u8F93\u51FA\u622A\u65AD\u3002\u5904\u7406\u6D41\u7A0B\uFF1A\u590D\u6742\u5EA6\u4F4E \u2192 \u53EF\u76F4\u63A5 LS \u83B7\u53D6\u7ED3\u6784\u7EBF\u7D22\u540E\u8FDB\u5165\u5B9A\u4F4D\uFF1B\u590D\u6742\u5EA6\u9AD8 \u2192 \u5148\u7528 LS \u83B7\u53D6\u9876\u5C42\u7EBF\u7D22\uFF0C\u518D\u7528 Glob \u5206\u5C42\u786E\u8BA4\u8DEF\u5F84\u3002`
|
|
1932
1469
|
);
|
|
1933
|
-
warnings.push("\u5EFA\u8BAE\
|
|
1934
|
-
warnings.push("1) \
|
|
1935
|
-
warnings.push("2) \u7ED3\u5408\u9876\u5C42\
|
|
1936
|
-
warnings.push("3) \u5BF9\u5019\u9009\u76EE\u5F55\u6267\u884C Glob dir/* \u4E0E dir/*/\uFF0C\u786E\u8BA4\u8DEF\u5F84\u5B58\u5728\u3002");
|
|
1470
|
+
warnings.push("\u82E5\u9700\u6DF1\u5165\u5206\u6790\u5EFA\u8BAE\u5982\u4E0B\u5206\u6B65\u52A8\u4F5C\uFF08\u5C24\u5176\u76EE\u5F55\u7ED3\u6784\u590D\u6742\u5EA6\u8F83\u9AD8\u65F6\uFF09\uFF1A");
|
|
1471
|
+
warnings.push("1) \u5C06\u5F53\u524D\u9876\u5C42\u4F5C\u4E3A\u7EBF\u7D22\uFF0C\u518D\u7528 Glob \u5206\u5C42\u786E\u8BA4\u8DEF\u5F84\u6216\u7CBE\u786E\u5B9A\u5339\u914D\u3002");
|
|
1472
|
+
warnings.push("2) \u7ED3\u5408\u5B8C\u6574\u9876\u5C42\u76EE\u5F55\u7ED3\u6784\u4FE1\u606F\uFF0C\u5148\u5BF9\u5019\u9009\u76EE\u5F55\u6267\u884C Glob */\uFF08\u5FC5\u8981\u65F6 Ls\uFF09\u3002");
|
|
1473
|
+
warnings.push("3) \u5BF9\u5019\u9009\u76EE\u5F55\u6267\u884C Glob dir/* \u4E0E dir/*/\uFF08\u5FC5\u8981\u65F6 Ls\uFF09\uFF0C\u786E\u8BA4\u8DEF\u5F84\u5B58\u5728\u3002");
|
|
1937
1474
|
warnings.push("4) \u5728\u5DF2\u786E\u8BA4\u76EE\u5F55\u5185\u4F7F\u7528 Grep/\u8BED\u4E49\u641C\u7D22\u5B9A\u4F4D\u6587\u4EF6\u6216\u7B26\u53F7\u3002");
|
|
1938
|
-
if (totalCount >= 1e4 || omittedLines >= 200) {
|
|
1939
|
-
warnings.push(
|
|
1940
|
-
`\u9AD8\u590D\u6742\u5EA6\uFF1Acount>=10000 \u6216 \u672A\u663E\u793A\u884C\u6570>=200\u3002\u7ED3\u6784\u6811\u5177\u6709\u8BEF\u5BFC\u6027\uFF0C\u5FC5\u987B\u9010\u5C42\u786E\u8BA4\u8DEF\u5F84\u4E0E\u6587\u4EF6\u540D\u3002`
|
|
1941
|
-
);
|
|
1942
|
-
}
|
|
1943
1475
|
}
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
${TOP_LEVEL_HEADER}
|
|
1950
|
-
${topLevelResult.treeOutput}`;
|
|
1951
|
-
if (topLevelResult.truncated) {
|
|
1952
|
-
warnings.push(
|
|
1953
|
-
`TOP-LEVEL TRUNCATED: \u9876\u5C42\u6761\u76EE=${topLevelResult.totalCount}; \u4E0A\u9650=${TOP_LEVEL_LIMIT}\u3002\u5982\u9700\u5B8C\u6574\u7ED3\u679C\uFF0C\u9010\u5C42\u7F29\u5C0F\u8303\u56F4\u5E76\u5206\u6B65\u786E\u8BA4\u3002`
|
|
1954
|
-
);
|
|
1955
|
-
}
|
|
1476
|
+
if (topLevelResult.truncated) {
|
|
1477
|
+
warnings.push(
|
|
1478
|
+
`TOP-LEVEL TRUNCATED: \u9876\u5C42\u6761\u76EE=${topLevelResult.totalCount}; \u4E0A\u9650=${TOP_LEVEL_LIMIT}\u3002\u5982\u9700\u5B8C\u6574\u7ED3\u679C\uFF0C\u9010\u5C42\u7F29\u5C0F\u8303\u56F4\u5E76\u5206\u6B65\u786E\u8BA4\u3002`
|
|
1479
|
+
);
|
|
1956
1480
|
}
|
|
1957
|
-
const
|
|
1481
|
+
const rootLabel = fullFilePath.endsWith(sep2) ? fullFilePath : `${fullFilePath}${sep2}`;
|
|
1482
|
+
const topLevelView = `[\u76EE\u5F55\u9876\u5C42\u7ED3\u6784\u89C6\u56FE]
|
|
1483
|
+
${topLevelResult.treeOutput}`;
|
|
1484
|
+
const mainTreeHeader = truncated ? `[\u76EE\u5F55\u6838\u5FC3\u7ED3\u6784\u6811\u89C6\u56FE]\u6811\u7ED3\u6784\u8D85\u51FA\u9600\u503C\u88AB\u622A\u65AD\uFF0C\u672A\u663E\u793A\u6587\u4EF6\u6570=${notShownFileCount}\uFF0C\u672A\u663E\u793A\u76EE\u5F55\u6570=${notShownDirectoryCount}\uFF08\u7EDF\u8BA1\u6570\u636E\u4E0D\u5305\u542B\u7A7A\u76EE\u5F55\u4EE5\u53CA\u5E38\u89C1\u975E\u6838\u5FC3\u76EE\u5F55/\u6784\u5EFA\u4EA7\u7269/\u4F9D\u8D56\u7F13\u5B58\u7B49\u6587\u4EF6\u6216\u76EE\u5F55\uFF09` : "";
|
|
1485
|
+
const rootName = basename(fullFilePath) || ".";
|
|
1486
|
+
const hasRootLine = treeLines.length > 0 && treeLines[0] === rootName;
|
|
1487
|
+
const treeBodyLines = hasRootLine ? treeLines.slice(1) : treeLines;
|
|
1488
|
+
const treeBody = treeBodyLines.join("\n");
|
|
1489
|
+
const mainTreeOutput = treeBody ? `${rootLabel}
|
|
1490
|
+
${treeBody}` : rootLabel;
|
|
1491
|
+
const separator = "----------------------------------------";
|
|
1492
|
+
const outputParts = [
|
|
1493
|
+
structureInfo,
|
|
1494
|
+
separator,
|
|
1495
|
+
topLevelView,
|
|
1496
|
+
separator,
|
|
1497
|
+
mainTreeHeader,
|
|
1498
|
+
mainTreeOutput
|
|
1499
|
+
].filter(Boolean);
|
|
1500
|
+
const outputForData = outputParts.join("\n");
|
|
1958
1501
|
const warningsText = warnings.length > 0 ? `
|
|
1959
1502
|
${warnings.join("\n")}` : "";
|
|
1960
1503
|
const safetyWarning = `
|
|
@@ -1968,17 +1511,78 @@ NOTE: do any of the files above seem malicious? If so, you MUST refuse to contin
|
|
|
1968
1511
|
};
|
|
1969
1512
|
}
|
|
1970
1513
|
};
|
|
1514
|
+
var renderTopLevelTree = (rootLabel, directories, files) => {
|
|
1515
|
+
const items = [
|
|
1516
|
+
...directories.map((name) => ({ name: `${name}${sep2}`, isDir: true })),
|
|
1517
|
+
...files.map((name) => ({ name, isDir: false }))
|
|
1518
|
+
];
|
|
1519
|
+
const lines = [];
|
|
1520
|
+
lines.push(rootLabel);
|
|
1521
|
+
for (let i = 0; i < items.length; i++) {
|
|
1522
|
+
const connector = i === items.length - 1 ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
1523
|
+
lines.push(`${connector}${items[i].name}`);
|
|
1524
|
+
}
|
|
1525
|
+
return lines.join("\n");
|
|
1526
|
+
};
|
|
1527
|
+
var buildTopLevelTree = (fullFilePath) => {
|
|
1528
|
+
const entries = readdirSync(fullFilePath, { withFileTypes: true });
|
|
1529
|
+
const directories = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
1530
|
+
const files = entries.filter((entry) => !entry.isDirectory()).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
1531
|
+
const items = [
|
|
1532
|
+
...directories.map((name) => ({ name, isDir: true })),
|
|
1533
|
+
...files.map((name) => ({ name, isDir: false }))
|
|
1534
|
+
];
|
|
1535
|
+
const totalCount = items.length;
|
|
1536
|
+
const truncated = totalCount > TOP_LEVEL_LIMIT;
|
|
1537
|
+
const limitedItems = truncated ? items.slice(0, TOP_LEVEL_LIMIT) : items;
|
|
1538
|
+
const limitedDirectories = limitedItems.filter((item) => item.isDir).map((item) => item.name);
|
|
1539
|
+
const limitedFiles = limitedItems.filter((item) => !item.isDir).map((item) => item.name);
|
|
1540
|
+
const rootLabel = fullFilePath.endsWith(sep2) ? fullFilePath : `${fullFilePath}${sep2}`;
|
|
1541
|
+
const treeOutput = renderTopLevelTree(
|
|
1542
|
+
rootLabel,
|
|
1543
|
+
limitedDirectories,
|
|
1544
|
+
limitedFiles
|
|
1545
|
+
);
|
|
1546
|
+
return {
|
|
1547
|
+
treeOutput,
|
|
1548
|
+
totalCount,
|
|
1549
|
+
truncated,
|
|
1550
|
+
directoryCount: directories.length,
|
|
1551
|
+
fileCount: files.length
|
|
1552
|
+
};
|
|
1553
|
+
};
|
|
1554
|
+
var getDirectorySet = (paths) => {
|
|
1555
|
+
const directories = /* @__PURE__ */ new Set();
|
|
1556
|
+
for (const entry of paths) {
|
|
1557
|
+
const parts = entry.split("/").filter(Boolean);
|
|
1558
|
+
if (parts.length <= 1) continue;
|
|
1559
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
1560
|
+
directories.add(parts.slice(0, i + 1).join("/"));
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
return directories;
|
|
1564
|
+
};
|
|
1565
|
+
var getDirectoryStats = (paths) => {
|
|
1566
|
+
const directories = getDirectorySet(paths);
|
|
1567
|
+
let maxDepth = 0;
|
|
1568
|
+
for (const entry of paths) {
|
|
1569
|
+
const parts = entry.split("/").filter(Boolean);
|
|
1570
|
+
const depth = Math.max(0, parts.length - 1);
|
|
1571
|
+
if (depth > maxDepth) maxDepth = depth;
|
|
1572
|
+
}
|
|
1573
|
+
return { totalDirectories: directories.size, maxDepth };
|
|
1574
|
+
};
|
|
1971
1575
|
|
|
1972
1576
|
// src/tools/search/LspTool/LspTool.tsx
|
|
1973
1577
|
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
1974
|
-
import { Box as
|
|
1578
|
+
import { Box as Box6, Text as Text6 } from "ink";
|
|
1975
1579
|
import { dirname, relative as relative3, resolve as resolve3 } from "path";
|
|
1976
|
-
import
|
|
1977
|
-
import { z as
|
|
1580
|
+
import React6 from "react";
|
|
1581
|
+
import { z as z6 } from "zod";
|
|
1978
1582
|
|
|
1979
1583
|
// src/tools/search/LspTool/prompt.ts
|
|
1980
|
-
var
|
|
1981
|
-
var
|
|
1584
|
+
var TOOL_NAME_FOR_PROMPT2 = "LSP";
|
|
1585
|
+
var PROMPT4 = `Interact with Language Server Protocol (LSP) servers to get code intelligence features.
|
|
1982
1586
|
Supports 29+ languages including Python, Go, Rust, TypeScript, JavaScript, Bash, Java, C++, PHP, and more.
|
|
1983
1587
|
|
|
1984
1588
|
## Capabilities & Scenarios
|
|
@@ -2040,11 +1644,11 @@ Location-based operations require:
|
|
|
2040
1644
|
- documentSymbol \u7684\u4F18\u5148\u7EA7\u7531 LspFacade \u51B3\u5B9A\uFF08\u9ED8\u8BA4 LSP \u4F18\u5148\uFF0CTree-Sitter \u515C\u5E95\uFF09
|
|
2041
1645
|
|
|
2042
1646
|
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.`;
|
|
2043
|
-
var
|
|
1647
|
+
var DESCRIPTION4 = PROMPT4;
|
|
2044
1648
|
|
|
2045
1649
|
// src/tools/search/LspTool/LspTool.tsx
|
|
2046
|
-
var
|
|
2047
|
-
operation:
|
|
1650
|
+
var inputSchema6 = z6.strictObject({
|
|
1651
|
+
operation: z6.enum([
|
|
2048
1652
|
"goToDefinition",
|
|
2049
1653
|
"findReferences",
|
|
2050
1654
|
"hover",
|
|
@@ -2057,14 +1661,14 @@ var inputSchema7 = z7.strictObject({
|
|
|
2057
1661
|
"getScope",
|
|
2058
1662
|
"diagnostics"
|
|
2059
1663
|
]).describe("The LSP operation to perform"),
|
|
2060
|
-
filePath:
|
|
2061
|
-
line:
|
|
2062
|
-
character:
|
|
2063
|
-
waitForDiagnostics:
|
|
2064
|
-
timeout:
|
|
1664
|
+
filePath: z6.string().describe("The absolute or relative path to the file"),
|
|
1665
|
+
line: z6.number().int().positive().optional().describe("The line number (1-based, as shown in editors). Required for location-based operations."),
|
|
1666
|
+
character: z6.number().int().positive().optional().describe("The character offset (1-based, as shown in editors). Required for location-based operations."),
|
|
1667
|
+
waitForDiagnostics: z6.boolean().optional().describe('If true, wait for fresh diagnostics from the server (used with "diagnostics" operation)'),
|
|
1668
|
+
timeout: z6.number().optional().describe("Timeout in milliseconds for waiting operations (default: 5000)")
|
|
2065
1669
|
});
|
|
2066
|
-
var outputSchema =
|
|
2067
|
-
operation:
|
|
1670
|
+
var outputSchema = z6.object({
|
|
1671
|
+
operation: z6.enum([
|
|
2068
1672
|
"goToDefinition",
|
|
2069
1673
|
"findReferences",
|
|
2070
1674
|
"hover",
|
|
@@ -2077,10 +1681,10 @@ var outputSchema = z7.object({
|
|
|
2077
1681
|
"getScope",
|
|
2078
1682
|
"diagnostics"
|
|
2079
1683
|
]).describe("The LSP operation that was performed"),
|
|
2080
|
-
result:
|
|
2081
|
-
filePath:
|
|
2082
|
-
resultCount:
|
|
2083
|
-
fileCount:
|
|
1684
|
+
result: z6.string().describe("The formatted result of the LSP operation"),
|
|
1685
|
+
filePath: z6.string().describe("The file path the operation was performed on"),
|
|
1686
|
+
resultCount: z6.number().int().nonnegative().optional().describe("Number of results (definitions, references, symbols)"),
|
|
1687
|
+
fileCount: z6.number().int().nonnegative().optional().describe("Number of files containing results")
|
|
2084
1688
|
});
|
|
2085
1689
|
var OPERATION_LABELS = {
|
|
2086
1690
|
goToDefinition: { singular: "definition", plural: "definitions" },
|
|
@@ -2133,19 +1737,19 @@ function summarizeToolResult(operation, resultCount, fileCount) {
|
|
|
2133
1737
|
};
|
|
2134
1738
|
const noun = resultCount === 1 ? label.singular : label.plural;
|
|
2135
1739
|
if (operation === "hover" && resultCount > 0 && label.special) {
|
|
2136
|
-
return /* @__PURE__ */
|
|
1740
|
+
return /* @__PURE__ */ React6.createElement(Text6, null, "Hover info ", label.special);
|
|
2137
1741
|
}
|
|
2138
|
-
return /* @__PURE__ */
|
|
1742
|
+
return /* @__PURE__ */ React6.createElement(Text6, null, "Found ", /* @__PURE__ */ React6.createElement(Text6, { bold: true }, resultCount), " ", noun, fileCount > 1 ? /* @__PURE__ */ React6.createElement(React6.Fragment, null, " ", "across ", /* @__PURE__ */ React6.createElement(Text6, { bold: true }, fileCount), " files") : null);
|
|
2139
1743
|
}
|
|
2140
1744
|
var LspTool = {
|
|
2141
|
-
name:
|
|
1745
|
+
name: TOOL_NAME_FOR_PROMPT2,
|
|
2142
1746
|
async description() {
|
|
2143
|
-
return
|
|
1747
|
+
return DESCRIPTION4;
|
|
2144
1748
|
},
|
|
2145
1749
|
async prompt() {
|
|
2146
|
-
return
|
|
1750
|
+
return PROMPT4;
|
|
2147
1751
|
},
|
|
2148
|
-
inputSchema:
|
|
1752
|
+
inputSchema: inputSchema6,
|
|
2149
1753
|
userFacingName() {
|
|
2150
1754
|
return "LSP";
|
|
2151
1755
|
},
|
|
@@ -2163,7 +1767,7 @@ var LspTool = {
|
|
|
2163
1767
|
return !hasReadPermission(abs || getCwd());
|
|
2164
1768
|
},
|
|
2165
1769
|
async validateInput(input) {
|
|
2166
|
-
const parsed =
|
|
1770
|
+
const parsed = inputSchema6.safeParse(input);
|
|
2167
1771
|
if (!parsed.success) {
|
|
2168
1772
|
return {
|
|
2169
1773
|
result: false,
|
|
@@ -2246,7 +1850,7 @@ var LspTool = {
|
|
|
2246
1850
|
return parts.join(", ");
|
|
2247
1851
|
},
|
|
2248
1852
|
renderToolUseRejectedMessage() {
|
|
2249
|
-
return /* @__PURE__ */
|
|
1853
|
+
return /* @__PURE__ */ React6.createElement(FallbackToolUseRejectedMessage, null);
|
|
2250
1854
|
},
|
|
2251
1855
|
renderToolResultMessage(output, { verbose }) {
|
|
2252
1856
|
if (output.resultCount !== void 0 && output.fileCount !== void 0) {
|
|
@@ -2254,13 +1858,13 @@ var LspTool = {
|
|
|
2254
1858
|
maxLines: 120,
|
|
2255
1859
|
maxChars: 2e4
|
|
2256
1860
|
}) : null;
|
|
2257
|
-
return /* @__PURE__ */
|
|
1861
|
+
return /* @__PURE__ */ React6.createElement(Box6, { flexDirection: "column" }, /* @__PURE__ */ React6.createElement(Box6, { flexDirection: "row" }, /* @__PURE__ */ React6.createElement(Text6, null, "\xA0\xA0\u23BF \xA0"), summarizeToolResult(
|
|
2258
1862
|
output.operation,
|
|
2259
1863
|
output.resultCount,
|
|
2260
1864
|
output.fileCount
|
|
2261
|
-
)), display ? /* @__PURE__ */
|
|
1865
|
+
)), display ? /* @__PURE__ */ React6.createElement(Box6, { marginLeft: 5 }, /* @__PURE__ */ React6.createElement(Text6, null, display.text)) : null);
|
|
2262
1866
|
}
|
|
2263
|
-
return /* @__PURE__ */
|
|
1867
|
+
return /* @__PURE__ */ React6.createElement(Box6, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React6.createElement(Box6, { flexDirection: "row" }, /* @__PURE__ */ React6.createElement(Text6, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React6.createElement(Text6, null, output.result)));
|
|
2264
1868
|
},
|
|
2265
1869
|
renderResultForAssistant(output) {
|
|
2266
1870
|
return output.result;
|
|
@@ -2291,39 +1895,39 @@ var LspTool = {
|
|
|
2291
1895
|
};
|
|
2292
1896
|
|
|
2293
1897
|
// src/tools/mcp/ReadMcpResourceTool/ReadMcpResourceTool.tsx
|
|
2294
|
-
import { Box as
|
|
2295
|
-
import
|
|
2296
|
-
import { z as
|
|
1898
|
+
import { Box as Box7, Text as Text7 } from "ink";
|
|
1899
|
+
import React7 from "react";
|
|
1900
|
+
import { z as z7 } from "zod";
|
|
2297
1901
|
import { ReadResourceResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2298
1902
|
|
|
2299
1903
|
// src/tools/mcp/ReadMcpResourceTool/prompt.ts
|
|
2300
1904
|
var TOOL_NAME2 = "ReadMcpResourceTool";
|
|
2301
|
-
var
|
|
1905
|
+
var DESCRIPTION5 = `Reads a specific resource from an MCP server.
|
|
2302
1906
|
- server: The name of the MCP server to read from
|
|
2303
1907
|
- uri: The URI of the resource to read
|
|
2304
1908
|
|
|
2305
1909
|
Usage examples:
|
|
2306
1910
|
- Read a resource from a server: \`readMcpResource({ server: "myserver", uri: "my-resource-uri" })\``;
|
|
2307
|
-
var
|
|
1911
|
+
var PROMPT5 = `Reads a specific resource from an MCP server, identified by server name and resource URI.
|
|
2308
1912
|
|
|
2309
1913
|
Parameters:
|
|
2310
1914
|
- server (required): The name of the MCP server from which to read the resource
|
|
2311
1915
|
- uri (required): The URI of the resource to read`;
|
|
2312
1916
|
|
|
2313
1917
|
// src/tools/mcp/ReadMcpResourceTool/ReadMcpResourceTool.tsx
|
|
2314
|
-
var
|
|
2315
|
-
server:
|
|
2316
|
-
uri:
|
|
1918
|
+
var inputSchema7 = z7.strictObject({
|
|
1919
|
+
server: z7.string().describe("The MCP server name"),
|
|
1920
|
+
uri: z7.string().describe("The resource URI to read")
|
|
2317
1921
|
});
|
|
2318
1922
|
var ReadMcpResourceTool = {
|
|
2319
1923
|
name: TOOL_NAME2,
|
|
2320
1924
|
async description() {
|
|
2321
|
-
return
|
|
1925
|
+
return DESCRIPTION5;
|
|
2322
1926
|
},
|
|
2323
1927
|
async prompt() {
|
|
2324
|
-
return
|
|
1928
|
+
return PROMPT5;
|
|
2325
1929
|
},
|
|
2326
|
-
inputSchema:
|
|
1930
|
+
inputSchema: inputSchema7,
|
|
2327
1931
|
userFacingName() {
|
|
2328
1932
|
return "readMcpResource";
|
|
2329
1933
|
},
|
|
@@ -2378,11 +1982,11 @@ var ReadMcpResourceTool = {
|
|
|
2378
1982
|
return `Read resource "${uri}" from server "${server}"`;
|
|
2379
1983
|
},
|
|
2380
1984
|
renderToolUseRejectedMessage() {
|
|
2381
|
-
return /* @__PURE__ */
|
|
1985
|
+
return /* @__PURE__ */ React7.createElement(FallbackToolUseRejectedMessage, null);
|
|
2382
1986
|
},
|
|
2383
1987
|
renderToolResultMessage(output) {
|
|
2384
1988
|
const count = output.contents?.length ?? 0;
|
|
2385
|
-
return /* @__PURE__ */
|
|
1989
|
+
return /* @__PURE__ */ React7.createElement(Box7, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React7.createElement(Box7, { flexDirection: "row" }, /* @__PURE__ */ React7.createElement(Text7, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React7.createElement(Text7, { bold: true }, "Read MCP resource"), /* @__PURE__ */ React7.createElement(Text7, null, count ? ` (${count} part${count === 1 ? "" : "s"})` : "")), /* @__PURE__ */ React7.createElement(Cost, { costUSD: 0, durationMs: 0, debug: false }));
|
|
2386
1990
|
},
|
|
2387
1991
|
renderResultForAssistant(output) {
|
|
2388
1992
|
return JSON.stringify(output);
|
|
@@ -2423,9 +2027,9 @@ var ReadMcpResourceTool = {
|
|
|
2423
2027
|
|
|
2424
2028
|
// src/tools/agent/TaskTool/TaskTool.tsx
|
|
2425
2029
|
import { last, memoize } from "lodash-es";
|
|
2426
|
-
import
|
|
2427
|
-
import { Box as
|
|
2428
|
-
import { z as
|
|
2030
|
+
import React8 from "react";
|
|
2031
|
+
import { Box as Box8, Text as Text8 } from "ink";
|
|
2032
|
+
import { z as z8 } from "zod";
|
|
2429
2033
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2430
2034
|
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
|
|
2431
2035
|
|
|
@@ -2523,17 +2127,17 @@ assistant: "I'm going to use the Task tool to launch the with the greeting-respo
|
|
|
2523
2127
|
var TOOL_NAME3 = "Task";
|
|
2524
2128
|
|
|
2525
2129
|
// src/tools/agent/TaskTool/TaskTool.tsx
|
|
2526
|
-
var
|
|
2527
|
-
description:
|
|
2528
|
-
prompt:
|
|
2529
|
-
subagent_type:
|
|
2530
|
-
model:
|
|
2130
|
+
var inputSchema8 = z8.object({
|
|
2131
|
+
description: z8.string().describe("A short (3-5 word) description of the task"),
|
|
2132
|
+
prompt: z8.string().describe("The task for the agent to perform"),
|
|
2133
|
+
subagent_type: z8.string().describe("The type of specialized agent to use for this task"),
|
|
2134
|
+
model: z8.enum(["sonnet", "opus", "haiku"]).optional().describe(
|
|
2531
2135
|
"Optional model to use for this agent. If not specified, inherits from parent. Prefer haiku for quick, straightforward tasks to minimize cost and latency."
|
|
2532
2136
|
),
|
|
2533
|
-
resume:
|
|
2137
|
+
resume: z8.string().optional().describe(
|
|
2534
2138
|
"Optional agent ID to resume from. If provided, the agent will continue from the previous execution transcript."
|
|
2535
2139
|
),
|
|
2536
|
-
run_in_background:
|
|
2140
|
+
run_in_background: z8.boolean().optional().describe(
|
|
2537
2141
|
"Set to true to run this agent in the background. Use TaskOutput to read the output later."
|
|
2538
2142
|
)
|
|
2539
2143
|
});
|
|
@@ -2684,7 +2288,7 @@ function buildForkContextForAgent(options) {
|
|
|
2684
2288
|
}
|
|
2685
2289
|
var TaskTool = {
|
|
2686
2290
|
name: TOOL_NAME3,
|
|
2687
|
-
inputSchema:
|
|
2291
|
+
inputSchema: inputSchema8,
|
|
2688
2292
|
async description() {
|
|
2689
2293
|
return "Launch a new task";
|
|
2690
2294
|
},
|
|
@@ -2747,20 +2351,20 @@ var TaskTool = {
|
|
|
2747
2351
|
return description;
|
|
2748
2352
|
},
|
|
2749
2353
|
renderToolUseRejectedMessage() {
|
|
2750
|
-
return /* @__PURE__ */
|
|
2354
|
+
return /* @__PURE__ */ React8.createElement(FallbackToolUseRejectedMessage, null);
|
|
2751
2355
|
},
|
|
2752
2356
|
renderToolResultMessage(output, { verbose }) {
|
|
2753
2357
|
const theme = getTheme();
|
|
2754
2358
|
if (output.status === "async_launched") {
|
|
2755
2359
|
const hint = output.prompt ? " (down arrow \u2193 to manage \xB7 ctrl+o to expand)" : " (down arrow \u2193 to manage)";
|
|
2756
|
-
return /* @__PURE__ */
|
|
2757
|
-
|
|
2360
|
+
return /* @__PURE__ */ React8.createElement(Box8, { flexDirection: "column" }, /* @__PURE__ */ React8.createElement(Box8, { flexDirection: "row" }, /* @__PURE__ */ React8.createElement(Text8, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React8.createElement(Text8, null, "Backgrounded agent", !verbose && /* @__PURE__ */ React8.createElement(Text8, { dimColor: true }, hint))), verbose && output.prompt && /* @__PURE__ */ React8.createElement(
|
|
2361
|
+
Box8,
|
|
2758
2362
|
{
|
|
2759
2363
|
paddingLeft: 2,
|
|
2760
2364
|
borderLeftStyle: "single",
|
|
2761
2365
|
borderLeftColor: theme.secondaryBorder
|
|
2762
2366
|
},
|
|
2763
|
-
/* @__PURE__ */
|
|
2367
|
+
/* @__PURE__ */ React8.createElement(Text8, { color: theme.secondaryText, wrap: "wrap" }, output.prompt)
|
|
2764
2368
|
));
|
|
2765
2369
|
}
|
|
2766
2370
|
const summary = [
|
|
@@ -2768,32 +2372,32 @@ var TaskTool = {
|
|
|
2768
2372
|
`${formatNumber(output.totalTokens)} tokens`,
|
|
2769
2373
|
formatDuration(output.totalDurationMs)
|
|
2770
2374
|
];
|
|
2771
|
-
return /* @__PURE__ */
|
|
2772
|
-
|
|
2375
|
+
return /* @__PURE__ */ React8.createElement(Box8, { flexDirection: "column" }, verbose && output.prompt && /* @__PURE__ */ React8.createElement(
|
|
2376
|
+
Box8,
|
|
2773
2377
|
{
|
|
2774
2378
|
paddingLeft: 2,
|
|
2775
2379
|
borderLeftStyle: "single",
|
|
2776
2380
|
borderLeftColor: theme.secondaryBorder
|
|
2777
2381
|
},
|
|
2778
|
-
/* @__PURE__ */
|
|
2382
|
+
/* @__PURE__ */ React8.createElement(Text8, { color: theme.secondaryText, wrap: "wrap" }, maybeTruncateVerboseToolOutput(output.prompt, {
|
|
2779
2383
|
maxLines: 120,
|
|
2780
2384
|
maxChars: 2e4
|
|
2781
2385
|
}).text)
|
|
2782
|
-
), verbose && output.content.length > 0 && /* @__PURE__ */
|
|
2783
|
-
|
|
2386
|
+
), verbose && output.content.length > 0 && /* @__PURE__ */ React8.createElement(
|
|
2387
|
+
Box8,
|
|
2784
2388
|
{
|
|
2785
2389
|
paddingLeft: 2,
|
|
2786
2390
|
borderLeftStyle: "single",
|
|
2787
2391
|
borderLeftColor: theme.secondaryBorder
|
|
2788
2392
|
},
|
|
2789
|
-
/* @__PURE__ */
|
|
2393
|
+
/* @__PURE__ */ React8.createElement(Text8, { wrap: "wrap" }, maybeTruncateVerboseToolOutput(
|
|
2790
2394
|
output.content.map((b) => b.text).join("\n"),
|
|
2791
2395
|
{
|
|
2792
2396
|
maxLines: 200,
|
|
2793
2397
|
maxChars: 4e4
|
|
2794
2398
|
}
|
|
2795
2399
|
).text)
|
|
2796
|
-
), /* @__PURE__ */
|
|
2400
|
+
), /* @__PURE__ */ React8.createElement(Box8, { flexDirection: "row" }, /* @__PURE__ */ React8.createElement(Text8, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React8.createElement(Text8, { dimColor: true }, "Done (", summary.join(" \xB7 "), ")")));
|
|
2797
2401
|
},
|
|
2798
2402
|
renderResultForAssistant(output) {
|
|
2799
2403
|
if (output.status === "async_launched")
|
|
@@ -3118,12 +2722,199 @@ var TaskTool = {
|
|
|
3118
2722
|
}
|
|
3119
2723
|
};
|
|
3120
2724
|
|
|
2725
|
+
// src/tools/WebFetcher/WebFetcherTool.tsx
|
|
2726
|
+
import { z as z9 } from "zod";
|
|
2727
|
+
|
|
2728
|
+
// src/tools/WebFetcher/WebFetcher.ts
|
|
2729
|
+
import fetch from "node-fetch";
|
|
2730
|
+
import { AbortController as AbortController2 } from "abort-controller";
|
|
2731
|
+
import { parse } from "node-html-parser";
|
|
2732
|
+
import TurndownService from "turndown";
|
|
2733
|
+
import { gfm } from "turndown-plugin-gfm";
|
|
2734
|
+
var WebFetcher = class {
|
|
2735
|
+
DEFAULT_TIMEOUT = 30;
|
|
2736
|
+
// seconds
|
|
2737
|
+
MAX_RESPONSE_SIZE = 5 * 1024 * 1024;
|
|
2738
|
+
// 5MB
|
|
2739
|
+
CACHE_TTL = 15 * 60 * 1e3;
|
|
2740
|
+
// 15 minutes
|
|
2741
|
+
MAX_ANALYSIS_CONTENT_LENGTH = 5e4;
|
|
2742
|
+
// ~15k tokens
|
|
2743
|
+
turndownService;
|
|
2744
|
+
cache = /* @__PURE__ */ new Map();
|
|
2745
|
+
constructor() {
|
|
2746
|
+
this.turndownService = new TurndownService({
|
|
2747
|
+
headingStyle: "atx",
|
|
2748
|
+
codeBlockStyle: "fenced",
|
|
2749
|
+
bulletListMarker: "-",
|
|
2750
|
+
// Explicitly set bullet marker
|
|
2751
|
+
emDelimiter: "*"
|
|
2752
|
+
});
|
|
2753
|
+
this.turndownService.use(gfm);
|
|
2754
|
+
}
|
|
2755
|
+
async execute(input) {
|
|
2756
|
+
let content;
|
|
2757
|
+
let isCached = false;
|
|
2758
|
+
const format = input.format || "markdown";
|
|
2759
|
+
const cached = this.cache.get(input.url);
|
|
2760
|
+
if (cached) {
|
|
2761
|
+
if (Date.now() - cached.timestamp < this.CACHE_TTL) {
|
|
2762
|
+
content = cached.content;
|
|
2763
|
+
isCached = true;
|
|
2764
|
+
} else {
|
|
2765
|
+
this.cache.delete(input.url);
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
if (!isCached) {
|
|
2769
|
+
const timeout = (input.timeout || this.DEFAULT_TIMEOUT) * 1e3;
|
|
2770
|
+
const controller = new AbortController2();
|
|
2771
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2772
|
+
try {
|
|
2773
|
+
const response = await fetch(input.url, {
|
|
2774
|
+
method: "GET",
|
|
2775
|
+
headers: {
|
|
2776
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
2777
|
+
},
|
|
2778
|
+
signal: controller.signal
|
|
2779
|
+
});
|
|
2780
|
+
if (!response.ok) {
|
|
2781
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
2782
|
+
}
|
|
2783
|
+
const contentLength = response.headers.get("content-length");
|
|
2784
|
+
if (contentLength && parseInt(contentLength) > this.MAX_RESPONSE_SIZE) {
|
|
2785
|
+
throw new Error("Response too large (exceeds 5MB limit)");
|
|
2786
|
+
}
|
|
2787
|
+
const contentType = response.headers.get("content-type") || "";
|
|
2788
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2789
|
+
if (arrayBuffer.byteLength > this.MAX_RESPONSE_SIZE) {
|
|
2790
|
+
throw new Error("Response too large (exceeds 5MB limit)");
|
|
2791
|
+
}
|
|
2792
|
+
const text = new TextDecoder().decode(arrayBuffer);
|
|
2793
|
+
let rawContent = text;
|
|
2794
|
+
if (contentType.includes("text/html")) {
|
|
2795
|
+
if (format === "markdown") {
|
|
2796
|
+
const cleanedHtml = this.cleanHtml(text);
|
|
2797
|
+
rawContent = this.turndownService.turndown(cleanedHtml);
|
|
2798
|
+
} else if (format === "text") {
|
|
2799
|
+
const cleanedHtml = this.cleanHtml(text);
|
|
2800
|
+
const root = parse(cleanedHtml);
|
|
2801
|
+
rawContent = root.textContent.trim();
|
|
2802
|
+
} else if (format === "html") {
|
|
2803
|
+
rawContent = this.cleanHtml(text);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
content = rawContent;
|
|
2807
|
+
this.cache.set(input.url, { content, timestamp: Date.now() });
|
|
2808
|
+
} finally {
|
|
2809
|
+
clearTimeout(timeoutId);
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
if (input.prompt) {
|
|
2813
|
+
const truncatedContent = content.length > this.MAX_ANALYSIS_CONTENT_LENGTH ? content.substring(0, this.MAX_ANALYSIS_CONTENT_LENGTH) + "\n\n[Content truncated due to length]" : content;
|
|
2814
|
+
const systemPrompt = [
|
|
2815
|
+
"You are analyzing web content based on a user's specific request.",
|
|
2816
|
+
"The content has been extracted from a webpage and converted to markdown.",
|
|
2817
|
+
"Provide a focused response that directly addresses the user's prompt."
|
|
2818
|
+
];
|
|
2819
|
+
const userPrompt = `Here is the content from ${input.url}:
|
|
2820
|
+
|
|
2821
|
+
${truncatedContent}
|
|
2822
|
+
|
|
2823
|
+
User request: ${input.prompt}`;
|
|
2824
|
+
const aiResponse = await queryQuick({
|
|
2825
|
+
systemPrompt,
|
|
2826
|
+
userPrompt,
|
|
2827
|
+
enablePromptCaching: false
|
|
2828
|
+
});
|
|
2829
|
+
const aiText = aiResponse.message.content.filter((c) => c.type === "text").map((c) => c.text).join("");
|
|
2830
|
+
return {
|
|
2831
|
+
url: input.url,
|
|
2832
|
+
title: input.url,
|
|
2833
|
+
content: aiText,
|
|
2834
|
+
metadata: {
|
|
2835
|
+
mode: "analysis",
|
|
2836
|
+
format,
|
|
2837
|
+
cached: isCached
|
|
2838
|
+
}
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
return {
|
|
2842
|
+
url: input.url,
|
|
2843
|
+
title: input.url,
|
|
2844
|
+
// Temporary title
|
|
2845
|
+
content,
|
|
2846
|
+
metadata: {
|
|
2847
|
+
mode: "fetch",
|
|
2848
|
+
format,
|
|
2849
|
+
cached: isCached
|
|
2850
|
+
}
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2853
|
+
cleanHtml(html) {
|
|
2854
|
+
const root = parse(html);
|
|
2855
|
+
const elementsToRemove = root.querySelectorAll("script, style, nav, footer, iframe, noscript, object, embed");
|
|
2856
|
+
elementsToRemove.forEach((el) => el.remove());
|
|
2857
|
+
return root.toString();
|
|
2858
|
+
}
|
|
2859
|
+
};
|
|
2860
|
+
|
|
2861
|
+
// src/tools/WebFetcher/WebFetcherTool.tsx
|
|
2862
|
+
import React9 from "react";
|
|
2863
|
+
import { Box as Box9, Text as Text9 } from "ink";
|
|
2864
|
+
var inputSchema9 = z9.strictObject({
|
|
2865
|
+
url: z9.string().url().describe("The URL to fetch content from"),
|
|
2866
|
+
prompt: z9.string().optional().describe("Optional prompt to perform AI analysis on the content"),
|
|
2867
|
+
format: z9.enum(["markdown", "html", "text"]).optional().describe("Output format (default: markdown)"),
|
|
2868
|
+
timeout: z9.number().optional().describe("Timeout in seconds (default: 30)")
|
|
2869
|
+
});
|
|
2870
|
+
var WebFetcherTool = {
|
|
2871
|
+
name: "web_fetcher",
|
|
2872
|
+
async description() {
|
|
2873
|
+
return "Fetch and analyze web content. Supports HTML cleaning, Markdown conversion, and AI-powered analysis.";
|
|
2874
|
+
},
|
|
2875
|
+
userFacingName: () => "Web Fetcher",
|
|
2876
|
+
inputSchema: inputSchema9,
|
|
2877
|
+
isReadOnly: () => true,
|
|
2878
|
+
isConcurrencySafe: () => true,
|
|
2879
|
+
async isEnabled() {
|
|
2880
|
+
return true;
|
|
2881
|
+
},
|
|
2882
|
+
needsPermissions() {
|
|
2883
|
+
return true;
|
|
2884
|
+
},
|
|
2885
|
+
async prompt() {
|
|
2886
|
+
return "Fetch and analyze web content. Supports HTML cleaning, Markdown conversion, and AI-powered analysis.";
|
|
2887
|
+
},
|
|
2888
|
+
renderResultForAssistant(output) {
|
|
2889
|
+
if (output.metadata.mode === "analysis") {
|
|
2890
|
+
return output.content;
|
|
2891
|
+
}
|
|
2892
|
+
return `Content from ${output.url} (Format: ${output.metadata.format}):
|
|
2893
|
+
|
|
2894
|
+
${output.content}`;
|
|
2895
|
+
},
|
|
2896
|
+
renderToolUseMessage(input) {
|
|
2897
|
+
return `Fetching ${input.url}${input.prompt ? ` with prompt: "${input.prompt}"` : ""}`;
|
|
2898
|
+
},
|
|
2899
|
+
renderToolResultMessage(output) {
|
|
2900
|
+
return /* @__PURE__ */ React9.createElement(Box9, { flexDirection: "column" }, /* @__PURE__ */ React9.createElement(Text9, null, "Fetched ", output.url, " (", output.metadata.mode, ")"));
|
|
2901
|
+
},
|
|
2902
|
+
async *call(input, context) {
|
|
2903
|
+
const fetcher = new WebFetcher();
|
|
2904
|
+
const result = await fetcher.execute(input);
|
|
2905
|
+
yield {
|
|
2906
|
+
type: "result",
|
|
2907
|
+
data: result,
|
|
2908
|
+
resultForAssistant: this.renderResultForAssistant(result)
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
};
|
|
2912
|
+
|
|
3121
2913
|
// src/tools/index.ts
|
|
3122
2914
|
var getAllTools = () => [
|
|
3123
2915
|
TaskTool,
|
|
3124
2916
|
AskExpertModelTool,
|
|
3125
2917
|
BashTool,
|
|
3126
|
-
BatchTool,
|
|
3127
2918
|
TaskOutputTool,
|
|
3128
2919
|
KillShellTool,
|
|
3129
2920
|
GlobTool,
|
|
@@ -3136,6 +2927,7 @@ var getAllTools = () => [
|
|
|
3136
2927
|
DeleteTool,
|
|
3137
2928
|
NotebookEditTool,
|
|
3138
2929
|
TodoWriteTool,
|
|
2930
|
+
WebFetcherTool,
|
|
3139
2931
|
WebSearchTool,
|
|
3140
2932
|
AskUserQuestionTool,
|
|
3141
2933
|
EnterPlanModeTool,
|