@dirgha/code 1.16.2 → 1.17.0
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/cli/config.d.ts +3 -3
- package/dist/cli/config.js +34 -14
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/interactive.js +129 -116
- package/dist/cli/interactive.js.map +1 -1
- package/dist/cli/main.js +8 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/slash/cost.d.ts +6 -0
- package/dist/cli/slash/cost.js +12 -0
- package/dist/cli/slash/cost.js.map +1 -0
- package/dist/cli/slash/export.d.ts +2 -0
- package/dist/cli/slash/export.js +151 -0
- package/dist/cli/slash/export.js.map +1 -0
- package/dist/cli/slash/fs.d.ts +2 -0
- package/dist/cli/slash/fs.js +145 -0
- package/dist/cli/slash/fs.js.map +1 -0
- package/dist/cli/slash/index.d.ts +29 -25
- package/dist/cli/slash/index.js +32 -24
- package/dist/cli/slash/index.js.map +1 -1
- package/dist/cli/slash/mcp.d.ts +2 -0
- package/dist/cli/slash/mcp.js +93 -0
- package/dist/cli/slash/mcp.js.map +1 -0
- package/dist/cli/slash/models.d.ts +1 -1
- package/dist/cli/slash/models.js +21 -20
- package/dist/cli/slash/models.js.map +1 -1
- package/dist/cli/slash.d.ts +5 -5
- package/dist/cli/slash.js +53 -22
- package/dist/cli/slash.js.map +1 -1
- package/dist/cli/subcommands/models.js +6 -2
- package/dist/cli/subcommands/models.js.map +1 -1
- package/dist/cli/update-check.d.ts +1 -0
- package/dist/cli/update-check.js +77 -0
- package/dist/cli/update-check.js.map +1 -0
- package/dist/context/default-soul.md +1 -1
- package/dist/context/ledger.d.ts +12 -2
- package/dist/context/ledger.js +92 -32
- package/dist/context/ledger.js.map +1 -1
- package/dist/context/memory.d.ts +7 -2
- package/dist/context/memory.js +71 -50
- package/dist/context/memory.js.map +1 -1
- package/dist/context/primer.d.ts +4 -2
- package/dist/context/primer.js +18 -10
- package/dist/context/primer.js.map +1 -1
- package/dist/context/session.d.ts +8 -7
- package/dist/context/session.js +40 -23
- package/dist/context/session.js.map +1 -1
- package/dist/daemon/server.d.ts +4 -4
- package/dist/daemon/server.js +66 -36
- package/dist/daemon/server.js.map +1 -1
- package/dist/fleet/templates.d.ts +18 -0
- package/dist/fleet/templates.js +103 -0
- package/dist/fleet/templates.js.map +1 -0
- package/dist/intelligence/prices.js +819 -193
- package/dist/intelligence/prices.js.map +1 -1
- package/dist/intelligence/smart-router.d.ts +3 -1
- package/dist/intelligence/smart-router.js +34 -12
- package/dist/intelligence/smart-router.js.map +1 -1
- package/dist/kernel/agent-loop.d.ts +11 -0
- package/dist/kernel/agent-loop.js +40 -2
- package/dist/kernel/agent-loop.js.map +1 -1
- package/dist/kernel/types.d.ts +28 -27
- package/dist/lsp/client.d.ts +76 -0
- package/dist/lsp/client.js +332 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/detector.d.ts +13 -0
- package/dist/lsp/detector.js +152 -0
- package/dist/lsp/detector.js.map +1 -0
- package/dist/lsp/index.d.ts +25 -0
- package/dist/lsp/index.js +127 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/providers/dispatch.d.ts +1 -1
- package/dist/providers/dispatch.js +70 -31
- package/dist/providers/dispatch.js.map +1 -1
- package/dist/providers/family-fallback.d.ts +12 -0
- package/dist/providers/family-fallback.js +73 -0
- package/dist/providers/family-fallback.js.map +1 -0
- package/dist/providers/health.d.ts +13 -0
- package/dist/providers/health.js +71 -0
- package/dist/providers/health.js.map +1 -0
- package/dist/providers/index.d.ts +15 -12
- package/dist/providers/index.js +63 -40
- package/dist/providers/index.js.map +1 -1
- package/dist/subagents/delegator.d.ts +2 -2
- package/dist/subagents/delegator.js +29 -14
- package/dist/subagents/delegator.js.map +1 -1
- package/dist/subagents/loop-detector.d.ts +30 -0
- package/dist/subagents/loop-detector.js +62 -0
- package/dist/subagents/loop-detector.js.map +1 -0
- package/dist/tools/exec.d.ts +8 -4
- package/dist/tools/exec.js +10 -1
- package/dist/tools/exec.js.map +1 -1
- package/dist/tools/fs-edit.d.ts +1 -1
- package/dist/tools/fs-edit.js +30 -17
- package/dist/tools/fs-edit.js.map +1 -1
- package/dist/tools/index.d.ts +26 -18
- package/dist/tools/index.js +31 -18
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp-definition.d.ts +2 -0
- package/dist/tools/lsp-definition.js +48 -0
- package/dist/tools/lsp-definition.js.map +1 -0
- package/dist/tools/lsp-hover.d.ts +2 -0
- package/dist/tools/lsp-hover.js +68 -0
- package/dist/tools/lsp-hover.js.map +1 -0
- package/dist/tools/lsp-references.d.ts +2 -0
- package/dist/tools/lsp-references.js +48 -0
- package/dist/tools/lsp-references.js.map +1 -0
- package/dist/tools/lsp-symbols.d.ts +2 -0
- package/dist/tools/lsp-symbols.js +62 -0
- package/dist/tools/lsp-symbols.js.map +1 -0
- package/dist/tools/registry.d.ts +3 -2
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/shell.d.ts +1 -1
- package/dist/tools/shell.js +55 -36
- package/dist/tools/shell.js.map +1 -1
- package/dist/tui/ink/App.d.ts +2 -0
- package/dist/tui/ink/App.js +28 -8
- package/dist/tui/ink/App.js.map +1 -1
- package/dist/tui/ink/components/ToolBox.d.ts +5 -0
- package/dist/tui/ink/components/ToolBox.js +45 -4
- package/dist/tui/ink/components/ToolBox.js.map +1 -1
- package/dist/tui/ink/components/ToolGroup.d.ts +1 -0
- package/dist/tui/ink/components/ToolGroup.js +20 -2
- package/dist/tui/ink/components/ToolGroup.js.map +1 -1
- package/dist/tui/ink/components/vim-bindings.d.ts +1 -1
- package/dist/tui/ink/components/vim-bindings.js +107 -40
- package/dist/tui/ink/components/vim-bindings.js.map +1 -1
- package/dist/tui/ink/index.d.ts +19 -18
- package/dist/tui/ink/index.js +26 -19
- package/dist/tui/ink/index.js.map +1 -1
- package/dist/tui/ink/use-event-projection.d.ts +1 -0
- package/dist/tui/ink/use-event-projection.js +25 -1
- package/dist/tui/ink/use-event-projection.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
* tool subset. The parent receives only the final text output; the full
|
|
7
7
|
* transcript is preserved in the child session for audit.
|
|
8
8
|
*/
|
|
9
|
-
import { randomUUID } from
|
|
10
|
-
import { createEventStream } from
|
|
11
|
-
import { runAgentLoop } from
|
|
12
|
-
import { extractText } from
|
|
13
|
-
import { createToolExecutor } from
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { createEventStream } from "../kernel/event-stream.js";
|
|
11
|
+
import { runAgentLoop } from "../kernel/agent-loop.js";
|
|
12
|
+
import { extractText } from "../kernel/message.js";
|
|
13
|
+
import { createToolExecutor } from "../tools/exec.js";
|
|
14
|
+
import { LoopDetector } from "../subagents/loop-detector.js";
|
|
14
15
|
export class SubagentDelegator {
|
|
15
16
|
opts;
|
|
16
17
|
constructor(opts) {
|
|
@@ -19,9 +20,11 @@ export class SubagentDelegator {
|
|
|
19
20
|
async delegate(req) {
|
|
20
21
|
const sessionId = `${this.opts.parentSessionId}-sub-${randomUUID().slice(0, 8)}`;
|
|
21
22
|
const events = createEventStream();
|
|
22
|
-
const allowlist = req.toolAllowlist
|
|
23
|
+
const allowlist = req.toolAllowlist
|
|
24
|
+
? new Set(req.toolAllowlist)
|
|
25
|
+
: undefined;
|
|
23
26
|
const filteredTools = allowlist
|
|
24
|
-
? this.opts.registry.list().filter(t => allowlist.has(t.name))
|
|
27
|
+
? this.opts.registry.list().filter((t) => allowlist.has(t.name))
|
|
25
28
|
: this.opts.registry.list();
|
|
26
29
|
const scoped = new Map();
|
|
27
30
|
for (const t of filteredTools)
|
|
@@ -35,8 +38,9 @@ export class SubagentDelegator {
|
|
|
35
38
|
});
|
|
36
39
|
const messages = [];
|
|
37
40
|
if (req.system)
|
|
38
|
-
messages.push({ role:
|
|
39
|
-
messages.push({ role:
|
|
41
|
+
messages.push({ role: "system", content: req.system });
|
|
42
|
+
messages.push({ role: "user", content: req.prompt });
|
|
43
|
+
const loopDetector = new LoopDetector();
|
|
40
44
|
const result = await runAgentLoop({
|
|
41
45
|
sessionId,
|
|
42
46
|
model: req.model ?? this.opts.defaultModel,
|
|
@@ -46,10 +50,13 @@ export class SubagentDelegator {
|
|
|
46
50
|
provider: this.opts.provider,
|
|
47
51
|
toolExecutor: executor,
|
|
48
52
|
events,
|
|
53
|
+
loopDetector,
|
|
49
54
|
});
|
|
50
|
-
const lastAssistant = [...result.messages]
|
|
55
|
+
const lastAssistant = [...result.messages]
|
|
56
|
+
.reverse()
|
|
57
|
+
.find((m) => m.role === "assistant");
|
|
51
58
|
return {
|
|
52
|
-
output: lastAssistant ? extractText(lastAssistant) :
|
|
59
|
+
output: lastAssistant ? extractText(lastAssistant) : "",
|
|
53
60
|
usage: result.usage,
|
|
54
61
|
transcript: result.messages,
|
|
55
62
|
stopReason: result.stopReason,
|
|
@@ -59,8 +66,12 @@ export class SubagentDelegator {
|
|
|
59
66
|
}
|
|
60
67
|
function createScopedRegistry(tools) {
|
|
61
68
|
return {
|
|
62
|
-
register() {
|
|
63
|
-
|
|
69
|
+
register() {
|
|
70
|
+
throw new Error("scoped registry is read-only");
|
|
71
|
+
},
|
|
72
|
+
unregister() {
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
64
75
|
has: (name) => tools.has(name),
|
|
65
76
|
get: (name) => tools.get(name),
|
|
66
77
|
list: () => [...tools.values()],
|
|
@@ -72,7 +83,11 @@ function createScopedRegistry(tools) {
|
|
|
72
83
|
const description = tool.description.length > limit
|
|
73
84
|
? `${tool.description.slice(0, limit - 3)}...`
|
|
74
85
|
: tool.description;
|
|
75
|
-
definitions.push({
|
|
86
|
+
definitions.push({
|
|
87
|
+
name: tool.name,
|
|
88
|
+
description,
|
|
89
|
+
inputSchema: tool.inputSchema,
|
|
90
|
+
});
|
|
76
91
|
nameSet.add(tool.name);
|
|
77
92
|
}
|
|
78
93
|
return { definitions, nameSet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegator.js","sourceRoot":"","sources":["../../src/subagents/delegator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"delegator.js","sourceRoot":"","sources":["../../src/subagents/delegator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AA0B7D,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,IAAsB;QAAtB,SAAI,GAAJ,IAAI,CAAkB;IAAG,CAAC;IAE9C,KAAK,CAAC,QAAQ,CAAC,GAAoB;QACjC,MAAM,SAAS,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,QAAQ,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACjF,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;QACnC,MAAM,SAAS,GAAG,GAAG,CAAC,aAAa;YACjC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC;YAC5B,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,aAAa,GAAW,SAAS;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BAClC,MAAM,WAAW,GACf,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,KAAK;oBAC7B,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,KAAK;oBAC9C,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;gBACvB,WAAW,CAAC,IAAI,CAAC;oBACf,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,WAAW;oBACX,WAAW,EAAE,IAAI,CAAC,WAAW;iBAC9B,CAAC,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;QAClC,CAAC;KACyB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-agent loop detector — ported from monorepo agent/loop-detector.ts.
|
|
3
|
+
*
|
|
4
|
+
* Detects infinite tool-calling loops in sub-agents by tracking:
|
|
5
|
+
* 1. Repeated tool calls with identical args
|
|
6
|
+
* 2. No-progress patterns (output stagnation)
|
|
7
|
+
* 3. Excessive turns without task completion
|
|
8
|
+
*/
|
|
9
|
+
import type { Message } from "../kernel/types.js";
|
|
10
|
+
export interface LoopConfig {
|
|
11
|
+
maxRepeatedToolCalls: number;
|
|
12
|
+
maxTurnsWithoutProgress: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class LoopDetector {
|
|
15
|
+
private config;
|
|
16
|
+
private toolCallHistory;
|
|
17
|
+
private turnsWithoutProgress;
|
|
18
|
+
private lastOutputHash;
|
|
19
|
+
constructor(config?: Partial<LoopConfig>);
|
|
20
|
+
track(turn: {
|
|
21
|
+
toolCalls?: Array<{
|
|
22
|
+
name: string;
|
|
23
|
+
args?: Record<string, unknown>;
|
|
24
|
+
}>;
|
|
25
|
+
message?: Message;
|
|
26
|
+
}): void;
|
|
27
|
+
isLoopDetected(): boolean;
|
|
28
|
+
reason(): string | null;
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const DEFAULT_LOOP_CONFIG = {
|
|
2
|
+
maxRepeatedToolCalls: 5,
|
|
3
|
+
maxTurnsWithoutProgress: 3,
|
|
4
|
+
};
|
|
5
|
+
export class LoopDetector {
|
|
6
|
+
config;
|
|
7
|
+
toolCallHistory = new Map();
|
|
8
|
+
turnsWithoutProgress = 0;
|
|
9
|
+
lastOutputHash = null;
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
this.config = { ...DEFAULT_LOOP_CONFIG, ...config };
|
|
12
|
+
}
|
|
13
|
+
track(turn) {
|
|
14
|
+
if (turn.toolCalls && turn.toolCalls.length > 0) {
|
|
15
|
+
for (const tc of turn.toolCalls) {
|
|
16
|
+
const key = `${tc.name}:${JSON.stringify(tc.args ?? {})}`;
|
|
17
|
+
const count = (this.toolCallHistory.get(key) ?? 0) + 1;
|
|
18
|
+
this.toolCallHistory.set(key, count);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (turn.message) {
|
|
22
|
+
const hash = typeof turn.message.content === "string"
|
|
23
|
+
? turn.message.content.slice(0, 500)
|
|
24
|
+
: JSON.stringify(turn.message.content).slice(0, 500);
|
|
25
|
+
if (this.lastOutputHash === hash) {
|
|
26
|
+
this.turnsWithoutProgress++;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.turnsWithoutProgress = 0;
|
|
30
|
+
this.lastOutputHash = hash;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
isLoopDetected() {
|
|
35
|
+
// Check repeated tool calls
|
|
36
|
+
for (const count of this.toolCallHistory.values()) {
|
|
37
|
+
if (count >= this.config.maxRepeatedToolCalls)
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
// Check output stagnation
|
|
41
|
+
if (this.turnsWithoutProgress >= this.config.maxTurnsWithoutProgress)
|
|
42
|
+
return true;
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
reason() {
|
|
46
|
+
for (const [key, count] of this.toolCallHistory) {
|
|
47
|
+
if (count >= this.config.maxRepeatedToolCalls) {
|
|
48
|
+
return `repeated tool call: ${key} (${count}x)`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (this.turnsWithoutProgress >= this.config.maxTurnsWithoutProgress) {
|
|
52
|
+
return `output stagnation: ${this.turnsWithoutProgress} turns without progress`;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
reset() {
|
|
57
|
+
this.toolCallHistory.clear();
|
|
58
|
+
this.turnsWithoutProgress = 0;
|
|
59
|
+
this.lastOutputHash = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=loop-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-detector.js","sourceRoot":"","sources":["../../src/subagents/loop-detector.ts"],"names":[],"mappings":"AAeA,MAAM,mBAAmB,GAAe;IACtC,oBAAoB,EAAE,CAAC;IACvB,uBAAuB,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,OAAO,YAAY;IACf,MAAM,CAAa;IACnB,eAAe,GAAwB,IAAI,GAAG,EAAE,CAAC;IACjD,oBAAoB,GAAG,CAAC,CAAC;IACzB,cAAc,GAAkB,IAAI,CAAC;IAE7C,YAAY,SAA8B,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,IAGL;QACC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBAChC,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,I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KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAChD,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;gBAC9C,OAAO,uBAAuB,GAAG,KAAK,KAAK,IAAI,CAAC;YAClD,CAAC;QACH,CAAC;QACD,IAAI,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,CAAC;YACrE,OAAO,sBAAsB,IAAI,CAAC,oBAAoB,yBAAyB,CAAC;QAClF,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC7B,CAAC;CACF"}
|
package/dist/tools/exec.d.ts
CHANGED
|
@@ -5,15 +5,19 @@
|
|
|
5
5
|
* the tool's execute() under the caller's AbortSignal, and returns a
|
|
6
6
|
* ToolResult. Tools themselves own their error handling; the executor
|
|
7
7
|
* converts unexpected exceptions into a uniform error result.
|
|
8
|
+
*
|
|
9
|
+
* When an onProgress callback is provided, tools that emit streaming
|
|
10
|
+
* progress push events back through the agent-loop event stream.
|
|
8
11
|
*/
|
|
9
|
-
import type { ToolExecutor } from
|
|
10
|
-
import type { ToolContext, ToolRegistry } from
|
|
11
|
-
export type { ToolExecutor } from
|
|
12
|
+
import type { ToolExecutor } from "../kernel/types.js";
|
|
13
|
+
import type { ToolContext, ToolRegistry } from "./registry.js";
|
|
14
|
+
export type { ToolExecutor } from "../kernel/types.js";
|
|
12
15
|
export interface ToolExecutorOptions {
|
|
13
16
|
registry: ToolRegistry;
|
|
14
17
|
cwd: string;
|
|
15
18
|
env?: Record<string, string>;
|
|
16
19
|
sessionId: string;
|
|
17
|
-
log?: ToolContext[
|
|
20
|
+
log?: ToolContext["log"];
|
|
21
|
+
onProgress?: (toolId: string, message: string) => void;
|
|
18
22
|
}
|
|
19
23
|
export declare function createToolExecutor(opts: ToolExecutorOptions): ToolExecutor;
|
package/dist/tools/exec.js
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* the tool's execute() under the caller's AbortSignal, and returns a
|
|
6
6
|
* ToolResult. Tools themselves own their error handling; the executor
|
|
7
7
|
* converts unexpected exceptions into a uniform error result.
|
|
8
|
+
*
|
|
9
|
+
* When an onProgress callback is provided, tools that emit streaming
|
|
10
|
+
* progress push events back through the agent-loop event stream.
|
|
8
11
|
*/
|
|
9
12
|
export function createToolExecutor(opts) {
|
|
10
13
|
const env = opts.env ?? sanitiseEnv(process.env);
|
|
@@ -12,7 +15,10 @@ export function createToolExecutor(opts) {
|
|
|
12
15
|
async execute(call, signal) {
|
|
13
16
|
const tool = opts.registry.get(call.name);
|
|
14
17
|
if (!tool) {
|
|
15
|
-
return {
|
|
18
|
+
return {
|
|
19
|
+
content: `Tool "${call.name}" is not registered.`,
|
|
20
|
+
isError: true,
|
|
21
|
+
};
|
|
16
22
|
}
|
|
17
23
|
const ctx = {
|
|
18
24
|
cwd: opts.cwd,
|
|
@@ -20,6 +26,9 @@ export function createToolExecutor(opts) {
|
|
|
20
26
|
sessionId: opts.sessionId,
|
|
21
27
|
signal,
|
|
22
28
|
log: opts.log,
|
|
29
|
+
onProgress: opts.onProgress
|
|
30
|
+
? (msg) => opts.onProgress(call.id, msg)
|
|
31
|
+
: undefined,
|
|
23
32
|
};
|
|
24
33
|
try {
|
|
25
34
|
return await runTool(tool, call.input, ctx);
|
package/dist/tools/exec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/tools/exec.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/tools/exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgBH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EACV,KAAc,EACd,GAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IAC9D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,MAAyB;IAC5C,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,KAAK,SAAS;YAAE,SAAS;QAC9B,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/tools/fs-edit.d.ts
CHANGED
package/dist/tools/fs-edit.js
CHANGED
|
@@ -7,21 +7,21 @@
|
|
|
7
7
|
* can retry with more specific anchors. This is deterministic and
|
|
8
8
|
* auditable — no "nearest fuzzy match" guessing.
|
|
9
9
|
*/
|
|
10
|
-
import { readFile, stat, writeFile } from
|
|
11
|
-
import { resolve } from
|
|
12
|
-
import { summariseDiff, unifiedDiff } from
|
|
10
|
+
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
11
|
+
import { resolve } from "node:path";
|
|
12
|
+
import { summariseDiff, unifiedDiff } from "./diff.js";
|
|
13
13
|
export const fsEditTool = {
|
|
14
|
-
name:
|
|
15
|
-
description:
|
|
14
|
+
name: "fs_edit",
|
|
15
|
+
description: "Replace an exact substring in a file. Fails on ambiguity (multiple matches) unless replaceAll is set. Use larger context around oldString to disambiguate.",
|
|
16
16
|
inputSchema: {
|
|
17
|
-
type:
|
|
17
|
+
type: "object",
|
|
18
18
|
properties: {
|
|
19
|
-
path: { type:
|
|
20
|
-
oldString: { type:
|
|
21
|
-
newString: { type:
|
|
22
|
-
replaceAll: { type:
|
|
19
|
+
path: { type: "string" },
|
|
20
|
+
oldString: { type: "string" },
|
|
21
|
+
newString: { type: "string" },
|
|
22
|
+
replaceAll: { type: "boolean" },
|
|
23
23
|
},
|
|
24
|
-
required: [
|
|
24
|
+
required: ["path", "oldString", "newString"],
|
|
25
25
|
},
|
|
26
26
|
requiresApproval: () => true,
|
|
27
27
|
async execute(rawInput, ctx) {
|
|
@@ -30,9 +30,12 @@ export const fsEditTool = {
|
|
|
30
30
|
const info = await stat(abs).catch(() => undefined);
|
|
31
31
|
if (!info || !info.isFile())
|
|
32
32
|
return { content: `No such file: ${input.path}`, isError: true };
|
|
33
|
-
const before = await readFile(abs,
|
|
33
|
+
const before = await readFile(abs, "utf8");
|
|
34
34
|
if (input.oldString === input.newString) {
|
|
35
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
content: "oldString and newString are identical; nothing to do.",
|
|
37
|
+
isError: true,
|
|
38
|
+
};
|
|
36
39
|
}
|
|
37
40
|
const exactCount = countOccurrences(before, input.oldString);
|
|
38
41
|
if (exactCount === 0) {
|
|
@@ -50,14 +53,24 @@ export const fsEditTool = {
|
|
|
50
53
|
const after = input.replaceAll
|
|
51
54
|
? splitJoin(before, input.oldString, input.newString)
|
|
52
55
|
: before.replace(input.oldString, input.newString);
|
|
53
|
-
const diff = unifiedDiff(before, after, {
|
|
56
|
+
const diff = unifiedDiff(before, after, {
|
|
57
|
+
fromLabel: input.path,
|
|
58
|
+
toLabel: input.path,
|
|
59
|
+
});
|
|
54
60
|
const { added, removed } = summariseDiff(diff);
|
|
55
|
-
await writeFile(abs, after,
|
|
61
|
+
await writeFile(abs, after, "utf8");
|
|
62
|
+
const summary = `Edited ${input.path}: ${input.replaceAll ? exactCount : 1} replacement(s) (+${added} / -${removed})`;
|
|
63
|
+
const content = diff ? `${summary}\n\n${diff}` : summary;
|
|
56
64
|
return {
|
|
57
|
-
content
|
|
65
|
+
content,
|
|
58
66
|
data: { replacements: input.replaceAll ? exactCount : 1, added, removed },
|
|
59
67
|
isError: false,
|
|
60
|
-
metadata: {
|
|
68
|
+
metadata: {
|
|
69
|
+
diff,
|
|
70
|
+
added,
|
|
71
|
+
removed,
|
|
72
|
+
replacements: input.replaceAll ? exactCount : 1,
|
|
73
|
+
},
|
|
61
74
|
};
|
|
62
75
|
},
|
|
63
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-edit.js","sourceRoot":"","sources":["../../src/tools/fs-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AASvD,MAAM,CAAC,MAAM,UAAU,GAAS;IAC9B,IAAI,EAAE,SAAS;IACf,WAAW,
|
|
1
|
+
{"version":3,"file":"fs-edit.js","sourceRoot":"","sources":["../../src/tools/fs-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AASvD,MAAM,CAAC,MAAM,UAAU,GAAS;IAC9B,IAAI,EAAE,SAAS;IACf,WAAW,EACT,4JAA4J;IAC9J,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxB,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC7B,SAAS,EAAE,EAAE,IAAI,EAAE,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I,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAClC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,SAAS,CAAC;QACR,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5C,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM;QACrB,KAAK,EAAE,CAAC;QACR,GAAG,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAChB,QAAgB,EAChB,MAAc,EACd,WAAmB;IAEnB,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -3,23 +3,31 @@
|
|
|
3
3
|
* bundled built-in tools. Consumers typically import
|
|
4
4
|
* `builtInTools` and register additional tools on top.
|
|
5
5
|
*/
|
|
6
|
-
import type { Tool } from
|
|
7
|
-
import { fsReadTool } from
|
|
8
|
-
import { fsWriteTool } from
|
|
9
|
-
import { fsEditTool } from
|
|
10
|
-
import { fsLsTool } from
|
|
11
|
-
import { shellTool } from
|
|
12
|
-
import { searchGrepTool } from
|
|
13
|
-
import { searchGlobTool } from
|
|
14
|
-
import { gitTool } from
|
|
15
|
-
import { browserTool } from
|
|
16
|
-
import { checkpointTool } from
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
import type { Tool } from "./registry.js";
|
|
7
|
+
import { fsReadTool } from "./fs-read.js";
|
|
8
|
+
import { fsWriteTool } from "./fs-write.js";
|
|
9
|
+
import { fsEditTool } from "./fs-edit.js";
|
|
10
|
+
import { fsLsTool } from "./fs-ls.js";
|
|
11
|
+
import { shellTool } from "./shell.js";
|
|
12
|
+
import { searchGrepTool } from "./search-grep.js";
|
|
13
|
+
import { searchGlobTool } from "./search-glob.js";
|
|
14
|
+
import { gitTool } from "./git.js";
|
|
15
|
+
import { browserTool } from "./browser.js";
|
|
16
|
+
import { checkpointTool } from "./checkpoint.js";
|
|
17
|
+
import { lspGoToDefinitionTool } from "./lsp-definition.js";
|
|
18
|
+
import { lspFindReferencesTool } from "./lsp-references.js";
|
|
19
|
+
import { lspHoverTool } from "./lsp-hover.js";
|
|
20
|
+
import { lspDocumentSymbolsTool } from "./lsp-symbols.js";
|
|
21
|
+
export { createCronTool } from "./cron.js";
|
|
22
|
+
export { createTaskTool } from "./task.js";
|
|
19
23
|
declare const cronTool: Tool;
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
24
|
+
export * from "./registry.js";
|
|
25
|
+
export * from "./permission.js";
|
|
26
|
+
export * from "./exec.js";
|
|
27
|
+
export * from "./diff.js";
|
|
28
|
+
export * from "./lsp-definition.js";
|
|
29
|
+
export * from "./lsp-references.js";
|
|
30
|
+
export * from "./lsp-hover.js";
|
|
31
|
+
export * from "./lsp-symbols.js";
|
|
24
32
|
export declare const builtInTools: Tool[];
|
|
25
|
-
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, browserTool, checkpointTool, cronTool, };
|
|
33
|
+
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, browserTool, checkpointTool, cronTool, lspGoToDefinitionTool, lspFindReferencesTool, lspHoverTool, lspDocumentSymbolsTool, };
|
package/dist/tools/index.js
CHANGED
|
@@ -3,25 +3,34 @@
|
|
|
3
3
|
* bundled built-in tools. Consumers typically import
|
|
4
4
|
* `builtInTools` and register additional tools on top.
|
|
5
5
|
*/
|
|
6
|
-
import { fsReadTool } from
|
|
7
|
-
import { fsWriteTool } from
|
|
8
|
-
import { fsEditTool } from
|
|
9
|
-
import { fsLsTool } from
|
|
10
|
-
import { shellTool } from
|
|
11
|
-
import { searchGrepTool } from
|
|
12
|
-
import { searchGlobTool } from
|
|
13
|
-
import { gitTool } from
|
|
14
|
-
import { browserTool } from
|
|
15
|
-
import { checkpointTool } from
|
|
16
|
-
import { createCronTool } from
|
|
6
|
+
import { fsReadTool } from "./fs-read.js";
|
|
7
|
+
import { fsWriteTool } from "./fs-write.js";
|
|
8
|
+
import { fsEditTool } from "./fs-edit.js";
|
|
9
|
+
import { fsLsTool } from "./fs-ls.js";
|
|
10
|
+
import { shellTool } from "./shell.js";
|
|
11
|
+
import { searchGrepTool } from "./search-grep.js";
|
|
12
|
+
import { searchGlobTool } from "./search-glob.js";
|
|
13
|
+
import { gitTool } from "./git.js";
|
|
14
|
+
import { browserTool } from "./browser.js";
|
|
15
|
+
import { checkpointTool } from "./checkpoint.js";
|
|
16
|
+
import { createCronTool } from "./cron.js";
|
|
17
|
+
import { lspGoToDefinitionTool } from "./lsp-definition.js";
|
|
18
|
+
import { lspFindReferencesTool } from "./lsp-references.js";
|
|
19
|
+
import { lspHoverTool } from "./lsp-hover.js";
|
|
20
|
+
import { lspDocumentSymbolsTool } from "./lsp-symbols.js";
|
|
17
21
|
// multimodal is a factory (needs runtime Provider) — wired in main.ts, not baked into builtInTools
|
|
18
|
-
export { createMultimodalTool } from
|
|
19
|
-
export { createCronTool } from
|
|
22
|
+
// export { createMultimodalTool } from "./multimodal.js";
|
|
23
|
+
export { createCronTool } from "./cron.js";
|
|
24
|
+
export { createTaskTool } from "./task.js";
|
|
20
25
|
const cronTool = createCronTool();
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
24
|
-
export * from
|
|
26
|
+
export * from "./registry.js";
|
|
27
|
+
export * from "./permission.js";
|
|
28
|
+
export * from "./exec.js";
|
|
29
|
+
export * from "./diff.js";
|
|
30
|
+
export * from "./lsp-definition.js";
|
|
31
|
+
export * from "./lsp-references.js";
|
|
32
|
+
export * from "./lsp-hover.js";
|
|
33
|
+
export * from "./lsp-symbols.js";
|
|
25
34
|
export const builtInTools = [
|
|
26
35
|
fsReadTool,
|
|
27
36
|
fsWriteTool,
|
|
@@ -34,6 +43,10 @@ export const builtInTools = [
|
|
|
34
43
|
browserTool,
|
|
35
44
|
checkpointTool,
|
|
36
45
|
cronTool,
|
|
46
|
+
lspGoToDefinitionTool,
|
|
47
|
+
lspFindReferencesTool,
|
|
48
|
+
lspHoverTool,
|
|
49
|
+
lspDocumentSymbolsTool,
|
|
37
50
|
];
|
|
38
|
-
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, browserTool, checkpointTool, cronTool, };
|
|
51
|
+
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, browserTool, checkpointTool, cronTool, lspGoToDefinitionTool, lspFindReferencesTool, lspHoverTool, lspDocumentSymbolsTool, };
|
|
39
52
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,O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Ac,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AAEjC,MAAM,CAAC,MAAM,YAAY,GAAW;IAClC,UAAU;IACV,WAAW;IACX,UAAU;IACV,QAAQ;IACR,SAAS;IACT,cAAc;IACd,cAAc;IACd,OAAO;IACP,WAAW;IACX,cAAc;IACd,QAAQ;IACR,qBAAqB;IACrB,qBAAqB;IACrB,YAAY;IACZ,sBAAsB;CACvB,CAAC;AAEF,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,cAAc,EACd,cAAc,EACd,OAAO,EACP,WAAW,EACX,cAAc,EACd,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,GACvB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { getLspManager } from "../lsp/index.js";
|
|
3
|
+
export const lspGoToDefinitionTool = {
|
|
4
|
+
name: "go_to_definition",
|
|
5
|
+
description: "Navigate to the definition of a symbol at a given position using LSP. " +
|
|
6
|
+
"Supports TypeScript, JavaScript, Python, Rust, and Go files when the " +
|
|
7
|
+
"corresponding language server is installed.",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
filePath: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Absolute path to the source file",
|
|
14
|
+
},
|
|
15
|
+
line: { type: "number", description: "1-indexed line number" },
|
|
16
|
+
character: { type: "number", description: "1-indexed character column" },
|
|
17
|
+
},
|
|
18
|
+
required: ["filePath", "line", "character"],
|
|
19
|
+
},
|
|
20
|
+
async execute(raw) {
|
|
21
|
+
const input = raw;
|
|
22
|
+
const filePath = resolve(input.filePath);
|
|
23
|
+
try {
|
|
24
|
+
const lsp = getLspManager();
|
|
25
|
+
const locations = await lsp.goToDefinition(filePath, input.line, input.character);
|
|
26
|
+
if (!locations.length) {
|
|
27
|
+
return {
|
|
28
|
+
content: `No definition found at ${filePath}:${input.line}:${input.character}`,
|
|
29
|
+
data: { definitions: [] },
|
|
30
|
+
isError: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const formatted = locations.map((loc) => `${loc.uri}:${loc.range.start.line + 1}:${loc.range.start.character + 1}`);
|
|
34
|
+
return {
|
|
35
|
+
content: `Found ${locations.length} definition(s):\n${formatted.join("\n")}`,
|
|
36
|
+
data: { definitions: locations },
|
|
37
|
+
isError: false,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return {
|
|
42
|
+
content: `LSP go_to_definition failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
43
|
+
isError: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=lsp-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lsp-definition.js","sourceRoot":"","sources":["../../src/tools/lsp-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,CAAC,MAAM,qBAAqB,GAAS;IACzC,IAAI,EAAE,kBAAkB;IACxB,WAAW,EACT,wEAAwE;QACxE,uEAAuE;QACvE,6CAA6C;IAC/C,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,kCAAkC;aAChD;YACD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,uBAAuB,EAAE;YAC9D,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4BAA4B,EAAE;SACzE;QACD,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,E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AI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { getLspManager } from "../lsp/index.js";
|
|
3
|
+
export const lspHoverTool = {
|
|
4
|
+
name: "hover_documentation",
|
|
5
|
+
description: "Get hover documentation for a symbol at a given position using LSP. " +
|
|
6
|
+
"Supports TypeScript, JavaScript, Python, Rust, and Go files when the " +
|
|
7
|
+
"corresponding language server is installed.",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
filePath: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Absolute path to the source file",
|
|
14
|
+
},
|
|
15
|
+
line: { type: "number", description: "1-indexed line number" },
|
|
16
|
+
character: { type: "number", description: "1-indexed character column" },
|
|
17
|
+
},
|
|
18
|
+
required: ["filePath", "line", "character"],
|
|
19
|
+
},
|
|
20
|
+
async execute(raw) {
|
|
21
|
+
const input = raw;
|
|
22
|
+
const filePath = resolve(input.filePath);
|
|
23
|
+
try {
|
|
24
|
+
const lsp = getLspManager();
|
|
25
|
+
const result = await lsp.hover(filePath, input.line, input.character);
|
|
26
|
+
if (!result) {
|
|
27
|
+
return {
|
|
28
|
+
content: `No documentation available at ${filePath}:${input.line}:${input.character}`,
|
|
29
|
+
data: { hover: null },
|
|
30
|
+
isError: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
let text;
|
|
34
|
+
const contents = result.contents;
|
|
35
|
+
if (typeof contents === "string") {
|
|
36
|
+
text = contents;
|
|
37
|
+
}
|
|
38
|
+
else if (Array.isArray(contents)) {
|
|
39
|
+
text = contents
|
|
40
|
+
.map((c) => typeof c === "string"
|
|
41
|
+
? c
|
|
42
|
+
: `\`\`\`${c.language ?? ""}\n${c.value}\n\`\`\``)
|
|
43
|
+
.join("\n");
|
|
44
|
+
}
|
|
45
|
+
else if (contents &&
|
|
46
|
+
typeof contents === "object" &&
|
|
47
|
+
"value" in contents) {
|
|
48
|
+
const marked = contents;
|
|
49
|
+
text = `\`\`\`${marked.language ?? ""}\n${marked.value}\n\`\`\``;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
text = JSON.stringify(contents);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
content: text,
|
|
56
|
+
data: { hover: result },
|
|
57
|
+
isError: false,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return {
|
|
62
|
+
content: `LSP hover failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
63
|
+
isError: true,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=lsp-hover.js.map
|