@clinebot/core 0.0.22 → 0.0.23

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.
Files changed (260) hide show
  1. package/dist/ClineCore.d.ts +110 -0
  2. package/dist/ClineCore.d.ts.map +1 -0
  3. package/dist/account/cline-account-service.d.ts +2 -1
  4. package/dist/account/cline-account-service.d.ts.map +1 -1
  5. package/dist/account/index.d.ts +1 -1
  6. package/dist/account/index.d.ts.map +1 -1
  7. package/dist/account/rpc.d.ts +3 -1
  8. package/dist/account/rpc.d.ts.map +1 -1
  9. package/dist/account/types.d.ts +3 -0
  10. package/dist/account/types.d.ts.map +1 -1
  11. package/dist/agents/plugin-loader.d.ts.map +1 -1
  12. package/dist/agents/plugin-sandbox-bootstrap.js +17 -17
  13. package/dist/auth/client.d.ts +1 -1
  14. package/dist/auth/client.d.ts.map +1 -1
  15. package/dist/auth/cline.d.ts +1 -1
  16. package/dist/auth/cline.d.ts.map +1 -1
  17. package/dist/auth/codex.d.ts +1 -1
  18. package/dist/auth/codex.d.ts.map +1 -1
  19. package/dist/auth/oca.d.ts +1 -1
  20. package/dist/auth/oca.d.ts.map +1 -1
  21. package/dist/auth/utils.d.ts +2 -2
  22. package/dist/auth/utils.d.ts.map +1 -1
  23. package/dist/index.d.ts +50 -5
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +949 -0
  26. package/dist/providers/local-provider-service.d.ts +4 -4
  27. package/dist/providers/local-provider-service.d.ts.map +1 -1
  28. package/dist/runtime/runtime-builder.d.ts +1 -0
  29. package/dist/runtime/runtime-builder.d.ts.map +1 -1
  30. package/dist/runtime/session-runtime.d.ts +2 -1
  31. package/dist/runtime/session-runtime.d.ts.map +1 -1
  32. package/dist/runtime/team-runtime-registry.d.ts +13 -0
  33. package/dist/runtime/team-runtime-registry.d.ts.map +1 -0
  34. package/dist/session/default-session-manager.d.ts +2 -2
  35. package/dist/session/default-session-manager.d.ts.map +1 -1
  36. package/dist/session/rpc-runtime-ensure.d.ts +53 -0
  37. package/dist/session/rpc-runtime-ensure.d.ts.map +1 -0
  38. package/dist/session/session-config-builder.d.ts +2 -3
  39. package/dist/session/session-config-builder.d.ts.map +1 -1
  40. package/dist/session/session-host.d.ts +8 -18
  41. package/dist/session/session-host.d.ts.map +1 -1
  42. package/dist/session/session-manager.d.ts +1 -1
  43. package/dist/session/session-manager.d.ts.map +1 -1
  44. package/dist/session/session-manifest.d.ts +1 -2
  45. package/dist/session/session-manifest.d.ts.map +1 -1
  46. package/dist/session/unified-session-persistence-service.d.ts +2 -2
  47. package/dist/session/unified-session-persistence-service.d.ts.map +1 -1
  48. package/dist/session/utils/helpers.d.ts +1 -1
  49. package/dist/session/utils/helpers.d.ts.map +1 -1
  50. package/dist/session/utils/types.d.ts +1 -1
  51. package/dist/session/utils/types.d.ts.map +1 -1
  52. package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -1
  53. package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -1
  54. package/dist/telemetry/distinct-id.d.ts +2 -0
  55. package/dist/telemetry/distinct-id.d.ts.map +1 -0
  56. package/dist/telemetry/{opentelemetry.d.ts → index.d.ts} +1 -1
  57. package/dist/telemetry/index.d.ts.map +1 -0
  58. package/dist/telemetry/index.js +28 -0
  59. package/dist/tools/constants.d.ts +1 -1
  60. package/dist/tools/constants.d.ts.map +1 -1
  61. package/dist/tools/definitions.d.ts +3 -3
  62. package/dist/tools/definitions.d.ts.map +1 -1
  63. package/dist/tools/executors/apply-patch.d.ts +1 -1
  64. package/dist/tools/executors/apply-patch.d.ts.map +1 -1
  65. package/dist/tools/executors/bash.d.ts +1 -1
  66. package/dist/tools/executors/bash.d.ts.map +1 -1
  67. package/dist/tools/executors/editor.d.ts +1 -1
  68. package/dist/tools/executors/editor.d.ts.map +1 -1
  69. package/dist/tools/executors/file-read.d.ts +1 -1
  70. package/dist/tools/executors/file-read.d.ts.map +1 -1
  71. package/dist/tools/executors/index.d.ts +14 -14
  72. package/dist/tools/executors/index.d.ts.map +1 -1
  73. package/dist/tools/executors/search.d.ts +1 -1
  74. package/dist/tools/executors/search.d.ts.map +1 -1
  75. package/dist/tools/executors/web-fetch.d.ts +1 -1
  76. package/dist/tools/executors/web-fetch.d.ts.map +1 -1
  77. package/dist/tools/helpers.d.ts +1 -1
  78. package/dist/tools/helpers.d.ts.map +1 -1
  79. package/dist/tools/index.d.ts +10 -10
  80. package/dist/tools/index.d.ts.map +1 -1
  81. package/dist/tools/model-tool-routing.d.ts +1 -1
  82. package/dist/tools/model-tool-routing.d.ts.map +1 -1
  83. package/dist/tools/presets.d.ts +1 -1
  84. package/dist/tools/presets.d.ts.map +1 -1
  85. package/dist/types/common.d.ts +17 -8
  86. package/dist/types/common.d.ts.map +1 -1
  87. package/dist/types/config.d.ts +4 -3
  88. package/dist/types/config.d.ts.map +1 -1
  89. package/dist/types/provider-settings.d.ts +1 -1
  90. package/dist/types/provider-settings.d.ts.map +1 -1
  91. package/dist/types.d.ts +5 -2
  92. package/dist/types.d.ts.map +1 -1
  93. package/dist/version.d.ts +2 -0
  94. package/dist/version.d.ts.map +1 -0
  95. package/package.json +44 -38
  96. package/src/ClineCore.ts +137 -0
  97. package/src/account/cline-account-service.test.ts +101 -0
  98. package/src/account/cline-account-service.ts +300 -0
  99. package/src/account/featurebase-token.test.ts +175 -0
  100. package/src/account/index.ts +23 -0
  101. package/src/account/rpc.test.ts +63 -0
  102. package/src/account/rpc.ts +185 -0
  103. package/src/account/types.ts +102 -0
  104. package/src/agents/agent-config-loader.test.ts +236 -0
  105. package/src/agents/agent-config-loader.ts +108 -0
  106. package/src/agents/agent-config-parser.ts +198 -0
  107. package/src/agents/hooks-config-loader.test.ts +20 -0
  108. package/src/agents/hooks-config-loader.ts +118 -0
  109. package/src/agents/index.ts +85 -0
  110. package/src/agents/plugin-config-loader.test.ts +140 -0
  111. package/src/agents/plugin-config-loader.ts +97 -0
  112. package/src/agents/plugin-loader.test.ts +210 -0
  113. package/src/agents/plugin-loader.ts +175 -0
  114. package/src/agents/plugin-sandbox-bootstrap.ts +448 -0
  115. package/src/agents/plugin-sandbox.test.ts +296 -0
  116. package/src/agents/plugin-sandbox.ts +341 -0
  117. package/src/agents/unified-config-file-watcher.test.ts +196 -0
  118. package/src/agents/unified-config-file-watcher.ts +483 -0
  119. package/src/agents/user-instruction-config-loader.test.ts +158 -0
  120. package/src/agents/user-instruction-config-loader.ts +438 -0
  121. package/src/auth/client.test.ts +40 -0
  122. package/src/auth/client.ts +25 -0
  123. package/src/auth/cline.test.ts +130 -0
  124. package/src/auth/cline.ts +420 -0
  125. package/src/auth/codex.test.ts +170 -0
  126. package/src/auth/codex.ts +491 -0
  127. package/src/auth/oca.test.ts +215 -0
  128. package/src/auth/oca.ts +573 -0
  129. package/src/auth/server.ts +216 -0
  130. package/src/auth/types.ts +81 -0
  131. package/src/auth/utils.test.ts +128 -0
  132. package/src/auth/utils.ts +247 -0
  133. package/src/chat/chat-schema.ts +82 -0
  134. package/src/index.ts +479 -0
  135. package/src/input/file-indexer.d.ts +11 -0
  136. package/src/input/file-indexer.test.ts +127 -0
  137. package/src/input/file-indexer.ts +327 -0
  138. package/src/input/index.ts +7 -0
  139. package/src/input/mention-enricher.test.ts +85 -0
  140. package/src/input/mention-enricher.ts +122 -0
  141. package/src/mcp/config-loader.test.ts +238 -0
  142. package/src/mcp/config-loader.ts +219 -0
  143. package/src/mcp/index.ts +26 -0
  144. package/src/mcp/manager.test.ts +106 -0
  145. package/src/mcp/manager.ts +262 -0
  146. package/src/mcp/types.ts +88 -0
  147. package/src/providers/local-provider-registry.ts +232 -0
  148. package/src/providers/local-provider-service.test.ts +783 -0
  149. package/src/providers/local-provider-service.ts +471 -0
  150. package/src/runtime/commands.test.ts +98 -0
  151. package/src/runtime/commands.ts +83 -0
  152. package/src/runtime/hook-file-hooks.test.ts +237 -0
  153. package/src/runtime/hook-file-hooks.ts +859 -0
  154. package/src/runtime/index.ts +37 -0
  155. package/src/runtime/rules.ts +34 -0
  156. package/src/runtime/runtime-builder.team-persistence.test.ts +245 -0
  157. package/src/runtime/runtime-builder.test.ts +371 -0
  158. package/src/runtime/runtime-builder.ts +631 -0
  159. package/src/runtime/runtime-parity.test.ts +143 -0
  160. package/src/runtime/sandbox/subprocess-sandbox.ts +231 -0
  161. package/src/runtime/session-runtime.ts +49 -0
  162. package/src/runtime/skills.ts +44 -0
  163. package/src/runtime/team-runtime-registry.ts +46 -0
  164. package/src/runtime/tool-approval.ts +104 -0
  165. package/src/runtime/workflows.test.ts +119 -0
  166. package/src/runtime/workflows.ts +45 -0
  167. package/src/session/default-session-manager.e2e.test.ts +384 -0
  168. package/src/session/default-session-manager.test.ts +1931 -0
  169. package/src/session/default-session-manager.ts +1422 -0
  170. package/src/session/file-session-service.ts +280 -0
  171. package/src/session/index.ts +45 -0
  172. package/src/session/rpc-runtime-ensure.ts +521 -0
  173. package/src/session/rpc-session-service.ts +107 -0
  174. package/src/session/rpc-spawn-lease.test.ts +49 -0
  175. package/src/session/rpc-spawn-lease.ts +122 -0
  176. package/src/session/runtime-oauth-token-manager.test.ts +137 -0
  177. package/src/session/runtime-oauth-token-manager.ts +272 -0
  178. package/src/session/session-agent-events.ts +248 -0
  179. package/src/session/session-artifacts.ts +106 -0
  180. package/src/session/session-config-builder.ts +113 -0
  181. package/src/session/session-graph.ts +92 -0
  182. package/src/session/session-host.test.ts +89 -0
  183. package/src/session/session-host.ts +205 -0
  184. package/src/session/session-manager.ts +69 -0
  185. package/src/session/session-manifest.ts +29 -0
  186. package/src/session/session-service.team-persistence.test.ts +48 -0
  187. package/src/session/session-service.ts +673 -0
  188. package/src/session/session-team-coordination.ts +229 -0
  189. package/src/session/session-telemetry.ts +100 -0
  190. package/src/session/sqlite-rpc-session-backend.ts +303 -0
  191. package/src/session/unified-session-persistence-service.test.ts +85 -0
  192. package/src/session/unified-session-persistence-service.ts +994 -0
  193. package/src/session/utils/helpers.ts +139 -0
  194. package/src/session/utils/types.ts +57 -0
  195. package/src/session/utils/usage.ts +32 -0
  196. package/src/session/workspace-manager.ts +98 -0
  197. package/src/session/workspace-manifest.ts +100 -0
  198. package/src/storage/artifact-store.ts +1 -0
  199. package/src/storage/file-team-store.ts +257 -0
  200. package/src/storage/index.ts +11 -0
  201. package/src/storage/provider-settings-legacy-migration.test.ts +424 -0
  202. package/src/storage/provider-settings-legacy-migration.ts +826 -0
  203. package/src/storage/provider-settings-manager.test.ts +191 -0
  204. package/src/storage/provider-settings-manager.ts +152 -0
  205. package/src/storage/session-store.ts +1 -0
  206. package/src/storage/sqlite-session-store.ts +275 -0
  207. package/src/storage/sqlite-team-store.ts +454 -0
  208. package/src/storage/team-store.ts +40 -0
  209. package/src/team/index.ts +4 -0
  210. package/src/team/projections.ts +285 -0
  211. package/src/telemetry/ITelemetryAdapter.ts +94 -0
  212. package/src/telemetry/LoggerTelemetryAdapter.test.ts +42 -0
  213. package/src/telemetry/LoggerTelemetryAdapter.ts +114 -0
  214. package/src/telemetry/OpenTelemetryAdapter.test.ts +157 -0
  215. package/src/telemetry/OpenTelemetryAdapter.ts +348 -0
  216. package/src/telemetry/OpenTelemetryProvider.test.ts +113 -0
  217. package/src/telemetry/OpenTelemetryProvider.ts +325 -0
  218. package/src/telemetry/TelemetryService.test.ts +134 -0
  219. package/src/telemetry/TelemetryService.ts +141 -0
  220. package/src/telemetry/core-events.ts +400 -0
  221. package/src/telemetry/distinct-id.test.ts +57 -0
  222. package/src/telemetry/distinct-id.ts +58 -0
  223. package/src/telemetry/index.ts +20 -0
  224. package/src/tools/constants.ts +35 -0
  225. package/src/tools/definitions.test.ts +704 -0
  226. package/src/tools/definitions.ts +709 -0
  227. package/src/tools/executors/apply-patch-parser.ts +520 -0
  228. package/src/tools/executors/apply-patch.ts +359 -0
  229. package/src/tools/executors/bash.test.ts +87 -0
  230. package/src/tools/executors/bash.ts +207 -0
  231. package/src/tools/executors/editor.test.ts +35 -0
  232. package/src/tools/executors/editor.ts +219 -0
  233. package/src/tools/executors/file-read.test.ts +49 -0
  234. package/src/tools/executors/file-read.ts +110 -0
  235. package/src/tools/executors/index.ts +87 -0
  236. package/src/tools/executors/search.ts +278 -0
  237. package/src/tools/executors/web-fetch.ts +259 -0
  238. package/src/tools/helpers.ts +130 -0
  239. package/src/tools/index.ts +169 -0
  240. package/src/tools/model-tool-routing.test.ts +86 -0
  241. package/src/tools/model-tool-routing.ts +132 -0
  242. package/src/tools/presets.test.ts +62 -0
  243. package/src/tools/presets.ts +168 -0
  244. package/src/tools/schemas.ts +327 -0
  245. package/src/tools/types.ts +329 -0
  246. package/src/types/common.ts +26 -0
  247. package/src/types/config.ts +86 -0
  248. package/src/types/events.ts +74 -0
  249. package/src/types/index.ts +24 -0
  250. package/src/types/provider-settings.ts +43 -0
  251. package/src/types/sessions.ts +16 -0
  252. package/src/types/storage.ts +64 -0
  253. package/src/types/workspace.ts +7 -0
  254. package/src/types.ts +132 -0
  255. package/src/version.ts +3 -0
  256. package/dist/index.node.d.ts +0 -47
  257. package/dist/index.node.d.ts.map +0 -1
  258. package/dist/index.node.js +0 -948
  259. package/dist/telemetry/opentelemetry.d.ts.map +0 -1
  260. package/dist/telemetry/opentelemetry.js +0 -27
