@clinebot/core 0.0.21 → 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,169 @@
1
+ /**
2
+ * Default Tools
3
+ *
4
+ * This module provides a set of configurable default tools for agents.
5
+ */
6
+
7
+ // Zod Utilities
8
+ export { validateWithZod, zodToJsonSchema } from "@clinebot/shared";
9
+ // Constants
10
+ export { ALL_DEFAULT_TOOL_NAMES, DefaultToolNames } from "./constants";
11
+ // Tool Definitions
12
+ export {
13
+ createApplyPatchTool,
14
+ createAskQuestionTool,
15
+ createBashTool,
16
+ createDefaultTools,
17
+ createEditorTool,
18
+ createReadFilesTool,
19
+ createSearchTool,
20
+ createSkillsTool,
21
+ createWebFetchTool,
22
+ createWindowsShellTool,
23
+ } from "./definitions";
24
+ // Built-in Executors
25
+ export {
26
+ type ApplyPatchExecutorOptions,
27
+ type BashExecutorOptions,
28
+ createApplyPatchExecutor,
29
+ createBashExecutor,
30
+ createDefaultExecutors,
31
+ createEditorExecutor,
32
+ createFileReadExecutor,
33
+ createSearchExecutor,
34
+ createWebFetchExecutor,
35
+ type DefaultExecutorsOptions,
36
+ type EditorExecutorOptions,
37
+ type FileReadExecutorOptions,
38
+ type SearchExecutorOptions,
39
+ type WebFetchExecutorOptions,
40
+ } from "./executors/index";
41
+ export {
42
+ DEFAULT_MODEL_TOOL_ROUTING_RULES,
43
+ resolveToolRoutingConfig,
44
+ type ToolRoutingRule,
45
+ } from "./model-tool-routing";
46
+ // Presets
47
+ export {
48
+ createDefaultToolsWithPreset,
49
+ createToolPoliciesWithPreset,
50
+ type ToolPolicyPresetName,
51
+ type ToolPresetName,
52
+ ToolPresets,
53
+ } from "./presets";
54
+ // Schemas
55
+ export {
56
+ type ApplyPatchInput,
57
+ ApplyPatchInputSchema,
58
+ type AskQuestionInput,
59
+ AskQuestionInputSchema,
60
+ type EditFileInput,
61
+ EditFileInputSchema,
62
+ type FetchWebContentInput,
63
+ FetchWebContentInputSchema,
64
+ type ReadFileRequest,
65
+ ReadFileRequestSchema,
66
+ type ReadFilesInput,
67
+ ReadFilesInputSchema,
68
+ type RunCommandsInput,
69
+ RunCommandsInputSchema,
70
+ type SearchCodebaseInput,
71
+ SearchCodebaseInputSchema,
72
+ type SkillsInput,
73
+ SkillsInputSchema,
74
+ type WebFetchRequest,
75
+ WebFetchRequestSchema,
76
+ } from "./schemas";
77
+ // Types
78
+ export type {
79
+ ApplyPatchExecutor,
80
+ AskQuestionExecutor,
81
+ BashExecutor,
82
+ CreateDefaultToolsOptions,
83
+ DefaultToolName,
84
+ DefaultToolsConfig,
85
+ EditorExecutor,
86
+ FileReadExecutor,
87
+ SearchExecutor,
88
+ SkillsExecutor,
89
+ SkillsExecutorSkillMetadata,
90
+ SkillsExecutorWithMetadata,
91
+ ToolExecutors,
92
+ ToolOperationResult,
93
+ WebFetchExecutor,
94
+ } from "./types";
95
+
96
+ // =============================================================================
97
+ // Convenience: Create Tools with Built-in Executors
98
+ // =============================================================================
99
+
100
+ import type { Tool } from "@clinebot/agents";
101
+ import { createDefaultTools } from "./definitions";
102
+ import {
103
+ createDefaultExecutors,
104
+ type DefaultExecutorsOptions,
105
+ } from "./executors/index";
106
+ import type { CreateDefaultToolsOptions, ToolExecutors } from "./types";
107
+
108
+ /**
109
+ * Options for creating default tools with built-in executors
110
+ */
111
+ export interface CreateBuiltinToolsOptions
112
+ extends Omit<CreateDefaultToolsOptions, "executors"> {
113
+ /**
114
+ * Configuration for the built-in executors
115
+ */
116
+ executorOptions?: DefaultExecutorsOptions;
117
+ /**
118
+ * Optional executor overrides/additions for tools without built-ins
119
+ */
120
+ executors?: Partial<ToolExecutors>;
121
+ }
122
+
123
+ /**
124
+ * Create default tools with built-in Node.js executors
125
+ *
126
+ * This is a convenience function that creates the default tools with
127
+ * working implementations using Node.js built-in modules.
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * import { Agent } from "@clinebot/agents"
132
+ * import { createBuiltinTools } from "@clinebot/core"
133
+ *
134
+ * const tools = createBuiltinTools({
135
+ * cwd: "/path/to/project",
136
+ * enableBash: true,
137
+ * enableWebFetch: false, // Disable web fetching
138
+ * executorOptions: {
139
+ * bash: { timeoutMs: 60000 },
140
+ * },
141
+ * })
142
+ *
143
+ * const agent = new Agent({
144
+ * providerId: "anthropic",
145
+ * modelId: "claude-sonnet-4-20250514",
146
+ * systemPrompt: "You are a coding assistant.",
147
+ * tools,
148
+ * })
149
+ * ```
150
+ */
151
+ export function createBuiltinTools(
152
+ options: CreateBuiltinToolsOptions = {},
153
+ ): Tool[] {
154
+ const {
155
+ executorOptions = {},
156
+ executors: executorOverrides,
157
+ ...toolsConfig
158
+ } = options;
159
+
160
+ const executors = {
161
+ ...createDefaultExecutors(executorOptions),
162
+ ...(executorOverrides ?? {}),
163
+ };
164
+
165
+ return createDefaultTools({
166
+ ...toolsConfig,
167
+ executors,
168
+ });
169
+ }
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ DEFAULT_MODEL_TOOL_ROUTING_RULES,
4
+ resolveToolRoutingConfig,
5
+ } from "./model-tool-routing";
6
+
7
+ describe("model tool routing", () => {
8
+ it("applies default codex/gpt routing in act mode", () => {
9
+ const config = resolveToolRoutingConfig(
10
+ "openai",
11
+ "openai/gpt-5.4",
12
+ "act",
13
+ DEFAULT_MODEL_TOOL_ROUTING_RULES,
14
+ );
15
+
16
+ expect(config.enableApplyPatch).toBe(true);
17
+ expect(config.enableEditor).toBe(false);
18
+ });
19
+
20
+ it("does not apply default codex/gpt routing in plan mode", () => {
21
+ const config = resolveToolRoutingConfig(
22
+ "openai",
23
+ "openai/gpt-5.4",
24
+ "plan",
25
+ DEFAULT_MODEL_TOOL_ROUTING_RULES,
26
+ );
27
+
28
+ expect(config).toEqual({});
29
+ });
30
+
31
+ it("applies matching custom rules in order", () => {
32
+ const config = resolveToolRoutingConfig(
33
+ "anthropic",
34
+ "claude-sonnet-4-6",
35
+ "act",
36
+ [
37
+ {
38
+ name: "claude-editor-off",
39
+ mode: "act",
40
+ modelIdIncludes: ["claude"],
41
+ disableTools: ["editor"],
42
+ },
43
+ {
44
+ name: "claude-apply-patch-on",
45
+ mode: "act",
46
+ modelIdIncludes: ["claude"],
47
+ enableTools: ["apply_patch"],
48
+ },
49
+ ],
50
+ );
51
+
52
+ expect(config.enableEditor).toBe(false);
53
+ expect(config.enableApplyPatch).toBe(true);
54
+ });
55
+
56
+ it("returns empty config when no rules match", () => {
57
+ const config = resolveToolRoutingConfig(
58
+ "anthropic",
59
+ "claude-sonnet-4-6",
60
+ "act",
61
+ [
62
+ {
63
+ mode: "act",
64
+ modelIdIncludes: ["gpt"],
65
+ enableTools: ["apply_patch"],
66
+ },
67
+ ],
68
+ );
69
+
70
+ expect(config).toEqual({});
71
+ });
72
+
73
+ it("can match provider-only rules", () => {
74
+ const config = resolveToolRoutingConfig("openai", "o4-mini", "act", [
75
+ {
76
+ mode: "act",
77
+ providerIdIncludes: ["openai"],
78
+ enableTools: ["apply_patch"],
79
+ disableTools: ["editor"],
80
+ },
81
+ ]);
82
+
83
+ expect(config.enableApplyPatch).toBe(true);
84
+ expect(config.enableEditor).toBe(false);
85
+ });
86
+ });
@@ -0,0 +1,132 @@
1
+ import type { CoreAgentMode } from "../types/config";
2
+ import type { DefaultToolName, DefaultToolsConfig } from "./types";
3
+
4
+ export interface ToolRoutingRule {
5
+ /**
6
+ * Optional rule label for debugging and logs.
7
+ */
8
+ name?: string;
9
+ /**
10
+ * Which mode the rule applies to.
11
+ * @default "any"
12
+ */
13
+ mode?: CoreAgentMode | "any";
14
+ /**
15
+ * Case-insensitive substrings that must match the model ID.
16
+ * When omitted/empty, the rule is not constrained by model ID.
17
+ */
18
+ modelIdIncludes?: string[];
19
+ /**
20
+ * Case-insensitive substrings that must match the provider ID.
21
+ * When omitted/empty, the rule is not constrained by provider ID.
22
+ */
23
+ providerIdIncludes?: string[];
24
+ /**
25
+ * Enable these tools when the rule matches.
26
+ */
27
+ enableTools?: DefaultToolName[];
28
+ /**
29
+ * Disable these tools when the rule matches.
30
+ */
31
+ disableTools?: DefaultToolName[];
32
+ }
33
+
34
+ const TOOL_NAME_TO_FLAG: Record<
35
+ DefaultToolName,
36
+ keyof Pick<
37
+ DefaultToolsConfig,
38
+ | "enableReadFiles"
39
+ | "enableSearch"
40
+ | "enableBash"
41
+ | "enableWebFetch"
42
+ | "enableApplyPatch"
43
+ | "enableEditor"
44
+ | "enableSkills"
45
+ | "enableAskQuestion"
46
+ >
47
+ > = {
48
+ read_files: "enableReadFiles",
49
+ search_codebase: "enableSearch",
50
+ run_commands: "enableBash",
51
+ fetch_web_content: "enableWebFetch",
52
+ apply_patch: "enableApplyPatch",
53
+ editor: "enableEditor",
54
+ skills: "enableSkills",
55
+ ask_question: "enableAskQuestion",
56
+ };
57
+
58
+ export const DEFAULT_MODEL_TOOL_ROUTING_RULES: ToolRoutingRule[] = [
59
+ {
60
+ name: "openai-native-use-apply-patch",
61
+ mode: "act",
62
+ providerIdIncludes: ["openai-native"],
63
+ enableTools: ["apply_patch"],
64
+ disableTools: ["editor"],
65
+ },
66
+ {
67
+ name: "codex-and-gpt-use-apply-patch",
68
+ mode: "act",
69
+ modelIdIncludes: ["codex", "gpt"],
70
+ enableTools: ["apply_patch"],
71
+ disableTools: ["editor"],
72
+ },
73
+ ];
74
+
75
+ function matchesModelId(
76
+ modelId: string,
77
+ includes: string[] | undefined,
78
+ ): boolean {
79
+ if (!includes || includes.length === 0) {
80
+ return true;
81
+ }
82
+ const normalizedModelId = modelId.toLowerCase();
83
+ return includes.some((value) =>
84
+ normalizedModelId.includes(value.toLowerCase()),
85
+ );
86
+ }
87
+
88
+ function matchesRule(
89
+ rule: ToolRoutingRule,
90
+ providerId: string,
91
+ modelId: string,
92
+ mode: CoreAgentMode,
93
+ ): boolean {
94
+ if (rule.mode && rule.mode !== "any" && rule.mode !== mode) {
95
+ return false;
96
+ }
97
+ return (
98
+ matchesModelId(providerId, rule.providerIdIncludes) &&
99
+ matchesModelId(modelId, rule.modelIdIncludes)
100
+ );
101
+ }
102
+
103
+ export function resolveToolRoutingConfig(
104
+ providerId: string,
105
+ modelId: string,
106
+ mode: CoreAgentMode,
107
+ rules: ToolRoutingRule[] | undefined,
108
+ ): Partial<DefaultToolsConfig> {
109
+ if (!rules || rules.length === 0) {
110
+ return {};
111
+ }
112
+
113
+ const toggles = new Map<DefaultToolName, boolean>();
114
+
115
+ for (const rule of rules) {
116
+ if (!matchesRule(rule, providerId, modelId, mode)) {
117
+ continue;
118
+ }
119
+ for (const toolName of rule.disableTools ?? []) {
120
+ toggles.set(toolName, false);
121
+ }
122
+ for (const toolName of rule.enableTools ?? []) {
123
+ toggles.set(toolName, true);
124
+ }
125
+ }
126
+
127
+ const config: Partial<DefaultToolsConfig> = {};
128
+ for (const [toolName, enabled] of toggles.entries()) {
129
+ config[TOOL_NAME_TO_FLAG[toolName]] = enabled;
130
+ }
131
+ return config;
132
+ }
@@ -0,0 +1,62 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ createDefaultToolsWithPreset,
4
+ createToolPoliciesWithPreset,
5
+ ToolPresets,
6
+ } from "./presets";
7
+
8
+ describe("default tool presets", () => {
9
+ it("explicitly configures ask_question across presets", () => {
10
+ expect(ToolPresets.search.enableAskQuestion).toBe(false);
11
+ expect(ToolPresets.development.enableAskQuestion).toBe(true);
12
+ expect(ToolPresets.readonly.enableAskQuestion).toBe(true);
13
+ expect(ToolPresets.minimal.enableAskQuestion).toBe(true);
14
+ expect(ToolPresets.yolo.enableAskQuestion).toBe(false);
15
+ });
16
+
17
+ it("yolo preset excludes ask_question even when its executor exists", () => {
18
+ const tools = createDefaultToolsWithPreset("yolo", {
19
+ executors: {
20
+ readFile: async () => "ok",
21
+ search: async () => "ok",
22
+ bash: async () => "ok",
23
+ webFetch: async () => "ok",
24
+ applyPatch: async () => "ok",
25
+ editor: async () => "ok",
26
+ skills: async () => "ok",
27
+ askQuestion: async () => "ok",
28
+ },
29
+ });
30
+
31
+ expect(tools.map((tool) => tool.name)).toEqual([
32
+ "read_files",
33
+ "search_codebase",
34
+ "run_commands",
35
+ "fetch_web_content",
36
+ "editor",
37
+ "skills",
38
+ ]);
39
+ });
40
+ });
41
+
42
+ describe("tool policy presets", () => {
43
+ it("returns empty policies for default", () => {
44
+ expect(createToolPoliciesWithPreset("default")).toEqual({});
45
+ });
46
+
47
+ it("yolo preset enables and auto-approves all tools", () => {
48
+ const policies = createToolPoliciesWithPreset("yolo");
49
+ expect(policies["*"]).toEqual({
50
+ enabled: true,
51
+ autoApprove: true,
52
+ });
53
+ expect(policies.ask_question).toEqual({
54
+ enabled: true,
55
+ autoApprove: true,
56
+ });
57
+ expect(policies.skills).toEqual({
58
+ enabled: true,
59
+ autoApprove: true,
60
+ });
61
+ });
62
+ });
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Tool Presets
3
+ *
4
+ * Pre-configured tool combinations for common use cases.
5
+ */
6
+
7
+ import type { Tool, ToolPolicy } from "@clinebot/shared";
8
+ import { ALL_DEFAULT_TOOL_NAMES } from "./constants";
9
+ import { createDefaultTools } from "./definitions";
10
+ import type { CreateDefaultToolsOptions, DefaultToolsConfig } from "./types";
11
+
12
+ /**
13
+ * Preset configurations for common use cases
14
+ */
15
+ export const ToolPresets = {
16
+ /**
17
+ * Browser-based tools (no shell access, no web fetch)
18
+ */
19
+ browser: {
20
+ enableReadFiles: false,
21
+ enableSearch: false,
22
+ enableBash: false,
23
+ enableWebFetch: false,
24
+ enableApplyPatch: false,
25
+ enableEditor: false,
26
+ enableSkills: true,
27
+ enableAskQuestion: true,
28
+ },
29
+
30
+ /**
31
+ * Search-focused tools (read_files + search_codebase)
32
+ * Good for code exploration and analysis agents
33
+ */
34
+ search: {
35
+ enableReadFiles: true,
36
+ enableSearch: true,
37
+ enableBash: false,
38
+ enableWebFetch: false,
39
+ enableApplyPatch: false,
40
+ enableEditor: false,
41
+ enableSkills: false,
42
+ enableAskQuestion: false,
43
+ },
44
+
45
+ /**
46
+ * Full development tools (all tools enabled) - Act mode
47
+ * Good for coding assistants and task automation
48
+ */
49
+ development: {
50
+ enableReadFiles: true,
51
+ enableSearch: true,
52
+ enableBash: true,
53
+ enableWebFetch: true,
54
+ enableApplyPatch: false,
55
+ enableEditor: true,
56
+ enableSkills: true,
57
+ enableAskQuestion: true,
58
+ },
59
+
60
+ /**
61
+ * Read-only tools (no shell access) - Plan mode
62
+ * Good for analysis and documentation agents
63
+ */
64
+ readonly: {
65
+ enableReadFiles: true,
66
+ enableSearch: true,
67
+ enableBash: true,
68
+ enableWebFetch: true,
69
+ enableApplyPatch: false,
70
+ enableEditor: false,
71
+ enableSkills: true,
72
+ enableAskQuestion: true,
73
+ },
74
+
75
+ /**
76
+ * Minimal tools (file reading only)
77
+ * Good for focused single-file tasks
78
+ */
79
+ minimal: {
80
+ enableReadFiles: false,
81
+ enableSearch: false,
82
+ enableBash: false,
83
+ enableWebFetch: false,
84
+ enableApplyPatch: false,
85
+ enableEditor: false,
86
+ enableSkills: false,
87
+ enableAskQuestion: true,
88
+ },
89
+
90
+ /**
91
+ * YOLO mode (automation-focused tools + no approval required)
92
+ * Good for trusted local automation workflows.
93
+ */
94
+ yolo: {
95
+ enableReadFiles: true,
96
+ enableSearch: true,
97
+ enableBash: true,
98
+ enableWebFetch: true,
99
+ enableApplyPatch: false,
100
+ enableEditor: true,
101
+ enableSkills: true,
102
+ enableAskQuestion: false,
103
+ },
104
+ } as const satisfies Record<string, DefaultToolsConfig>;
105
+
106
+ /**
107
+ * Type for preset names
108
+ */
109
+ export type ToolPresetName = keyof typeof ToolPresets;
110
+
111
+ /**
112
+ * Tool policy preset names
113
+ */
114
+ export type ToolPolicyPresetName = "default" | "yolo";
115
+
116
+ /**
117
+ * Build tool policies for a preset.
118
+ * `yolo` guarantees tool policies are enabled and auto-approved.
119
+ */
120
+ export function createToolPoliciesWithPreset(
121
+ presetName: ToolPolicyPresetName,
122
+ ): Record<string, ToolPolicy> {
123
+ if (presetName !== "yolo") {
124
+ return {};
125
+ }
126
+
127
+ const yoloPolicy: ToolPolicy = {
128
+ enabled: true,
129
+ autoApprove: true,
130
+ };
131
+
132
+ const policies: Record<string, ToolPolicy> = {
133
+ "*": yoloPolicy,
134
+ };
135
+
136
+ for (const toolName of ALL_DEFAULT_TOOL_NAMES) {
137
+ policies[toolName] = yoloPolicy;
138
+ }
139
+
140
+ return policies;
141
+ }
142
+
143
+ /**
144
+ * Create default tools using a preset configuration
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const tools = createDefaultToolsWithPreset("readonly", {
149
+ * executors: {
150
+ * readFile: async ({ path }) => fs.readFile(path, "utf-8"),
151
+ * search: async (query, cwd) => searchFiles(query, cwd),
152
+ * webFetch: async (url, prompt) => fetchAndAnalyze(url, prompt),
153
+ * },
154
+ * cwd: "/path/to/project",
155
+ * })
156
+ * ```
157
+ */
158
+ export function createDefaultToolsWithPreset(
159
+ presetName: ToolPresetName,
160
+ options: Omit<CreateDefaultToolsOptions, keyof DefaultToolsConfig> &
161
+ Partial<DefaultToolsConfig>,
162
+ ): Tool[] {
163
+ const preset = ToolPresets[presetName];
164
+ return createDefaultTools({
165
+ ...preset,
166
+ ...options,
167
+ });
168
+ }