@gaunt-sloth/agent 0.1.8 → 2.0.0-alpha.1
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/README.md +14 -5
- package/cli-acp.js +35 -0
- package/cli.js +35 -0
- package/dist/builtInToolsConfig.d.ts +26 -0
- package/dist/builtInToolsConfig.js +148 -0
- package/dist/builtInToolsConfig.js.map +1 -0
- package/dist/core/GthDeepAgent.d.ts +76 -0
- package/dist/core/GthDeepAgent.js +368 -0
- package/dist/core/GthDeepAgent.js.map +1 -0
- package/dist/core/debugCapture.d.ts +51 -0
- package/dist/core/debugCapture.js +2 -0
- package/dist/core/debugCapture.js.map +1 -0
- package/dist/core/deepAgentPermissions.d.ts +55 -0
- package/dist/core/deepAgentPermissions.js +120 -0
- package/dist/core/deepAgentPermissions.js.map +1 -0
- package/dist/core/gthAcpServer.d.ts +27 -0
- package/dist/core/gthAcpServer.js +71 -0
- package/dist/core/gthAcpServer.js.map +1 -0
- package/dist/core/gthDeepAgentFactory.d.ts +8 -0
- package/dist/core/gthDeepAgentFactory.js +9 -0
- package/dist/core/gthDeepAgentFactory.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/OAuthClientProviderImpl.d.ts +37 -0
- package/dist/mcp/OAuthClientProviderImpl.js +223 -0
- package/dist/mcp/OAuthClientProviderImpl.js.map +1 -0
- package/dist/middleware/binaryContentInjectionMiddleware.d.ts +22 -0
- package/dist/middleware/binaryContentInjectionMiddleware.js +125 -0
- package/dist/middleware/binaryContentInjectionMiddleware.js.map +1 -0
- package/dist/middleware/registry.d.ts +34 -0
- package/dist/middleware/registry.js +124 -0
- package/dist/middleware/registry.js.map +1 -0
- package/dist/middleware/types.d.ts +89 -0
- package/dist/middleware/types.js +9 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/modules/a2a/A2AClientWrapper.d.ts +22 -0
- package/dist/modules/a2a/A2AClientWrapper.js +63 -0
- package/dist/modules/a2a/A2AClientWrapper.js.map +1 -0
- package/dist/modules/acpModule.d.ts +37 -0
- package/dist/modules/acpModule.js +67 -0
- package/dist/modules/acpModule.js.map +1 -0
- package/dist/modules/apiAgUiModule.d.ts +2 -0
- package/dist/modules/apiAgUiModule.js +417 -0
- package/dist/modules/apiAgUiModule.js.map +1 -0
- package/dist/modules/interactiveSessionModule.d.ts +9 -0
- package/dist/modules/interactiveSessionModule.js +99 -0
- package/dist/modules/interactiveSessionModule.js.map +1 -0
- package/dist/resolvers.d.ts +18 -0
- package/dist/resolvers.js +140 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/tools/A2AAgentTool.d.ts +24 -0
- package/dist/tools/A2AAgentTool.js +37 -0
- package/dist/tools/A2AAgentTool.js.map +1 -0
- package/dist/tools/GthCustomToolkit.d.ts +41 -0
- package/dist/tools/GthCustomToolkit.js +289 -0
- package/dist/tools/GthCustomToolkit.js.map +1 -0
- package/dist/tools/GthDevToolkit.d.ts +24 -0
- package/dist/tools/GthDevToolkit.js +189 -0
- package/dist/tools/GthDevToolkit.js.map +1 -0
- package/dist/tools/GthFileSystemToolkit.d.ts +36 -0
- package/dist/tools/GthFileSystemToolkit.js +775 -0
- package/dist/tools/GthFileSystemToolkit.js.map +1 -0
- package/dist/tools/binaryUtils.d.ts +13 -0
- package/dist/tools/binaryUtils.js +55 -0
- package/dist/tools/binaryUtils.js.map +1 -0
- package/dist/tools/gthStatusUpdateTool.d.ts +2 -0
- package/dist/tools/gthStatusUpdateTool.js +15 -0
- package/dist/tools/gthStatusUpdateTool.js.map +1 -0
- package/dist/tools/gthWebFetchTool.d.ts +2 -0
- package/dist/tools/gthWebFetchTool.js +47 -0
- package/dist/tools/gthWebFetchTool.js.map +1 -0
- package/dist/tools/showA2UISurfaceTool.d.ts +9 -0
- package/dist/tools/showA2UISurfaceTool.js +25 -0
- package/dist/tools/showA2UISurfaceTool.js.map +1 -0
- package/dist/utils/mcpUtils.d.ts +13 -0
- package/dist/utils/mcpUtils.js +225 -0
- package/dist/utils/mcpUtils.js.map +1 -0
- package/package.json +49 -10
- package/index.js +0 -6
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Resolver implementations for the AgentResolvers pattern.
|
|
4
|
+
*
|
|
5
|
+
* Provides `resolveTools` / `cleanupTools` that wire up built-in tools
|
|
6
|
+
* (filesystem, dev, custom), MCP servers, and A2A agents.
|
|
7
|
+
*
|
|
8
|
+
* Provides `resolveMiddleware` / `cleanupMiddleware` that delegate to the
|
|
9
|
+
* agent middleware registry.
|
|
10
|
+
*/
|
|
11
|
+
import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
|
|
12
|
+
import { displayInfo } from '@gaunt-sloth/core/utils/consoleUtils.js';
|
|
13
|
+
import { createA2AAgentTool } from '#src/tools/A2AAgentTool.js';
|
|
14
|
+
import { prepareMcpTools } from '#src/utils/mcpUtils.js';
|
|
15
|
+
import { createAuthProviderAndAuthenticate } from '#src/mcp/OAuthClientProviderImpl.js';
|
|
16
|
+
import { MultiServerMCPClient } from '@langchain/mcp-adapters';
|
|
17
|
+
/**
|
|
18
|
+
* Create a full set of resolvers for the GthLangChainAgent.
|
|
19
|
+
*
|
|
20
|
+
* Each call returns a fresh set of resolvers with their own MCP client
|
|
21
|
+
* instance, avoiding shared module-level state and race conditions.
|
|
22
|
+
*/
|
|
23
|
+
export function createResolvers() {
|
|
24
|
+
let mcpClientInstance = null;
|
|
25
|
+
const resolveTools = async (config, command) => {
|
|
26
|
+
const tools = [];
|
|
27
|
+
// 1. Get built-in tools (filesystem, devTools, customTools, etc.)
|
|
28
|
+
try {
|
|
29
|
+
const { getDefaultTools } = await import('#src/builtInToolsConfig.js');
|
|
30
|
+
const defaultTools = await getDefaultTools(config, command);
|
|
31
|
+
debugLog(`Default tools loaded: ${defaultTools.length}`);
|
|
32
|
+
tools.push(...defaultTools);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
debugLog(`Built-in tools not available: ${error}`);
|
|
36
|
+
}
|
|
37
|
+
// 2. Get MCP tools
|
|
38
|
+
try {
|
|
39
|
+
mcpClientInstance = await getMcpClient(config);
|
|
40
|
+
if (mcpClientInstance) {
|
|
41
|
+
const rawMcpTools = await mcpClientInstance.getTools();
|
|
42
|
+
// Use a simple status callback for prepareMcpTools
|
|
43
|
+
const statusCallback = (level, message) => {
|
|
44
|
+
displayInfo(message);
|
|
45
|
+
};
|
|
46
|
+
const mcpTools = prepareMcpTools(statusCallback, config, rawMcpTools) ?? [];
|
|
47
|
+
debugLog(`MCP tools loaded: ${mcpTools.length}`);
|
|
48
|
+
tools.push(...mcpTools);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
debugLog(`MCP tools error: ${error}`);
|
|
53
|
+
}
|
|
54
|
+
// 3. Get A2A tools
|
|
55
|
+
const a2aTools = getA2ATools(config);
|
|
56
|
+
debugLog(`A2A tools loaded: ${a2aTools.length}`);
|
|
57
|
+
tools.push(...a2aTools);
|
|
58
|
+
return tools;
|
|
59
|
+
};
|
|
60
|
+
const cleanupTools = async () => {
|
|
61
|
+
if (mcpClientInstance) {
|
|
62
|
+
try {
|
|
63
|
+
await mcpClientInstance.close();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Ignore cleanup errors
|
|
67
|
+
}
|
|
68
|
+
mcpClientInstance = null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const resolveMiddleware = async (
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
middleware, config
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
) => {
|
|
76
|
+
try {
|
|
77
|
+
const { resolveMiddleware: resolve } = await import('#src/middleware/registry.js');
|
|
78
|
+
return await resolve(middleware, config);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
debugLog(`Middleware resolution error: ${error}`);
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const cleanupMiddleware = async () => {
|
|
86
|
+
// No cleanup needed for middleware currently
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
resolveTools,
|
|
90
|
+
cleanupTools,
|
|
91
|
+
resolveMiddleware,
|
|
92
|
+
cleanupMiddleware,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// --- Private helpers ---
|
|
96
|
+
async function getMcpClient(config) {
|
|
97
|
+
debugLog('Setting up MCP client...');
|
|
98
|
+
const rawMcpServers = { ...(config.mcpServers || {}) };
|
|
99
|
+
debugLog(`MCP servers count: ${Object.keys(rawMcpServers).length}`);
|
|
100
|
+
const mcpServers = {};
|
|
101
|
+
for (const serverName of Object.keys(rawMcpServers)) {
|
|
102
|
+
const server = rawMcpServers[serverName];
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
if (server.url && server && server.authProvider === 'OAuth') {
|
|
105
|
+
displayInfo(`Starting OAuth for ${server.url}`);
|
|
106
|
+
const authProvider = await createAuthProviderAndAuthenticate(server);
|
|
107
|
+
mcpServers[serverName] = {
|
|
108
|
+
...server,
|
|
109
|
+
authProvider,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
mcpServers[serverName] = server;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(mcpServers).length > 0) {
|
|
117
|
+
debugLog('Creating MultiServerMCPClient...');
|
|
118
|
+
return new MultiServerMCPClient({
|
|
119
|
+
throwOnLoadError: true,
|
|
120
|
+
prefixToolNameWithServerName: true,
|
|
121
|
+
additionalToolNamePrefix: 'mcp',
|
|
122
|
+
mcpServers: mcpServers,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
debugLog('No MCP servers configured');
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function getA2ATools(config) {
|
|
131
|
+
debugLog('Setting up A2A tools...');
|
|
132
|
+
const a2aAgents = (config.a2aAgents || {});
|
|
133
|
+
const tools = [];
|
|
134
|
+
for (const [agentId, agentConfig] of Object.entries(a2aAgents)) {
|
|
135
|
+
debugLog(`Adding A2A agent tool: ${agentId}`);
|
|
136
|
+
tools.push(createA2AAgentTool(agentConfig));
|
|
137
|
+
}
|
|
138
|
+
return tools;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=resolvers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.js","sourceRoot":"","sources":["../src/resolvers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAiC,MAAM,yBAAyB,CAAC;AAG9F;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,iBAAiB,GAAgC,IAAI,CAAC;IAE1D,MAAM,YAAY,GAAG,KAAK,EACxB,MAAiB,EACjB,OAAoB,EACgB,EAAE;QACtC,MAAM,KAAK,GAA8B,EAAE,CAAC;QAE5C,kEAAkE;QAClE,IAAI,CAAC;YACH,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,4BAA4B,CAAC,CAAC;YACvE,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC5D,QAAQ,CAAC,yBAAyB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;YACzD,KAAK,CAAC,IAAI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AAE,CAAC,CAAC;YAChD,MAAM,YAAY,GAAG,MAAM,iCAAiC,CAAC,MAAM,CAAC,CAAC;YACrE,UAAU,CAAC,UAAU,CAAC,GAAG;gBACvB,GAAG,MAAM;gBACT,YAAY;aACb,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;QAClC,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,QAAQ,CAAC,kCAAkC,CAAC,CAAC;QAC7C,OAAO,IAAI,oBAAoB,CAAC;YAC9B,gBAAgB,EAAE,IAAI;YACtB,4BAA4B,EAAE,IAAI;YAClC,wBAAwB,EAAE,KAAK;YAC/B,UAAU,EAAE,UAAU;SACvB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,2BAA2B,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,MAAiB;IACpC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAGxC,CAAC;IACF,MAAM,KAAK,GAA8B,EAAE,CAAC;IAE5C,KAAK,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/D,QAAQ,CAAC,0BAA0B,OAAO,EAAE,CAAC,CAAC;QAC9C,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module A2AAgentTool
|
|
3
|
+
* LangChain tool for interacting with A2A protocol agents.
|
|
4
|
+
* @experimental A2A support is experimental and may change.
|
|
5
|
+
*/
|
|
6
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/**
|
|
9
|
+
* Creates a LangChain tool for communicating with an A2A agent.
|
|
10
|
+
* The tool will be named `a2a_agent_<agentId>`.
|
|
11
|
+
* @param config - A2A agent configuration
|
|
12
|
+
* @returns A DynamicStructuredTool for the agent
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
export declare const createA2AAgentTool: (config: {
|
|
16
|
+
agentId: string;
|
|
17
|
+
agentUrl: string;
|
|
18
|
+
}) => DynamicStructuredTool<z.ZodObject<{
|
|
19
|
+
message: z.ZodString;
|
|
20
|
+
}, z.core.$strip>, {
|
|
21
|
+
message: string;
|
|
22
|
+
}, {
|
|
23
|
+
message: string;
|
|
24
|
+
}, string, unknown, `a2a_agent_${string}`>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module A2AAgentTool
|
|
3
|
+
* LangChain tool for interacting with A2A protocol agents.
|
|
4
|
+
* @experimental A2A support is experimental and may change.
|
|
5
|
+
*/
|
|
6
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { A2AClientWrapper } from '#src/modules/a2a/A2AClientWrapper.js';
|
|
9
|
+
import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a LangChain tool for communicating with an A2A agent.
|
|
12
|
+
* The tool will be named `a2a_agent_<agentId>`.
|
|
13
|
+
* @param config - A2A agent configuration
|
|
14
|
+
* @returns A DynamicStructuredTool for the agent
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export const createA2AAgentTool = (config) => {
|
|
18
|
+
const client = new A2AClientWrapper(config);
|
|
19
|
+
return new DynamicStructuredTool({
|
|
20
|
+
name: `a2a_agent_${config.agentId}`,
|
|
21
|
+
description: `Interact with the external A2A agent '${config.agentId}'. Use this tool to delegate tasks or ask questions to the external agent.`,
|
|
22
|
+
schema: z.object({
|
|
23
|
+
message: z.string().describe('The message or task description to send to the agent.'),
|
|
24
|
+
}),
|
|
25
|
+
func: async ({ message }) => {
|
|
26
|
+
debugLog(`Tool a2a_agent_${config.agentId} called with message: ${message}`);
|
|
27
|
+
try {
|
|
28
|
+
const response = await client.sendMessage(message);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return `Error communicating with agent: ${error.message}`;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=A2AAgentTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A2AAgentTool.js","sourceRoot":"","sources":["../../src/tools/A2AAgentTool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAA6C,EAAE,EAAE;IAClF,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE5C,OAAO,IAAI,qBAAqB,CAAC;QAC/B,IAAI,EAAE,aAAa,MAAM,CAAC,OAAO,EAAE;QACnC,WAAW,EAAE,yCAAyC,MAAM,CAAC,OAAO,4EAA4E;QAChJ,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uDAAuD,CAAC;SACtF,CAAC;QACF,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YAC1B,QAAQ,CAAC,kBAAkB,MAAM,CAAC,OAAO,yBAAyB,OAAO,EAAE,CAAC,CAAC;YAC7E,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBACnD,OAAO,QAAQ,CAAC;YAClB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,mCAAoC,KAAe,CAAC,OAAO,EAAE,CAAC;YACvE,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module GthCustomToolkit
|
|
3
|
+
* Toolkit for user-defined custom shell commands.
|
|
4
|
+
* Provides secure execution of shell commands with parameter validation.
|
|
5
|
+
*/
|
|
6
|
+
import { BaseToolkit, StructuredToolInterface } from '@langchain/core/tools';
|
|
7
|
+
import { CustomToolsConfig, CustomCommandParameter, ValidationCheck } from '@gaunt-sloth/core/config.js';
|
|
8
|
+
export default class GthCustomToolkit extends BaseToolkit {
|
|
9
|
+
tools: StructuredToolInterface[];
|
|
10
|
+
private customTools;
|
|
11
|
+
constructor(customTools?: CustomToolsConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Validate parameter value to prevent security issues.
|
|
14
|
+
* Checks can be selectively skipped via the `allow` list.
|
|
15
|
+
*/
|
|
16
|
+
validateParameterValue(paramValue: string, paramName: string, allow?: ValidationCheck[]): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build a custom command with parameter interpolation
|
|
19
|
+
*/
|
|
20
|
+
buildCustomCommand(commandTemplate: string, parameters: Record<string, string>, parameterConfig?: Record<string, CustomCommandParameter>): string;
|
|
21
|
+
/**
|
|
22
|
+
* Prompt the user to confirm execution of a command that failed validation.
|
|
23
|
+
* Returns true if the user confirms, false otherwise.
|
|
24
|
+
*/
|
|
25
|
+
promptUserForValidationOverride(command: string, toolName: string, validationError: string): Promise<boolean>;
|
|
26
|
+
private executeCommand;
|
|
27
|
+
/**
|
|
28
|
+
* Create a Zod schema for a custom command's parameters
|
|
29
|
+
*/
|
|
30
|
+
private createCustomCommandSchema;
|
|
31
|
+
/**
|
|
32
|
+
* Build command without validation (for display in the user prompt).
|
|
33
|
+
* Simply interpolates parameters into the template without security checks.
|
|
34
|
+
*/
|
|
35
|
+
private buildCommandForDisplay;
|
|
36
|
+
/**
|
|
37
|
+
* Create a tool for a custom command
|
|
38
|
+
*/
|
|
39
|
+
private createCustomCommandTool;
|
|
40
|
+
private createTools;
|
|
41
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module GthCustomToolkit
|
|
3
|
+
* Toolkit for user-defined custom shell commands.
|
|
4
|
+
* Provides secure execution of shell commands with parameter validation.
|
|
5
|
+
*/
|
|
6
|
+
import { BaseToolkit, tool } from '@langchain/core/tools';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { displayInfo, displayError, displayWarning } from '@gaunt-sloth/core/utils/consoleUtils.js';
|
|
11
|
+
import { createInterface, stdin, stdout } from '@gaunt-sloth/core/utils/systemUtils.js';
|
|
12
|
+
// Helper function to create a tool with execute type
|
|
13
|
+
function createCustomTool(fn, config) {
|
|
14
|
+
const toolInstance = tool(fn, config);
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
toolInstance.gthCustomType = 'execute';
|
|
17
|
+
return toolInstance;
|
|
18
|
+
}
|
|
19
|
+
export default class GthCustomToolkit extends BaseToolkit {
|
|
20
|
+
tools;
|
|
21
|
+
customTools;
|
|
22
|
+
constructor(customTools = {}) {
|
|
23
|
+
super();
|
|
24
|
+
this.customTools = customTools;
|
|
25
|
+
this.tools = this.createTools();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validate parameter value to prevent security issues.
|
|
29
|
+
* Checks can be selectively skipped via the `allow` list.
|
|
30
|
+
*/
|
|
31
|
+
validateParameterValue(paramValue, paramName, allow = []) {
|
|
32
|
+
const allowSet = new Set(allow);
|
|
33
|
+
// Check for absolute paths
|
|
34
|
+
if (!allowSet.has('absolute-paths') && path.isAbsolute(paramValue)) {
|
|
35
|
+
throw new Error(`Absolute paths are not allowed for parameter '${paramName}'`);
|
|
36
|
+
}
|
|
37
|
+
// Check for directory traversal attempts
|
|
38
|
+
if (!allowSet.has('directory-traversal') &&
|
|
39
|
+
(paramValue.includes('..') || paramValue.includes('\\..\\') || paramValue.includes('/../'))) {
|
|
40
|
+
throw new Error(`Directory traversal attempts are not allowed in parameter '${paramName}'`);
|
|
41
|
+
}
|
|
42
|
+
// Check for pipe attempts and other shell injection
|
|
43
|
+
if (!allowSet.has('shell-injection') &&
|
|
44
|
+
(paramValue.includes('|') ||
|
|
45
|
+
paramValue.includes('&') ||
|
|
46
|
+
paramValue.includes(';') ||
|
|
47
|
+
paramValue.includes('`') ||
|
|
48
|
+
paramValue.includes("'") ||
|
|
49
|
+
paramValue.includes('$') ||
|
|
50
|
+
paramValue.includes('$(') ||
|
|
51
|
+
paramValue.includes('\n') ||
|
|
52
|
+
paramValue.includes('\r'))) {
|
|
53
|
+
throw new Error(`Shell injection attempts are not allowed in parameter '${paramName}'.` +
|
|
54
|
+
'Disallowed symbols pipe, ampersand, semicolon, backtick, single quote, dollar sign, command substitution, newline, carriage return');
|
|
55
|
+
}
|
|
56
|
+
// Check for null bytes
|
|
57
|
+
if (!allowSet.has('null-bytes') && paramValue.includes('\0')) {
|
|
58
|
+
throw new Error(`Null bytes are not allowed in parameter '${paramName}'`);
|
|
59
|
+
}
|
|
60
|
+
// Normalize the path to remove any redundant separators
|
|
61
|
+
// Skip normalization when absolute paths are allowed, since normalize
|
|
62
|
+
// would strip the leading separator context on some values
|
|
63
|
+
if (allowSet.has('absolute-paths')) {
|
|
64
|
+
// Still do the post-normalization traversal check when traversal is not allowed
|
|
65
|
+
if (!allowSet.has('directory-traversal')) {
|
|
66
|
+
const normalizedValue = path.normalize(paramValue);
|
|
67
|
+
if (normalizedValue.includes('..')) {
|
|
68
|
+
throw new Error(`Directory traversal attempts are not allowed in parameter '${paramName}'`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return paramValue;
|
|
72
|
+
}
|
|
73
|
+
const normalizedValue = path.normalize(paramValue);
|
|
74
|
+
// Double-check after normalization
|
|
75
|
+
if (!allowSet.has('directory-traversal') && normalizedValue.includes('..')) {
|
|
76
|
+
throw new Error(`Directory traversal attempts are not allowed in parameter '${paramName}'`);
|
|
77
|
+
}
|
|
78
|
+
return normalizedValue;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build a custom command with parameter interpolation
|
|
82
|
+
*/
|
|
83
|
+
buildCustomCommand(commandTemplate, parameters, parameterConfig) {
|
|
84
|
+
let command = commandTemplate;
|
|
85
|
+
const paramNames = Object.keys(parameters);
|
|
86
|
+
// Check if all provided parameters have placeholders or should be appended
|
|
87
|
+
const hasPlaceholders = paramNames.some((name) => command.includes(`\${${name}}`));
|
|
88
|
+
if (hasPlaceholders) {
|
|
89
|
+
// Replace all placeholders with validated parameter values
|
|
90
|
+
for (const [name, value] of Object.entries(parameters)) {
|
|
91
|
+
const allow = parameterConfig?.[name]?.allow || [];
|
|
92
|
+
const validatedValue = this.validateParameterValue(value, name, allow);
|
|
93
|
+
const placeholder = '${' + name + '}';
|
|
94
|
+
command = command.replace(new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), validatedValue);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (paramNames.length > 0 && parameterConfig) {
|
|
98
|
+
// Append parameters in the order defined in the config
|
|
99
|
+
const orderedParams = Object.keys(parameterConfig);
|
|
100
|
+
const appendValues = [];
|
|
101
|
+
for (const name of orderedParams) {
|
|
102
|
+
if (parameters[name] !== undefined) {
|
|
103
|
+
const allow = parameterConfig[name]?.allow || [];
|
|
104
|
+
const validatedValue = this.validateParameterValue(parameters[name], name, allow);
|
|
105
|
+
appendValues.push(validatedValue);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (appendValues.length > 0) {
|
|
109
|
+
command = `${command} ${appendValues.join(' ')}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return command;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Prompt the user to confirm execution of a command that failed validation.
|
|
116
|
+
* Returns true if the user confirms, false otherwise.
|
|
117
|
+
*/
|
|
118
|
+
async promptUserForValidationOverride(command, toolName, validationError) {
|
|
119
|
+
displayWarning(`\n⚠️ Validation failed for tool '${toolName}': ${validationError}`);
|
|
120
|
+
displayWarning(`The agent is trying to execute: ${command}`);
|
|
121
|
+
displayWarning('You can add "allow" to this tool\'s configuration in .gsloth.config.json to skip this check (permanent). ' +
|
|
122
|
+
'Available values: "absolute-paths", "directory-traversal", "shell-injection", "null-bytes"');
|
|
123
|
+
// The agent stream may have stdin in raw mode for Escape/Q interruption.
|
|
124
|
+
// Readline needs canonical line mode for y/N to be delivered after Enter.
|
|
125
|
+
const shouldRestoreRawMode = stdin.isTTY && stdin.isRaw;
|
|
126
|
+
if (shouldRestoreRawMode) {
|
|
127
|
+
stdin.setRawMode(false);
|
|
128
|
+
}
|
|
129
|
+
// Write prompt manually to avoid double-echo when readline echoes input
|
|
130
|
+
stdout.write('Do you want to allow this execution (one-time)? (y/N): ');
|
|
131
|
+
const rl = createInterface({ input: stdin });
|
|
132
|
+
try {
|
|
133
|
+
const answer = await rl.question('');
|
|
134
|
+
return answer.trim().toLowerCase() === 'y' || answer.trim().toLowerCase() === 'yes';
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
rl.close();
|
|
138
|
+
if (shouldRestoreRawMode) {
|
|
139
|
+
stdin.setRawMode(true);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async executeCommand(command, toolName, timeoutSeconds) {
|
|
144
|
+
displayInfo(`\n🔧 Executing ${toolName}: ${command}`);
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const child = spawn(command, {
|
|
147
|
+
shell: true,
|
|
148
|
+
});
|
|
149
|
+
let output = '';
|
|
150
|
+
let timedOut = false;
|
|
151
|
+
let timer;
|
|
152
|
+
if (timeoutSeconds !== undefined && timeoutSeconds > 0) {
|
|
153
|
+
timer = setTimeout(() => {
|
|
154
|
+
timedOut = true;
|
|
155
|
+
child.kill();
|
|
156
|
+
}, timeoutSeconds * 1000);
|
|
157
|
+
}
|
|
158
|
+
// Capture output if available (when stdio is not 'inherit')
|
|
159
|
+
if (child.stdout) {
|
|
160
|
+
child.stdout.on('data', (data) => {
|
|
161
|
+
const chunk = data.toString();
|
|
162
|
+
stdout.write(chunk);
|
|
163
|
+
output += chunk;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (child.stderr) {
|
|
167
|
+
child.stderr.on('data', (data) => {
|
|
168
|
+
const chunk = data.toString();
|
|
169
|
+
stdout.write(chunk);
|
|
170
|
+
output += chunk;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
child.on('close', (code) => {
|
|
174
|
+
if (timer)
|
|
175
|
+
clearTimeout(timer);
|
|
176
|
+
if (timedOut) {
|
|
177
|
+
resolve(`Executing '${command}'...\n\n` +
|
|
178
|
+
`<COMMAND_OUTPUT>\n` +
|
|
179
|
+
output +
|
|
180
|
+
`</COMMAND_OUTPUT>\n` +
|
|
181
|
+
`\n\nCommand '${command}' timed out after ${timeoutSeconds} seconds`);
|
|
182
|
+
}
|
|
183
|
+
else if (code === 0) {
|
|
184
|
+
resolve(`Executing '${command}'...\n\n` +
|
|
185
|
+
`<COMMAND_OUTPUT>\n` +
|
|
186
|
+
output +
|
|
187
|
+
`</COMMAND_OUTPUT>\n` +
|
|
188
|
+
`\n\nCommand '${command}' completed successfully`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
resolve(`Executing '${command}'...\n\n` +
|
|
192
|
+
`<COMMAND_OUTPUT>\n` +
|
|
193
|
+
output +
|
|
194
|
+
`</COMMAND_OUTPUT>\n` +
|
|
195
|
+
`\n\nCommand '${command}' exited with code ${code}`);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
child.on('error', (error) => {
|
|
199
|
+
if (timer)
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
const errorMsg = `Failed to execute command '${command}': ${error.message}`;
|
|
202
|
+
displayError(errorMsg);
|
|
203
|
+
reject(new Error(errorMsg));
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Create a Zod schema for a custom command's parameters
|
|
209
|
+
*/
|
|
210
|
+
createCustomCommandSchema(config
|
|
211
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
212
|
+
) {
|
|
213
|
+
if (!config.parameters || Object.keys(config.parameters).length === 0) {
|
|
214
|
+
return z.object({});
|
|
215
|
+
}
|
|
216
|
+
const shape = {};
|
|
217
|
+
for (const [paramName, paramConfig] of Object.entries(config.parameters)) {
|
|
218
|
+
shape[paramName] = z.string().describe(paramConfig.description);
|
|
219
|
+
}
|
|
220
|
+
return z.object(shape);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Build command without validation (for display in the user prompt).
|
|
224
|
+
* Simply interpolates parameters into the template without security checks.
|
|
225
|
+
*/
|
|
226
|
+
buildCommandForDisplay(commandTemplate, parameters, parameterConfig) {
|
|
227
|
+
let command = commandTemplate;
|
|
228
|
+
const paramNames = Object.keys(parameters);
|
|
229
|
+
const hasPlaceholders = paramNames.some((name) => command.includes(`\${${name}}`));
|
|
230
|
+
if (hasPlaceholders) {
|
|
231
|
+
for (const [name, value] of Object.entries(parameters)) {
|
|
232
|
+
const placeholder = '${' + name + '}';
|
|
233
|
+
command = command.replace(new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), value);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (paramNames.length > 0 && parameterConfig) {
|
|
237
|
+
const orderedParams = Object.keys(parameterConfig);
|
|
238
|
+
const appendValues = [];
|
|
239
|
+
for (const name of orderedParams) {
|
|
240
|
+
if (parameters[name] !== undefined) {
|
|
241
|
+
appendValues.push(parameters[name]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (appendValues.length > 0) {
|
|
245
|
+
command = `${command} ${appendValues.join(' ')}`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return command;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Create a tool for a custom command
|
|
252
|
+
*/
|
|
253
|
+
createCustomCommandTool(name, config) {
|
|
254
|
+
const schema = this.createCustomCommandSchema(config);
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
256
|
+
const toolFn = async (args) => {
|
|
257
|
+
// All parameters are strings, safe to cast
|
|
258
|
+
const stringArgs = args;
|
|
259
|
+
try {
|
|
260
|
+
const command = this.buildCustomCommand(config.command, stringArgs, config.parameters);
|
|
261
|
+
return await this.executeCommand(command, name, config.timeout);
|
|
262
|
+
}
|
|
263
|
+
catch (validationError) {
|
|
264
|
+
// If validation fails, prompt the user for confirmation
|
|
265
|
+
const errorMessage = validationError instanceof Error ? validationError.message : String(validationError);
|
|
266
|
+
const displayCommand = this.buildCommandForDisplay(config.command, stringArgs, config.parameters);
|
|
267
|
+
const userConfirmed = await this.promptUserForValidationOverride(displayCommand, name, errorMessage);
|
|
268
|
+
if (userConfirmed) {
|
|
269
|
+
return await this.executeCommand(displayCommand, name);
|
|
270
|
+
}
|
|
271
|
+
throw new Error(`Execution of '${name}' was rejected by user. Validation error: ${errorMessage}`);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
return createCustomTool(toolFn, {
|
|
275
|
+
name,
|
|
276
|
+
description: config.description + `\nThe configured command is [${config.command}].`,
|
|
277
|
+
schema,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
createTools() {
|
|
281
|
+
const tools = [];
|
|
282
|
+
// Create tools for custom commands
|
|
283
|
+
for (const [name, config] of Object.entries(this.customTools)) {
|
|
284
|
+
tools.push(this.createCustomCommandTool(name, config));
|
|
285
|
+
}
|
|
286
|
+
return tools;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=GthCustomToolkit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GthCustomToolkit.js","sourceRoot":"","sources":["../../src/tools/GthCustomToolkit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAA2B,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAOpG,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AAExF,qDAAqD;AACrD,SAAS,gBAAgB,CACvB,EAAyC,EACzC,MAIC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACtC,8DAA8D;IAC7D,YAAoB,CAAC,aAAa,GAAG,SAAS,CAAC;IAChD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,WAAW;IACvD,KAAK,CAA4B;IACzB,WAAW,CAAoB;IAEvC,YAAY,cAAiC,EAAE;QAC7C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC;IAED;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AAE,IAAI,CAAC,CAAC;gBACzD,CAAC;gBAED,MAAM,IAAI,KAAK,CACb,iBAAiB,IAAI,6CAA6C,YAAY,EAAE,CACjF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,gBAAgB,CAAC,MAAM,EAAE;YAC9B,IAAI;YACJ,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,gCAAgC,MAAM,CAAC,OAAO,IAAI;YACpF,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAEO,WAAW;QACjB,MAAM,KAAK,GAA8B,EAAE,CAAC;QAE5C,mCAAmC;QACnC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module GthDevToolkit
|
|
3
|
+
*/
|
|
4
|
+
import { BaseToolkit, StructuredToolInterface } from '@langchain/core/tools';
|
|
5
|
+
import { GthDevToolsConfig } from '@gaunt-sloth/core/config.js';
|
|
6
|
+
export default class GthDevToolkit extends BaseToolkit {
|
|
7
|
+
tools: StructuredToolInterface[];
|
|
8
|
+
private commands;
|
|
9
|
+
constructor(commands?: GthDevToolsConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Get tools filtered by operation type
|
|
12
|
+
*/
|
|
13
|
+
getFilteredTools(allowedOperations: 'execute'[]): StructuredToolInterface[];
|
|
14
|
+
/**
|
|
15
|
+
* Validate parameter value to prevent security issues
|
|
16
|
+
*/
|
|
17
|
+
validateParameterValue(paramValue: string, paramName: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Build the command for running a single test file
|
|
20
|
+
*/
|
|
21
|
+
private buildSingleTestCommand;
|
|
22
|
+
private executeCommand;
|
|
23
|
+
private createTools;
|
|
24
|
+
}
|