@@ -0,0 +1,704 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import {
3
+ createDefaultTools,
4
+ createReadFilesTool,
5
+ createSkillsTool,
6
+ createWindowsShellTool,
7
+ } from "./definitions";
8
+ import { INPUT_ARG_CHAR_LIMIT } from "./schemas";
9
+ import type { SkillsExecutorWithMetadata } from "./types";
10
+
11
+ function createMockSkillsExecutor(
12
+ fn: (...args: unknown[]) => Promise<string> = async () => "ok",
13
+ configuredSkills?: SkillsExecutorWithMetadata["configuredSkills"],
14
+ ): SkillsExecutorWithMetadata {
15
+ const executor = fn as SkillsExecutorWithMetadata;
16
+ executor.configuredSkills = configuredSkills;
17
+ return executor;
18
+ }
19
+
20
+ describe("default skills tool", () => {
21
+ it("is included only when enabled with a skills executor", () => {
22
+ const toolsWithoutExecutor = createDefaultTools({
23
+ executors: {},
24
+ enableSkills: true,
25
+ });
26
+ expect(toolsWithoutExecutor.map((tool) => tool.name)).not.toContain(
27
+ "skills",
28
+ );
29
+
30
+ const toolsWithExecutor = createDefaultTools({
31
+ executors: {
32
+ skills: createMockSkillsExecutor(),
33
+ },
34
+ enableSkills: true,
35
+ });
36
+ expect(toolsWithExecutor.map((tool) => tool.name)).toContain("skills");
37
+ });
38
+
39
+ it("includes configured skill names in description", () => {
40
+ const executor = createMockSkillsExecutor(
41
+ async () => "ok",
42
+ [
43
+ { id: "commit", name: "commit", disabled: false },
44
+ {
45
+ id: "review-pr",
46
+ name: "review-pr",
47
+ description: "Review a PR",
48
+ disabled: false,
49
+ },
50
+ { id: "disabled-skill", name: "disabled-skill", disabled: true },
51
+ ],
52
+ );
53
+ const tool = createSkillsTool(executor);
54
+ expect(tool.description).toContain("Available skills: commit, review-pr.");
55
+ expect(tool.description).not.toContain("disabled-skill");
56
+ });
57
+
58
+ it("omits skill list from description when no skills are configured", () => {
59
+ const executor = createMockSkillsExecutor(async () => "ok");
60
+ const tool = createSkillsTool(executor);
61
+ expect(tool.description).not.toContain("Available skills");
62
+ });
63
+
64
+ it("validates and executes skill invocation input", async () => {
65
+ const execute = vi.fn(async () => "loaded");
66
+ const tools = createDefaultTools({
67
+ executors: {
68
+ skills: createMockSkillsExecutor(execute),
69
+ },
70
+ enableReadFiles: false,
71
+ enableSearch: false,
72
+ enableBash: false,
73
+ enableWebFetch: false,
74
+ enableEditor: false,
75
+ enableSkills: true,
76
+ });
77
+ const skillsTool = tools.find((tool) => tool.name === "skills");
78
+ expect(skillsTool).toBeDefined();
79
+ if (!skillsTool) {
80
+ throw new Error("Expected skills tool to be defined.");
81
+ }
82
+
83
+ const result = await skillsTool.execute(
84
+ { skill: "commit", args: "-m 'fix'" },
85
+ {
86
+ agentId: "agent-1",
87
+ conversationId: "conv-1",
88
+ iteration: 1,
89
+ },
90
+ );
91
+
92
+ expect(result).toBe("loaded");
93
+ expect(execute).toHaveBeenCalledWith(
94
+ "commit",
95
+ "-m 'fix'",
96
+ expect.objectContaining({
97
+ agentId: "agent-1",
98
+ conversationId: "conv-1",
99
+ iteration: 1,
100
+ }),
101
+ );
102
+ });
103
+ });
104
+
105
+ describe("default ask_question tool", () => {
106
+ it("is enabled by default when executor is provided", () => {
107
+ const tools = createDefaultTools({
108
+ executors: {
109
+ askQuestion: async () => "ok",
110
+ },
111
+ });
112
+ expect(tools.map((tool) => tool.name)).toContain("ask_question");
113
+ });
114
+
115
+ it("is excluded when explicitly disabled", () => {
116
+ const tools = createDefaultTools({
117
+ executors: {
118
+ askQuestion: async () => "ok",
119
+ },
120
+ enableAskQuestion: false,
121
+ });
122
+ expect(tools.map((tool) => tool.name)).not.toContain("ask_question");
123
+ });
124
+
125
+ it("is included only when enabled with an askQuestion executor", () => {
126
+ const toolsWithoutExecutor = createDefaultTools({
127
+ executors: {},
128
+ enableAskQuestion: true,
129
+ });
130
+ expect(toolsWithoutExecutor.map((tool) => tool.name)).not.toContain(
131
+ "ask_question",
132
+ );
133
+
134
+ const toolsWithExecutor = createDefaultTools({
135
+ executors: {
136
+ askQuestion: async () => "ok",
137
+ },
138
+ enableAskQuestion: true,
139
+ });
140
+ expect(toolsWithExecutor.map((tool) => tool.name)).toContain(
141
+ "ask_question",
142
+ );
143
+ });
144
+
145
+ it("validates and executes ask_question input", async () => {
146
+ const execute = vi.fn(async () => "asked");
147
+ const tools = createDefaultTools({
148
+ executors: {
149
+ askQuestion: execute,
150
+ },
151
+ enableReadFiles: false,
152
+ enableSearch: false,
153
+ enableBash: false,
154
+ enableWebFetch: false,
155
+ enableEditor: false,
156
+ enableSkills: false,
157
+ enableAskQuestion: true,
158
+ });
159
+ const askTool = tools.find((tool) => tool.name === "ask_question");
160
+ expect(askTool).toBeDefined();
161
+ if (!askTool) {
162
+ throw new Error("Expected ask_question tool to be defined.");
163
+ }
164
+
165
+ const result = await askTool.execute(
166
+ {
167
+ question: "Which approach should I take?",
168
+ options: ["Option 1", "Option 2"],
169
+ },
170
+ {
171
+ agentId: "agent-1",
172
+ conversationId: "conv-1",
173
+ iteration: 1,
174
+ },
175
+ );
176
+
177
+ expect(result).toBe("asked");
178
+ expect(execute).toHaveBeenCalledWith(
179
+ "Which approach should I take?",
180
+ ["Option 1", "Option 2"],
181
+ expect.objectContaining({
182
+ agentId: "agent-1",
183
+ conversationId: "conv-1",
184
+ iteration: 1,
185
+ }),
186
+ );
187
+ });
188
+ });
189
+
190
+ describe("default apply_patch tool", () => {
191
+ it("is included only when enabled with an applyPatch executor", () => {
192
+ const toolsWithoutExecutor = createDefaultTools({
193
+ executors: {},
194
+ enableApplyPatch: true,
195
+ });
196
+ expect(toolsWithoutExecutor.map((tool) => tool.name)).not.toContain(
197
+ "apply_patch",
198
+ );
199
+
200
+ const toolsWithExecutor = createDefaultTools({
201
+ executors: {
202
+ applyPatch: async () => "ok",
203
+ },
204
+ enableApplyPatch: true,
205
+ });
206
+ expect(toolsWithExecutor.map((tool) => tool.name)).toContain("apply_patch");
207
+ });
208
+
209
+ it("validates and executes apply_patch input", async () => {
210
+ const execute = vi.fn(async () => "patched");
211
+ const tools = createDefaultTools({
212
+ executors: {
213
+ applyPatch: execute,
214
+ },
215
+ enableReadFiles: false,
216
+ enableSearch: false,
217
+ enableBash: false,
218
+ enableWebFetch: false,
219
+ enableEditor: false,
220
+ enableSkills: false,
221
+ enableAskQuestion: false,
222
+ enableApplyPatch: true,
223
+ });
224
+
225
+ const applyPatchTool = tools.find((tool) => tool.name === "apply_patch");
226
+ expect(applyPatchTool).toBeDefined();
227
+ if (!applyPatchTool) {
228
+ throw new Error("Expected apply_patch tool to be defined.");
229
+ }
230
+
231
+ const result = await applyPatchTool.execute(
232
+ { input: "*** Begin Patch\n*** End Patch" },
233
+ {
234
+ agentId: "agent-1",
235
+ conversationId: "conv-1",
236
+ iteration: 1,
237
+ },
238
+ );
239
+
240
+ expect(result).toEqual({
241
+ query: "apply_patch",
242
+ result: "patched",
243
+ success: true,
244
+ });
245
+ expect(execute).toHaveBeenCalledWith(
246
+ { input: "*** Begin Patch\n*** End Patch" },
247
+ process.cwd(),
248
+ expect.objectContaining({
249
+ agentId: "agent-1",
250
+ conversationId: "conv-1",
251
+ iteration: 1,
252
+ }),
253
+ );
254
+ });
255
+ });
256
+
257
+ describe("default run_commands tool", () => {
258
+ it("accepts object input with commands as a single string", async () => {
259
+ const execute = vi.fn(async (command: string | { command: string }) =>
260
+ typeof command === "string" ? `ran:${command}` : `ran:${command.command}`,
261
+ );
262
+ const tool = createWindowsShellTool(execute);
263
+
264
+ const result = await tool.execute({ commands: "ls" } as never, {
265
+ agentId: "agent-1",
266
+ conversationId: "conv-1",
267
+ iteration: 1,
268
+ });
269
+
270
+ expect(result).toEqual([
271
+ {
272
+ query: "ls",
273
+ result: "ran:ls",
274
+ success: true,
275
+ },
276
+ ]);
277
+ expect(execute).toHaveBeenCalledTimes(1);
278
+ expect(execute).toHaveBeenCalledWith(
279
+ "ls",
280
+ process.cwd(),
281
+ expect.objectContaining({
282
+ agentId: "agent-1",
283
+ conversationId: "conv-1",
284
+ iteration: 1,
285
+ }),
286
+ );
287
+ });
288
+
289
+ it("accepts structured commands and preserves argv", async () => {
290
+ const execute = vi.fn(
291
+ async (command: string | { command: string; args?: string[] }) =>
292
+ typeof command === "string"
293
+ ? `ran:${command}`
294
+ : `ran:${command.command}:${(command.args ?? []).join(",")}`,
295
+ );
296
+ const tool = createWindowsShellTool(execute);
297
+
298
+ const result = await tool.execute(
299
+ {
300
+ commands: {
301
+ command: "node",
302
+ args: ["-e", "console.log('ok')"],
303
+ },
304
+ } as never,
305
+ {
306
+ agentId: "agent-1",
307
+ conversationId: "conv-1",
308
+ iteration: 1,
309
+ },
310
+ );
311
+
312
+ expect(result).toEqual([
313
+ {
314
+ query: "node -e console.log('ok')",
315
+ result: "ran:node:-e,console.log('ok')",
316
+ success: true,
317
+ },
318
+ ]);
319
+ expect(execute).toHaveBeenCalledWith(
320
+ {
321
+ command: "node",
322
+ args: ["-e", "console.log('ok')"],
323
+ },
324
+ process.cwd(),
325
+ expect.objectContaining({
326
+ agentId: "agent-1",
327
+ conversationId: "conv-1",
328
+ iteration: 1,
329
+ }),
330
+ );
331
+ });
332
+ });
333
+
334
+ describe("default read_files tool", () => {
335
+ it("normalizes ranged file requests and passes them to the executor", async () => {
336
+ const execute = vi.fn(async () => "selected lines");
337
+ const tool = createReadFilesTool(execute);
338
+
339
+ const result = await tool.execute(
340
+ {
341
+ files: [
342
+ {
343
+ path: "/tmp/example.ts",
344
+ start_line: 3,
345
+ end_line: 5,
346
+ },
347
+ ],
348
+ },
349
+ {
350
+ agentId: "agent-1",
351
+ conversationId: "conv-1",
352
+ iteration: 1,
353
+ },
354
+ );
355
+
356
+ expect(result).toEqual([
357
+ {
358
+ query: "/tmp/example.ts:3-5",
359
+ result: "selected lines",
360
+ success: true,
361
+ },
362
+ ]);
363
+ expect(execute).toHaveBeenCalledWith(
364
+ {
365
+ path: "/tmp/example.ts",
366
+ start_line: 3,
367
+ end_line: 5,
368
+ },
369
+ expect.objectContaining({
370
+ agentId: "agent-1",
371
+ conversationId: "conv-1",
372
+ iteration: 1,
373
+ }),
374
+ );
375
+ });
376
+
377
+ it("keeps legacy string inputs reading full file content", async () => {
378
+ const execute = vi.fn(async () => "full file");
379
+ const tool = createReadFilesTool(execute);
380
+
381
+ await tool.execute("/tmp/example.ts" as never, {
382
+ agentId: "agent-1",
383
+ conversationId: "conv-1",
384
+ iteration: 1,
385
+ });
386
+
387
+ expect(execute).toHaveBeenCalledWith(
388
+ { path: "/tmp/example.ts" },
389
+ expect.objectContaining({
390
+ agentId: "agent-1",
391
+ conversationId: "conv-1",
392
+ iteration: 1,
393
+ }),
394
+ );
395
+ });
396
+
397
+ it("treats null line bounds as full-file boundaries", async () => {
398
+ const execute = vi.fn(async () => "full file");
399
+ const tool = createReadFilesTool(execute);
400
+
401
+ const result = await tool.execute(
402
+ {
403
+ files: [
404
+ {
405
+ path: "/tmp/example.ts",
406
+ start_line: null,
407
+ end_line: null,
408
+ },
409
+ ],
410
+ },
411
+ {
412
+ agentId: "agent-1",
413
+ conversationId: "conv-1",
414
+ iteration: 1,
415
+ },
416
+ );
417
+
418
+ expect(result).toEqual([
419
+ {
420
+ query: "/tmp/example.ts",
421
+ result: "full file",
422
+ success: true,
423
+ },
424
+ ]);
425
+ expect(execute).toHaveBeenCalledWith(
426
+ {
427
+ path: "/tmp/example.ts",
428
+ start_line: null,
429
+ end_line: null,
430
+ },
431
+ expect.objectContaining({
432
+ agentId: "agent-1",
433
+ conversationId: "conv-1",
434
+ iteration: 1,
435
+ }),
436
+ );
437
+ });
438
+ });
439
+
440
+ describe("zod schema conversion", () => {
441
+ it("preserves read_files required properties in generated JSON schema", () => {
442
+ const tool = createReadFilesTool(async () => "ok");
443
+ const inputSchema = tool.inputSchema as Record<string, unknown>;
444
+ const properties = inputSchema.properties as Record<string, unknown>;
445
+ expect(inputSchema.type).toBe("object");
446
+ expect(properties.files).toMatchObject({
447
+ type: "array",
448
+ items: {
449
+ type: "object",
450
+ properties: {
451
+ path: {
452
+ type: "string",
453
+ description:
454
+ "The absolute file path of a text file to read content from",
455
+ },
456
+ start_line: {
457
+ anyOf: [{ type: "integer" }, { type: "null" }],
458
+ description:
459
+ "Optional one-based starting line number to read from; use null or omit for the start of the file",
460
+ },
461
+ end_line: {
462
+ anyOf: [{ type: "integer" }, { type: "null" }],
463
+ description:
464
+ "Optional one-based ending line number to read through; use null or omit for the end of the file",
465
+ },
466
+ },
467
+ required: ["path"],
468
+ },
469
+ description:
470
+ "Array of file read requests. Omit start_line/end_line or set them to null to return the full file content boundaries; provide integers to return only that inclusive one-based line range. Prefer this tool over running terminal command to get file content for better performance and reliability.",
471
+ });
472
+ expect(inputSchema.required).toEqual(["files"]);
473
+ });
474
+
475
+ it("exposes skills args as optional nullable in tool schemas", () => {
476
+ const tools = createDefaultTools({
477
+ executors: {
478
+ skills: createMockSkillsExecutor(),
479
+ },
480
+ enableReadFiles: false,
481
+ enableSearch: false,
482
+ enableBash: false,
483
+ enableWebFetch: false,
484
+ enableEditor: false,
485
+ enableApplyPatch: false,
486
+ enableAskQuestion: false,
487
+ enableSkills: true,
488
+ });
489
+ const skills = tools.find((tool) => tool.name === "skills");
490
+ expect(skills).toBeDefined();
491
+ if (!skills) {
492
+ throw new Error("Expected skills tool.");
493
+ }
494
+ const schema = skills.inputSchema as {
495
+ required?: string[];
496
+ properties?: Record<string, unknown>;
497
+ };
498
+ expect(schema.required).toEqual(["skill"]);
499
+ expect(schema.properties).toHaveProperty("args");
500
+ });
501
+ });
502
+
503
+ describe("default editor tool", () => {
504
+ it("accepts replacement edits without insert fields", async () => {
505
+ const execute = vi.fn(async () => "patched");
506
+ const tools = createDefaultTools({
507
+ executors: {
508
+ editor: execute,
509
+ },
510
+ enableReadFiles: false,
511
+ enableSearch: false,
512
+ enableBash: false,
513
+ enableWebFetch: false,
514
+ enableSkills: false,
515
+ enableAskQuestion: false,
516
+ enableApplyPatch: false,
517
+ enableEditor: true,
518
+ });
519
+ const editorTool = tools.find((tool) => tool.name === "editor");
520
+ expect(editorTool).toBeDefined();
521
+ if (!editorTool) {
522
+ throw new Error("Expected editor tool to be defined.");
523
+ }
524
+
525
+ const result = await editorTool.execute(
526
+ {
527
+ path: "/tmp/example.ts",
528
+ old_text: "before",
529
+ new_text: "after",
530
+ },
531
+ {
532
+ agentId: "agent-1",
533
+ conversationId: "conv-1",
534
+ iteration: 1,
535
+ },
536
+ );
537
+
538
+ expect(result).toEqual({
539
+ query: "edit:/tmp/example.ts",
540
+ result: "patched",
541
+ success: true,
542
+ });
543
+ expect(execute).toHaveBeenCalledWith(
544
+ expect.objectContaining({
545
+ path: "/tmp/example.ts",
546
+ old_text: "before",
547
+ new_text: "after",
548
+ }),
549
+ process.cwd(),
550
+ expect.objectContaining({
551
+ agentId: "agent-1",
552
+ conversationId: "conv-1",
553
+ iteration: 1,
554
+ }),
555
+ );
556
+ });
557
+
558
+ it("allows edit without old_text so missing files can be created", async () => {
559
+ const execute = vi.fn(async () => "patched");
560
+ const tools = createDefaultTools({
561
+ executors: {
562
+ editor: execute,
563
+ },
564
+ enableReadFiles: false,
565
+ enableSearch: false,
566
+ enableBash: false,
567
+ enableWebFetch: false,
568
+ enableSkills: false,
569
+ enableAskQuestion: false,
570
+ enableApplyPatch: false,
571
+ enableEditor: true,
572
+ });
573
+ const editorTool = tools.find((tool) => tool.name === "editor");
574
+ expect(editorTool).toBeDefined();
575
+ if (!editorTool) {
576
+ throw new Error("Expected editor tool to be defined.");
577
+ }
578
+
579
+ const result = await editorTool.execute(
580
+ {
581
+ path: "/tmp/example.ts",
582
+ new_text: "created",
583
+ },
584
+ {
585
+ agentId: "agent-1",
586
+ conversationId: "conv-1",
587
+ iteration: 1,
588
+ },
589
+ );
590
+
591
+ expect(result).toEqual({
592
+ query: "edit:/tmp/example.ts",
593
+ result: "patched",
594
+ success: true,
595
+ });
596
+ expect(execute).toHaveBeenCalledWith(
597
+ expect.objectContaining({
598
+ path: "/tmp/example.ts",
599
+ new_text: "created",
600
+ }),
601
+ process.cwd(),
602
+ expect.anything(),
603
+ );
604
+ });
605
+
606
+ it("treats insert_line as an insert operation", async () => {
607
+ const execute = vi.fn(async () => "patched");
608
+ const tools = createDefaultTools({
609
+ executors: {
610
+ editor: execute,
611
+ },
612
+ enableReadFiles: false,
613
+ enableSearch: false,
614
+ enableBash: false,
615
+ enableWebFetch: false,
616
+ enableSkills: false,
617
+ enableAskQuestion: false,
618
+ enableApplyPatch: false,
619
+ enableEditor: true,
620
+ });
621
+ const editorTool = tools.find((tool) => tool.name === "editor");
622
+ expect(editorTool).toBeDefined();
623
+ if (!editorTool) {
624
+ throw new Error("Expected editor tool to be defined.");
625
+ }
626
+
627
+ const result = await editorTool.execute(
628
+ {
629
+ path: "/tmp/example.ts",
630
+ new_text: "after",
631
+ insert_line: 3,
632
+ },
633
+ {
634
+ agentId: "agent-1",
635
+ conversationId: "conv-1",
636
+ iteration: 1,
637
+ },
638
+ );
639
+
640
+ expect(result).toEqual({
641
+ query: "insert:/tmp/example.ts",
642
+ result: "patched",
643
+ success: true,
644
+ });
645
+ expect(execute).toHaveBeenCalledWith(
646
+ expect.objectContaining({
647
+ path: "/tmp/example.ts",
648
+ new_text: "after",
649
+ insert_line: 3,
650
+ }),
651
+ process.cwd(),
652
+ expect.anything(),
653
+ );
654
+ });
655
+
656
+ it("returns a recoverable tool error when text exceeds the soft character limit", async () => {
657
+ const execute = vi.fn(async () => "patched");
658
+ const tools = createDefaultTools({
659
+ executors: {
660
+ editor: execute,
661
+ },
662
+ enableReadFiles: false,
663
+ enableSearch: false,
664
+ enableBash: false,
665
+ enableWebFetch: false,
666
+ enableSkills: false,
667
+ enableAskQuestion: false,
668
+ enableApplyPatch: false,
669
+ enableEditor: true,
670
+ });
671
+ const editorTool = tools.find((tool) => tool.name === "editor");
672
+ expect(editorTool).toBeDefined();
673
+ if (!editorTool) {
674
+ throw new Error("Expected editor tool to be defined.");
675
+ }
676
+
677
+ const oversizedText = "x".repeat(INPUT_ARG_CHAR_LIMIT + 1);
678
+ const result = await editorTool.execute(
679
+ {
680
+ path: "/tmp/example.ts",
681
+ new_text: oversizedText,
682
+ },
683
+ {
684
+ agentId: "agent-1",
685
+ conversationId: "conv-1",
686
+ iteration: 1,
687
+ },
688
+ );
689
+
690
+ expect(result).toEqual({
691
+ query: "edit:/tmp/example.ts",
692
+ result: "",
693
+ error: expect.stringContaining("new_text was"),
694
+ success: false,
695
+ });
696
+ if (typeof result !== "object" || result == null || !("error" in result)) {
697
+ throw new Error("Expected editor tool result to include an error.");
698
+ }
699
+ expect(result.error).toContain(
700
+ `recommended limit of ${INPUT_ARG_CHAR_LIMIT}`,
701
+ );
702
+ expect(execute).not.toHaveBeenCalled();
703
+ });
704
+ });