@clinebot/core 0.0.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/README.md +88 -0
- package/dist/account/cline-account-service.d.ts +34 -0
- package/dist/account/index.d.ts +3 -0
- package/dist/account/rpc.d.ts +38 -0
- package/dist/account/types.d.ts +74 -0
- package/dist/agents/agent-config-loader.d.ts +18 -0
- package/dist/agents/agent-config-parser.d.ts +25 -0
- package/dist/agents/hooks-config-loader.d.ts +23 -0
- package/dist/agents/index.d.ts +11 -0
- package/dist/agents/plugin-config-loader.d.ts +22 -0
- package/dist/agents/plugin-loader.d.ts +9 -0
- package/dist/agents/plugin-sandbox.d.ts +12 -0
- package/dist/agents/unified-config-file-watcher.d.ts +77 -0
- package/dist/agents/user-instruction-config-loader.d.ts +63 -0
- package/dist/auth/client.d.ts +11 -0
- package/dist/auth/cline.d.ts +41 -0
- package/dist/auth/codex.d.ts +39 -0
- package/dist/auth/oca.d.ts +22 -0
- package/dist/auth/server.d.ts +22 -0
- package/dist/auth/types.d.ts +72 -0
- package/dist/auth/utils.d.ts +32 -0
- package/dist/chat/chat-schema.d.ts +145 -0
- package/dist/default-tools/constants.d.ts +23 -0
- package/dist/default-tools/definitions.d.ts +96 -0
- package/dist/default-tools/executors/apply-patch-parser.d.ts +68 -0
- package/dist/default-tools/executors/apply-patch.d.ts +26 -0
- package/dist/default-tools/executors/bash.d.ts +49 -0
- package/dist/default-tools/executors/editor.d.ts +31 -0
- package/dist/default-tools/executors/file-read.d.ts +40 -0
- package/dist/default-tools/executors/index.d.ts +44 -0
- package/dist/default-tools/executors/search.d.ts +50 -0
- package/dist/default-tools/executors/web-fetch.d.ts +58 -0
- package/dist/default-tools/index.d.ts +57 -0
- package/dist/default-tools/presets.d.ts +124 -0
- package/dist/default-tools/schemas.d.ts +121 -0
- package/dist/default-tools/types.d.ts +237 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +220 -0
- package/dist/input/file-indexer.d.ts +5 -0
- package/dist/input/index.d.ts +4 -0
- package/dist/input/mention-enricher.d.ts +12 -0
- package/dist/mcp/config-loader.d.ts +15 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/manager.d.ts +24 -0
- package/dist/mcp/types.d.ts +66 -0
- package/dist/runtime/hook-file-hooks.d.ts +18 -0
- package/dist/runtime/rules.d.ts +5 -0
- package/dist/runtime/runtime-builder.d.ts +5 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +19 -0
- package/dist/runtime/session-runtime.d.ts +36 -0
- package/dist/runtime/tool-approval.d.ts +9 -0
- package/dist/runtime/workflows.d.ts +13 -0
- package/dist/server/index.d.ts +47 -0
- package/dist/server/index.js +641 -0
- package/dist/session/default-session-manager.d.ts +77 -0
- package/dist/session/rpc-session-service.d.ts +12 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +28 -0
- package/dist/session/session-artifacts.d.ts +19 -0
- package/dist/session/session-graph.d.ts +15 -0
- package/dist/session/session-host.d.ts +21 -0
- package/dist/session/session-manager.d.ts +50 -0
- package/dist/session/session-manifest.d.ts +30 -0
- package/dist/session/session-service.d.ts +113 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +30 -0
- package/dist/session/unified-session-persistence-service.d.ts +93 -0
- package/dist/session/workspace-manager.d.ts +28 -0
- package/dist/session/workspace-manifest.d.ts +25 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +13 -0
- package/dist/storage/provider-settings-manager.d.ts +20 -0
- package/dist/storage/sqlite-session-store.d.ts +29 -0
- package/dist/storage/sqlite-team-store.d.ts +31 -0
- package/dist/storage/team-store.d.ts +2 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/projections.d.ts +8 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/types/config.d.ts +37 -0
- package/dist/types/events.d.ts +54 -0
- package/dist/types/provider-settings.d.ts +20 -0
- package/dist/types/sessions.d.ts +9 -0
- package/dist/types/storage.d.ts +37 -0
- package/dist/types/workspace.d.ts +7 -0
- package/dist/types.d.ts +26 -0
- package/package.json +63 -0
- package/src/account/cline-account-service.test.ts +101 -0
- package/src/account/cline-account-service.ts +267 -0
- package/src/account/index.ts +20 -0
- package/src/account/rpc.test.ts +62 -0
- package/src/account/rpc.ts +172 -0
- package/src/account/types.ts +80 -0
- package/src/agents/agent-config-loader.test.ts +234 -0
- package/src/agents/agent-config-loader.ts +107 -0
- package/src/agents/agent-config-parser.ts +191 -0
- package/src/agents/hooks-config-loader.ts +97 -0
- package/src/agents/index.ts +84 -0
- package/src/agents/plugin-config-loader.test.ts +91 -0
- package/src/agents/plugin-config-loader.ts +160 -0
- package/src/agents/plugin-loader.test.ts +102 -0
- package/src/agents/plugin-loader.ts +105 -0
- package/src/agents/plugin-sandbox.test.ts +120 -0
- package/src/agents/plugin-sandbox.ts +471 -0
- package/src/agents/unified-config-file-watcher.test.ts +196 -0
- package/src/agents/unified-config-file-watcher.ts +483 -0
- package/src/agents/user-instruction-config-loader.test.ts +158 -0
- package/src/agents/user-instruction-config-loader.ts +438 -0
- package/src/auth/client.test.ts +40 -0
- package/src/auth/client.ts +25 -0
- package/src/auth/cline.test.ts +130 -0
- package/src/auth/cline.ts +414 -0
- package/src/auth/codex.test.ts +170 -0
- package/src/auth/codex.ts +466 -0
- package/src/auth/oca.test.ts +215 -0
- package/src/auth/oca.ts +546 -0
- package/src/auth/server.ts +216 -0
- package/src/auth/types.ts +78 -0
- package/src/auth/utils.test.ts +128 -0
- package/src/auth/utils.ts +247 -0
- package/src/chat/chat-schema.ts +82 -0
- package/src/default-tools/constants.ts +35 -0
- package/src/default-tools/definitions.test.ts +233 -0
- package/src/default-tools/definitions.ts +632 -0
- package/src/default-tools/executors/apply-patch-parser.ts +520 -0
- package/src/default-tools/executors/apply-patch.ts +359 -0
- package/src/default-tools/executors/bash.ts +205 -0
- package/src/default-tools/executors/editor.ts +231 -0
- package/src/default-tools/executors/file-read.test.ts +25 -0
- package/src/default-tools/executors/file-read.ts +94 -0
- package/src/default-tools/executors/index.ts +75 -0
- package/src/default-tools/executors/search.ts +278 -0
- package/src/default-tools/executors/web-fetch.ts +259 -0
- package/src/default-tools/index.ts +161 -0
- package/src/default-tools/presets.test.ts +63 -0
- package/src/default-tools/presets.ts +168 -0
- package/src/default-tools/schemas.ts +228 -0
- package/src/default-tools/types.ts +324 -0
- package/src/index.ts +119 -0
- package/src/input/file-indexer.d.ts +11 -0
- package/src/input/file-indexer.test.ts +87 -0
- package/src/input/file-indexer.ts +280 -0
- package/src/input/index.ts +7 -0
- package/src/input/mention-enricher.test.ts +82 -0
- package/src/input/mention-enricher.ts +119 -0
- package/src/mcp/config-loader.test.ts +238 -0
- package/src/mcp/config-loader.ts +219 -0
- package/src/mcp/index.ts +26 -0
- package/src/mcp/manager.test.ts +106 -0
- package/src/mcp/manager.ts +262 -0
- package/src/mcp/types.ts +88 -0
- package/src/runtime/hook-file-hooks.test.ts +106 -0
- package/src/runtime/hook-file-hooks.ts +736 -0
- package/src/runtime/index.ts +27 -0
- package/src/runtime/rules.ts +34 -0
- package/src/runtime/runtime-builder.team-persistence.test.ts +203 -0
- package/src/runtime/runtime-builder.test.ts +215 -0
- package/src/runtime/runtime-builder.ts +515 -0
- package/src/runtime/runtime-parity.test.ts +132 -0
- package/src/runtime/sandbox/subprocess-sandbox.ts +207 -0
- package/src/runtime/session-runtime.ts +44 -0
- package/src/runtime/tool-approval.ts +104 -0
- package/src/runtime/workflows.test.ts +119 -0
- package/src/runtime/workflows.ts +54 -0
- package/src/server/index.ts +282 -0
- package/src/session/default-session-manager.e2e.test.ts +354 -0
- package/src/session/default-session-manager.test.ts +816 -0
- package/src/session/default-session-manager.ts +1286 -0
- package/src/session/index.ts +37 -0
- package/src/session/rpc-session-service.ts +189 -0
- package/src/session/runtime-oauth-token-manager.test.ts +137 -0
- package/src/session/runtime-oauth-token-manager.ts +265 -0
- package/src/session/session-artifacts.ts +106 -0
- package/src/session/session-graph.ts +90 -0
- package/src/session/session-host.ts +190 -0
- package/src/session/session-manager.ts +56 -0
- package/src/session/session-manifest.ts +29 -0
- package/src/session/session-service.team-persistence.test.ts +48 -0
- package/src/session/session-service.ts +610 -0
- package/src/session/sqlite-rpc-session-backend.ts +303 -0
- package/src/session/unified-session-persistence-service.ts +781 -0
- package/src/session/workspace-manager.ts +98 -0
- package/src/session/workspace-manifest.ts +100 -0
- package/src/storage/artifact-store.ts +1 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/provider-settings-legacy-migration.test.ts +175 -0
- package/src/storage/provider-settings-legacy-migration.ts +637 -0
- package/src/storage/provider-settings-manager.test.ts +111 -0
- package/src/storage/provider-settings-manager.ts +129 -0
- package/src/storage/session-store.ts +1 -0
- package/src/storage/sqlite-session-store.ts +270 -0
- package/src/storage/sqlite-team-store.ts +443 -0
- package/src/storage/team-store.ts +5 -0
- package/src/team/index.ts +4 -0
- package/src/team/projections.ts +285 -0
- package/src/types/common.ts +14 -0
- package/src/types/config.ts +64 -0
- package/src/types/events.ts +46 -0
- package/src/types/index.ts +24 -0
- package/src/types/provider-settings.ts +43 -0
- package/src/types/sessions.ts +16 -0
- package/src/types/storage.ts +64 -0
- package/src/types/workspace.ts +7 -0
- package/src/types.ts +127 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const ChatSessionConfigSchema = z.object({
|
|
4
|
+
workspaceRoot: z.string().min(1),
|
|
5
|
+
cwd: z.string().optional(),
|
|
6
|
+
provider: z.string().min(1),
|
|
7
|
+
model: z.string().min(1),
|
|
8
|
+
mode: z.enum(["act", "plan"]).default("act"),
|
|
9
|
+
apiKey: z.string(),
|
|
10
|
+
systemPrompt: z.string().optional(),
|
|
11
|
+
rules: z.string().optional(),
|
|
12
|
+
maxIterations: z.number().int().positive().optional(),
|
|
13
|
+
enableTools: z.boolean(),
|
|
14
|
+
enableSpawn: z.boolean(),
|
|
15
|
+
enableTeams: z.boolean(),
|
|
16
|
+
autoApproveTools: z.boolean().optional(),
|
|
17
|
+
teamName: z.string().min(1),
|
|
18
|
+
missionStepInterval: z.number().int().positive(),
|
|
19
|
+
missionTimeIntervalMs: z.number().int().positive(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const ChatSessionStatusSchema = z.enum([
|
|
23
|
+
"idle",
|
|
24
|
+
"starting",
|
|
25
|
+
"running",
|
|
26
|
+
"stopping",
|
|
27
|
+
"completed",
|
|
28
|
+
"cancelled",
|
|
29
|
+
"failed",
|
|
30
|
+
"error",
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
export const ChatMessageRoleSchema = z.enum([
|
|
34
|
+
"user",
|
|
35
|
+
"assistant",
|
|
36
|
+
"tool",
|
|
37
|
+
"system",
|
|
38
|
+
"status",
|
|
39
|
+
"error",
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
export const ChatMessageSchema = z.object({
|
|
43
|
+
id: z.string().min(1),
|
|
44
|
+
sessionId: z.string().nullable(),
|
|
45
|
+
role: ChatMessageRoleSchema,
|
|
46
|
+
content: z.string(),
|
|
47
|
+
createdAt: z.number().int().nonnegative(),
|
|
48
|
+
meta: z
|
|
49
|
+
.object({
|
|
50
|
+
stream: z.enum(["stdout", "stderr"]).optional(),
|
|
51
|
+
toolName: z.string().optional(),
|
|
52
|
+
iteration: z.number().int().nonnegative().optional(),
|
|
53
|
+
agentId: z.string().optional(),
|
|
54
|
+
conversationId: z.string().optional(),
|
|
55
|
+
hookEventName: z.string().optional(),
|
|
56
|
+
inputTokens: z.number().int().nonnegative().optional(),
|
|
57
|
+
outputTokens: z.number().int().nonnegative().optional(),
|
|
58
|
+
})
|
|
59
|
+
.optional(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const ChatSummarySchema = z.object({
|
|
63
|
+
toolCalls: z.number().int().nonnegative(),
|
|
64
|
+
tokensIn: z.number().int().nonnegative(),
|
|
65
|
+
tokensOut: z.number().int().nonnegative(),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export const ChatViewStateSchema = z.object({
|
|
69
|
+
sessionId: z.string().nullable(),
|
|
70
|
+
status: ChatSessionStatusSchema,
|
|
71
|
+
config: ChatSessionConfigSchema,
|
|
72
|
+
messages: z.array(ChatMessageSchema),
|
|
73
|
+
rawTranscript: z.string(),
|
|
74
|
+
error: z.string().nullable(),
|
|
75
|
+
summary: ChatSummarySchema,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export type ChatSessionConfig = z.infer<typeof ChatSessionConfigSchema>;
|
|
79
|
+
export type ChatSessionStatus = z.infer<typeof ChatSessionStatusSchema>;
|
|
80
|
+
export type ChatMessage = z.infer<typeof ChatMessageSchema>;
|
|
81
|
+
export type ChatSummary = z.infer<typeof ChatSummarySchema>;
|
|
82
|
+
export type ChatViewState = z.infer<typeof ChatViewStateSchema>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Default Tools
|
|
3
|
+
*
|
|
4
|
+
* Tool name constants and utility arrays.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { DefaultToolName } from "./types.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constants for default tool names
|
|
11
|
+
*/
|
|
12
|
+
export const DefaultToolNames = {
|
|
13
|
+
READ_FILES: "read_files",
|
|
14
|
+
SEARCH_CODEBASE: "search_codebase",
|
|
15
|
+
RUN_COMMANDS: "run_commands",
|
|
16
|
+
FETCH_WEB_CONTENT: "fetch_web_content",
|
|
17
|
+
APPLY_PATCH: "apply_patch",
|
|
18
|
+
EDITOR: "editor",
|
|
19
|
+
SKILLS: "skills",
|
|
20
|
+
ASK: "ask_question",
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Array of all default tool names
|
|
25
|
+
*/
|
|
26
|
+
export const ALL_DEFAULT_TOOL_NAMES: DefaultToolName[] = [
|
|
27
|
+
DefaultToolNames.READ_FILES,
|
|
28
|
+
DefaultToolNames.SEARCH_CODEBASE,
|
|
29
|
+
DefaultToolNames.RUN_COMMANDS,
|
|
30
|
+
DefaultToolNames.FETCH_WEB_CONTENT,
|
|
31
|
+
DefaultToolNames.APPLY_PATCH,
|
|
32
|
+
DefaultToolNames.EDITOR,
|
|
33
|
+
DefaultToolNames.SKILLS,
|
|
34
|
+
DefaultToolNames.ASK,
|
|
35
|
+
];
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createDefaultTools, createReadFilesTool } from "./definitions.js";
|
|
3
|
+
|
|
4
|
+
describe("default skills tool", () => {
|
|
5
|
+
it("is included only when enabled with a skills executor", () => {
|
|
6
|
+
const toolsWithoutExecutor = createDefaultTools({
|
|
7
|
+
executors: {},
|
|
8
|
+
enableSkills: true,
|
|
9
|
+
});
|
|
10
|
+
expect(toolsWithoutExecutor.map((tool) => tool.name)).not.toContain(
|
|
11
|
+
"skills",
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const toolsWithExecutor = createDefaultTools({
|
|
15
|
+
executors: {
|
|
16
|
+
skills: async () => "ok",
|
|
17
|
+
},
|
|
18
|
+
enableSkills: true,
|
|
19
|
+
});
|
|
20
|
+
expect(toolsWithExecutor.map((tool) => tool.name)).toContain("skills");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("validates and executes skill invocation input", async () => {
|
|
24
|
+
const execute = vi.fn(async () => "loaded");
|
|
25
|
+
const tools = createDefaultTools({
|
|
26
|
+
executors: {
|
|
27
|
+
skills: execute,
|
|
28
|
+
},
|
|
29
|
+
enableReadFiles: false,
|
|
30
|
+
enableSearch: false,
|
|
31
|
+
enableBash: false,
|
|
32
|
+
enableWebFetch: false,
|
|
33
|
+
enableEditor: false,
|
|
34
|
+
enableSkills: true,
|
|
35
|
+
});
|
|
36
|
+
const skillsTool = tools.find((tool) => tool.name === "skills");
|
|
37
|
+
expect(skillsTool).toBeDefined();
|
|
38
|
+
if (!skillsTool) {
|
|
39
|
+
throw new Error("Expected skills tool to be defined.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const result = await skillsTool.execute(
|
|
43
|
+
{ skill: "commit", args: "-m 'fix'" },
|
|
44
|
+
{
|
|
45
|
+
agentId: "agent-1",
|
|
46
|
+
conversationId: "conv-1",
|
|
47
|
+
iteration: 1,
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(result).toBe("loaded");
|
|
52
|
+
expect(execute).toHaveBeenCalledWith(
|
|
53
|
+
"commit",
|
|
54
|
+
"-m 'fix'",
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
agentId: "agent-1",
|
|
57
|
+
conversationId: "conv-1",
|
|
58
|
+
iteration: 1,
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("default ask_question tool", () => {
|
|
65
|
+
it("is enabled by default when executor is provided", () => {
|
|
66
|
+
const tools = createDefaultTools({
|
|
67
|
+
executors: {
|
|
68
|
+
askQuestion: async () => "ok",
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
expect(tools.map((tool) => tool.name)).toContain("ask_question");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("is excluded when explicitly disabled", () => {
|
|
75
|
+
const tools = createDefaultTools({
|
|
76
|
+
executors: {
|
|
77
|
+
askQuestion: async () => "ok",
|
|
78
|
+
},
|
|
79
|
+
enableAskQuestion: false,
|
|
80
|
+
});
|
|
81
|
+
expect(tools.map((tool) => tool.name)).not.toContain("ask_question");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("is included only when enabled with an askQuestion executor", () => {
|
|
85
|
+
const toolsWithoutExecutor = createDefaultTools({
|
|
86
|
+
executors: {},
|
|
87
|
+
enableAskQuestion: true,
|
|
88
|
+
});
|
|
89
|
+
expect(toolsWithoutExecutor.map((tool) => tool.name)).not.toContain(
|
|
90
|
+
"ask_question",
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const toolsWithExecutor = createDefaultTools({
|
|
94
|
+
executors: {
|
|
95
|
+
askQuestion: async () => "ok",
|
|
96
|
+
},
|
|
97
|
+
enableAskQuestion: true,
|
|
98
|
+
});
|
|
99
|
+
expect(toolsWithExecutor.map((tool) => tool.name)).toContain(
|
|
100
|
+
"ask_question",
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("validates and executes ask_question input", async () => {
|
|
105
|
+
const execute = vi.fn(async () => "asked");
|
|
106
|
+
const tools = createDefaultTools({
|
|
107
|
+
executors: {
|
|
108
|
+
askQuestion: execute,
|
|
109
|
+
},
|
|
110
|
+
enableReadFiles: false,
|
|
111
|
+
enableSearch: false,
|
|
112
|
+
enableBash: false,
|
|
113
|
+
enableWebFetch: false,
|
|
114
|
+
enableEditor: false,
|
|
115
|
+
enableSkills: false,
|
|
116
|
+
enableAskQuestion: true,
|
|
117
|
+
});
|
|
118
|
+
const askTool = tools.find((tool) => tool.name === "ask_question");
|
|
119
|
+
expect(askTool).toBeDefined();
|
|
120
|
+
if (!askTool) {
|
|
121
|
+
throw new Error("Expected ask_question tool to be defined.");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const result = await askTool.execute(
|
|
125
|
+
{
|
|
126
|
+
question: "Which approach should I take?",
|
|
127
|
+
options: ["Option 1", "Option 2"],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
agentId: "agent-1",
|
|
131
|
+
conversationId: "conv-1",
|
|
132
|
+
iteration: 1,
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(result).toBe("asked");
|
|
137
|
+
expect(execute).toHaveBeenCalledWith(
|
|
138
|
+
"Which approach should I take?",
|
|
139
|
+
["Option 1", "Option 2"],
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
agentId: "agent-1",
|
|
142
|
+
conversationId: "conv-1",
|
|
143
|
+
iteration: 1,
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("default apply_patch tool", () => {
|
|
150
|
+
it("is included only when enabled with an applyPatch executor", () => {
|
|
151
|
+
const toolsWithoutExecutor = createDefaultTools({
|
|
152
|
+
executors: {},
|
|
153
|
+
enableApplyPatch: true,
|
|
154
|
+
});
|
|
155
|
+
expect(toolsWithoutExecutor.map((tool) => tool.name)).not.toContain(
|
|
156
|
+
"apply_patch",
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const toolsWithExecutor = createDefaultTools({
|
|
160
|
+
executors: {
|
|
161
|
+
applyPatch: async () => "ok",
|
|
162
|
+
},
|
|
163
|
+
enableApplyPatch: true,
|
|
164
|
+
});
|
|
165
|
+
expect(toolsWithExecutor.map((tool) => tool.name)).toContain("apply_patch");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("validates and executes apply_patch input", async () => {
|
|
169
|
+
const execute = vi.fn(async () => "patched");
|
|
170
|
+
const tools = createDefaultTools({
|
|
171
|
+
executors: {
|
|
172
|
+
applyPatch: execute,
|
|
173
|
+
},
|
|
174
|
+
enableReadFiles: false,
|
|
175
|
+
enableSearch: false,
|
|
176
|
+
enableBash: false,
|
|
177
|
+
enableWebFetch: false,
|
|
178
|
+
enableEditor: false,
|
|
179
|
+
enableSkills: false,
|
|
180
|
+
enableAskQuestion: false,
|
|
181
|
+
enableApplyPatch: true,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const applyPatchTool = tools.find((tool) => tool.name === "apply_patch");
|
|
185
|
+
expect(applyPatchTool).toBeDefined();
|
|
186
|
+
if (!applyPatchTool) {
|
|
187
|
+
throw new Error("Expected apply_patch tool to be defined.");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const result = await applyPatchTool.execute(
|
|
191
|
+
{ input: "*** Begin Patch\n*** End Patch" },
|
|
192
|
+
{
|
|
193
|
+
agentId: "agent-1",
|
|
194
|
+
conversationId: "conv-1",
|
|
195
|
+
iteration: 1,
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect(result).toEqual({
|
|
200
|
+
query: "apply_patch",
|
|
201
|
+
result: "patched",
|
|
202
|
+
success: true,
|
|
203
|
+
});
|
|
204
|
+
expect(execute).toHaveBeenCalledWith(
|
|
205
|
+
{ input: "*** Begin Patch\n*** End Patch" },
|
|
206
|
+
process.cwd(),
|
|
207
|
+
expect.objectContaining({
|
|
208
|
+
agentId: "agent-1",
|
|
209
|
+
conversationId: "conv-1",
|
|
210
|
+
iteration: 1,
|
|
211
|
+
}),
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("zod schema conversion", () => {
|
|
217
|
+
it("preserves read_files required properties in generated JSON schema", () => {
|
|
218
|
+
const tool = createReadFilesTool(async () => "ok");
|
|
219
|
+
const inputSchema = tool.inputSchema as Record<string, unknown>;
|
|
220
|
+
const properties = inputSchema.properties as Record<string, unknown>;
|
|
221
|
+
expect(inputSchema.type).toBe("object");
|
|
222
|
+
expect(properties.file_paths).toEqual({
|
|
223
|
+
type: "array",
|
|
224
|
+
items: {
|
|
225
|
+
type: "string",
|
|
226
|
+
description:
|
|
227
|
+
"The absolute file path of a text file to read content from",
|
|
228
|
+
},
|
|
229
|
+
description: "Array of absolute file paths",
|
|
230
|
+
});
|
|
231
|
+
expect(inputSchema.required).toEqual(["file_paths"]);
|
|
232
|
+
});
|
|
233
|
+
});
|