@clinebot/core 0.0.35 → 0.0.36

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 (335) hide show
  1. package/README.md +1 -2
  2. package/dist/ClineCore.d.ts +53 -39
  3. package/dist/ClineCore.d.ts.map +1 -1
  4. package/dist/account/index.d.ts +1 -1
  5. package/dist/account/index.d.ts.map +1 -1
  6. package/dist/account/rpc.d.ts +6 -6
  7. package/dist/account/rpc.d.ts.map +1 -1
  8. package/dist/cron/index.d.ts +6 -0
  9. package/dist/cron/index.d.ts.map +1 -0
  10. package/dist/cron/resource-limiter.d.ts +9 -0
  11. package/dist/cron/resource-limiter.d.ts.map +1 -0
  12. package/dist/cron/schedule-command-service.d.ts +10 -0
  13. package/dist/cron/schedule-command-service.d.ts.map +1 -0
  14. package/dist/cron/schedule-service.d.ts +100 -0
  15. package/dist/cron/schedule-service.d.ts.map +1 -0
  16. package/dist/cron/scheduler.d.ts +66 -0
  17. package/dist/cron/scheduler.d.ts.map +1 -0
  18. package/dist/cron/sqlite-schedule-store.d.ts +52 -0
  19. package/dist/cron/sqlite-schedule-store.d.ts.map +1 -0
  20. package/dist/extensions/config/agent-config-loader.d.ts +4 -3
  21. package/dist/extensions/config/agent-config-loader.d.ts.map +1 -1
  22. package/dist/extensions/config/runtime-commands.d.ts +1 -0
  23. package/dist/extensions/config/runtime-commands.d.ts.map +1 -1
  24. package/dist/extensions/config/user-instruction-config-loader.d.ts +1 -0
  25. package/dist/extensions/config/user-instruction-config-loader.d.ts.map +1 -1
  26. package/dist/extensions/context/agentic-compaction.d.ts +2 -2
  27. package/dist/extensions/context/agentic-compaction.d.ts.map +1 -1
  28. package/dist/extensions/context/compaction-shared.d.ts +5 -4
  29. package/dist/extensions/context/compaction-shared.d.ts.map +1 -1
  30. package/dist/extensions/context/compaction.d.ts.map +1 -1
  31. package/dist/extensions/plugin/plugin-config-loader.d.ts +9 -2
  32. package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
  33. package/dist/extensions/plugin/plugin-loader.d.ts +5 -3
  34. package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -1
  35. package/dist/extensions/plugin/plugin-module-import.d.ts.map +1 -1
  36. package/dist/extensions/plugin/plugin-sandbox.d.ts +15 -2
  37. package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -1
  38. package/dist/extensions/plugin/plugin-targeting.d.ts +7 -0
  39. package/dist/extensions/plugin/plugin-targeting.d.ts.map +1 -0
  40. package/dist/extensions/plugin-sandbox-bootstrap.js +211 -211
  41. package/dist/extensions/tools/definitions.d.ts +1 -1
  42. package/dist/extensions/tools/definitions.d.ts.map +1 -1
  43. package/dist/extensions/tools/executors/apply-patch.d.ts +3 -1
  44. package/dist/extensions/tools/executors/apply-patch.d.ts.map +1 -1
  45. package/dist/extensions/tools/executors/search.d.ts +1 -1
  46. package/dist/extensions/tools/executors/search.d.ts.map +1 -1
  47. package/dist/extensions/tools/index.d.ts +2 -0
  48. package/dist/extensions/tools/index.d.ts.map +1 -1
  49. package/dist/extensions/tools/presets.d.ts +26 -43
  50. package/dist/extensions/tools/presets.d.ts.map +1 -1
  51. package/dist/extensions/tools/runtime.d.ts +25 -0
  52. package/dist/extensions/tools/runtime.d.ts.map +1 -0
  53. package/dist/extensions/tools/schemas.d.ts.map +1 -1
  54. package/dist/extensions/tools/team/team-tools.d.ts +1 -0
  55. package/dist/extensions/tools/team/team-tools.d.ts.map +1 -1
  56. package/dist/hooks/hook-file-hooks.d.ts +4 -1
  57. package/dist/hooks/hook-file-hooks.d.ts.map +1 -1
  58. package/dist/hooks/index.d.ts +0 -1
  59. package/dist/hooks/index.d.ts.map +1 -1
  60. package/dist/hooks/subprocess.d.ts +8 -1
  61. package/dist/hooks/subprocess.d.ts.map +1 -1
  62. package/dist/hub/browser-websocket.d.ts +18 -0
  63. package/dist/hub/browser-websocket.d.ts.map +1 -0
  64. package/dist/hub/client.d.ts +45 -0
  65. package/dist/hub/client.d.ts.map +1 -0
  66. package/dist/hub/connect.d.ts +15 -0
  67. package/dist/hub/connect.d.ts.map +1 -0
  68. package/dist/hub/daemon-entry.d.ts +2 -0
  69. package/dist/hub/daemon-entry.d.ts.map +1 -0
  70. package/dist/hub/daemon-entry.js +1045 -0
  71. package/dist/hub/daemon.d.ts +5 -0
  72. package/dist/hub/daemon.d.ts.map +1 -0
  73. package/dist/hub/defaults.d.ts +13 -0
  74. package/dist/hub/defaults.d.ts.map +1 -0
  75. package/dist/hub/discovery.d.ts +29 -0
  76. package/dist/hub/discovery.d.ts.map +1 -0
  77. package/dist/hub/index.d.ts +15 -0
  78. package/dist/hub/index.d.ts.map +1 -0
  79. package/dist/hub/index.js +1044 -0
  80. package/dist/hub/native-transport.d.ts +17 -0
  81. package/dist/hub/native-transport.d.ts.map +1 -0
  82. package/dist/hub/runtime-handlers.d.ts +11 -0
  83. package/dist/hub/runtime-handlers.d.ts.map +1 -0
  84. package/dist/hub/server.d.ts +86 -0
  85. package/dist/hub/server.d.ts.map +1 -0
  86. package/dist/hub/session-client.d.ts +87 -0
  87. package/dist/hub/session-client.d.ts.map +1 -0
  88. package/dist/hub/start-shared-server.d.ts +19 -0
  89. package/dist/hub/start-shared-server.d.ts.map +1 -0
  90. package/dist/hub/transport.d.ts +8 -0
  91. package/dist/hub/transport.d.ts.map +1 -0
  92. package/dist/hub/ui-client.d.ts +44 -0
  93. package/dist/hub/ui-client.d.ts.map +1 -0
  94. package/dist/hub/workspace.d.ts +4 -0
  95. package/dist/hub/workspace.d.ts.map +1 -0
  96. package/dist/index.d.ts +26 -15
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +498 -476
  99. package/dist/llms/configured-provider-registry.d.ts +28 -0
  100. package/dist/llms/configured-provider-registry.d.ts.map +1 -0
  101. package/dist/llms/provider-defaults.d.ts +27 -0
  102. package/dist/llms/provider-defaults.d.ts.map +1 -0
  103. package/dist/llms/provider-settings.d.ts +202 -0
  104. package/dist/llms/provider-settings.d.ts.map +1 -0
  105. package/dist/llms/runtime-config.d.ts +4 -0
  106. package/dist/llms/runtime-config.d.ts.map +1 -0
  107. package/dist/llms/runtime-registry.d.ts +20 -0
  108. package/dist/llms/runtime-registry.d.ts.map +1 -0
  109. package/dist/llms/runtime-types.d.ts +85 -0
  110. package/dist/llms/runtime-types.d.ts.map +1 -0
  111. package/dist/runtime/host.d.ts +1 -2
  112. package/dist/runtime/host.d.ts.map +1 -1
  113. package/dist/runtime/rules.d.ts +1 -0
  114. package/dist/runtime/rules.d.ts.map +1 -1
  115. package/dist/runtime/runtime-builder.d.ts.map +1 -1
  116. package/dist/runtime/runtime-host.d.ts +22 -24
  117. package/dist/runtime/runtime-host.d.ts.map +1 -1
  118. package/dist/runtime/runtime-oauth-token-manager.d.ts.map +1 -1
  119. package/dist/runtime/session-runtime.d.ts +1 -19
  120. package/dist/runtime/session-runtime.d.ts.map +1 -1
  121. package/dist/services/global-settings.d.ts +12 -0
  122. package/dist/services/global-settings.d.ts.map +1 -0
  123. package/dist/services/local-runtime-bootstrap.d.ts +9 -3
  124. package/dist/services/local-runtime-bootstrap.d.ts.map +1 -1
  125. package/dist/services/plugin-tools.d.ts +16 -0
  126. package/dist/services/plugin-tools.d.ts.map +1 -0
  127. package/dist/services/providers/local-provider-registry.d.ts +4 -4
  128. package/dist/services/providers/local-provider-registry.d.ts.map +1 -1
  129. package/dist/services/providers/local-provider-service.d.ts +13 -13
  130. package/dist/services/providers/local-provider-service.d.ts.map +1 -1
  131. package/dist/services/session-data.d.ts +1 -1
  132. package/dist/services/session-data.d.ts.map +1 -1
  133. package/dist/services/storage/provider-settings-legacy-migration.d.ts +1 -1
  134. package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +1 -1
  135. package/dist/services/telemetry/index.js +28 -15
  136. package/dist/services/workspace-manifest.d.ts +11 -0
  137. package/dist/services/workspace-manifest.d.ts.map +1 -1
  138. package/dist/session/persistence-service.d.ts +11 -23
  139. package/dist/session/persistence-service.d.ts.map +1 -1
  140. package/dist/session/session-manifest-store.d.ts +22 -0
  141. package/dist/session/session-manifest-store.d.ts.map +1 -0
  142. package/dist/session/session-row.d.ts +93 -0
  143. package/dist/session/session-row.d.ts.map +1 -0
  144. package/dist/session/session-service.d.ts +2 -102
  145. package/dist/session/session-service.d.ts.map +1 -1
  146. package/dist/session/subagent-session-manager.d.ts +36 -0
  147. package/dist/session/subagent-session-manager.d.ts.map +1 -0
  148. package/dist/session/team-persistence-store.d.ts +24 -0
  149. package/dist/session/team-persistence-store.d.ts.map +1 -0
  150. package/dist/transports/hub.d.ts +47 -0
  151. package/dist/transports/hub.d.ts.map +1 -0
  152. package/dist/transports/local.d.ts +10 -6
  153. package/dist/transports/local.d.ts.map +1 -1
  154. package/dist/transports/remote.d.ts +10 -0
  155. package/dist/transports/remote.d.ts.map +1 -0
  156. package/dist/transports/runtime-host-support.d.ts +3 -2
  157. package/dist/transports/runtime-host-support.d.ts.map +1 -1
  158. package/dist/types/chat-schema.d.ts +10 -12
  159. package/dist/types/chat-schema.d.ts.map +1 -1
  160. package/dist/types/config.d.ts +8 -7
  161. package/dist/types/config.d.ts.map +1 -1
  162. package/dist/types/provider-settings.d.ts +4 -5
  163. package/dist/types/provider-settings.d.ts.map +1 -1
  164. package/dist/types/session.d.ts +2 -1
  165. package/dist/types/session.d.ts.map +1 -1
  166. package/dist/types.d.ts +8 -1
  167. package/dist/types.d.ts.map +1 -1
  168. package/package.json +20 -6
  169. package/src/ClineCore.ts +68 -40
  170. package/src/account/index.ts +3 -3
  171. package/src/account/rpc.ts +12 -12
  172. package/src/cron/index.ts +5 -0
  173. package/src/cron/resource-limiter.ts +46 -0
  174. package/src/cron/schedule-command-service.ts +193 -0
  175. package/src/cron/schedule-service.ts +703 -0
  176. package/src/cron/scheduler.ts +637 -0
  177. package/src/cron/sqlite-schedule-store.ts +708 -0
  178. package/src/extensions/config/agent-config-loader.ts +17 -7
  179. package/src/extensions/config/runtime-commands.ts +6 -0
  180. package/src/extensions/config/user-instruction-config-loader.ts +1 -0
  181. package/src/extensions/context/agentic-compaction.ts +3 -3
  182. package/src/extensions/context/basic-compaction.ts +2 -2
  183. package/src/extensions/context/compaction-shared.ts +5 -4
  184. package/src/extensions/context/compaction.ts +3 -3
  185. package/src/extensions/plugin/plugin-config-loader.ts +17 -2
  186. package/src/extensions/plugin/plugin-loader.ts +48 -4
  187. package/src/extensions/plugin/plugin-module-import.ts +0 -2
  188. package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +93 -39
  189. package/src/extensions/plugin/plugin-sandbox.ts +47 -27
  190. package/src/extensions/plugin/plugin-targeting.ts +32 -0
  191. package/src/extensions/tools/definitions.ts +30 -49
  192. package/src/extensions/tools/executors/apply-patch.ts +69 -80
  193. package/src/extensions/tools/executors/search.ts +195 -3
  194. package/src/extensions/tools/index.ts +10 -0
  195. package/src/extensions/tools/presets.ts +31 -46
  196. package/src/extensions/tools/runtime.ts +261 -0
  197. package/src/extensions/tools/schemas.ts +4 -2
  198. package/src/extensions/tools/team/team-tools.ts +21 -0
  199. package/src/hooks/hook-file-hooks.ts +8 -2
  200. package/src/hooks/index.ts +0 -7
  201. package/src/hooks/subprocess-runner.ts +1 -1
  202. package/src/hooks/subprocess.ts +9 -0
  203. package/src/hub/browser-websocket.ts +137 -0
  204. package/src/hub/client.ts +574 -0
  205. package/src/hub/connect.ts +156 -0
  206. package/src/hub/daemon-entry.ts +87 -0
  207. package/src/hub/daemon.ts +181 -0
  208. package/src/hub/defaults.ts +43 -0
  209. package/src/hub/discovery.ts +247 -0
  210. package/src/hub/index.ts +14 -0
  211. package/src/hub/native-transport.ts +31 -0
  212. package/src/hub/runtime-handlers.ts +140 -0
  213. package/src/hub/server.ts +1888 -0
  214. package/src/hub/session-client.ts +460 -0
  215. package/src/hub/start-shared-server.ts +58 -0
  216. package/src/hub/transport.ts +14 -0
  217. package/src/hub/ui-client.ts +122 -0
  218. package/src/hub/workspace.ts +19 -0
  219. package/src/index.ts +124 -68
  220. package/src/llms/configured-provider-registry.ts +193 -0
  221. package/src/llms/provider-defaults.ts +637 -0
  222. package/src/llms/provider-settings.ts +263 -0
  223. package/src/llms/runtime-config.ts +43 -0
  224. package/src/llms/runtime-registry.ts +171 -0
  225. package/src/llms/runtime-types.ts +121 -0
  226. package/src/runtime/host.ts +107 -269
  227. package/src/runtime/index.ts +1 -0
  228. package/src/runtime/rules.ts +12 -0
  229. package/src/runtime/runtime-builder.ts +24 -8
  230. package/src/runtime/runtime-host.ts +89 -61
  231. package/src/runtime/runtime-oauth-token-manager.ts +11 -15
  232. package/src/runtime/session-runtime.ts +0 -24
  233. package/src/services/global-settings.ts +122 -0
  234. package/src/services/local-runtime-bootstrap.ts +51 -13
  235. package/src/services/plugin-tools.ts +85 -0
  236. package/src/services/providers/local-provider-registry.ts +6 -6
  237. package/src/services/providers/local-provider-service.ts +42 -37
  238. package/src/services/session-data.ts +15 -9
  239. package/src/services/storage/provider-settings-legacy-migration.ts +6 -4
  240. package/src/services/storage/provider-settings-manager.ts +1 -1
  241. package/src/services/workspace-manifest.ts +18 -0
  242. package/src/session/file-session-service.ts +1 -1
  243. package/src/session/index.ts +6 -27
  244. package/src/session/persistence-service.ts +119 -504
  245. package/src/session/session-manifest-store.ts +158 -0
  246. package/src/session/session-row.ts +199 -0
  247. package/src/session/session-service.ts +17 -376
  248. package/src/session/session-team-coordination.ts +1 -1
  249. package/src/session/subagent-session-manager.ts +397 -0
  250. package/src/session/team-persistence-store.ts +176 -0
  251. package/src/transports/hub.ts +656 -0
  252. package/src/transports/local.ts +135 -40
  253. package/src/transports/remote.ts +26 -0
  254. package/src/transports/runtime-host-support.ts +63 -9
  255. package/src/types/chat-schema.ts +4 -5
  256. package/src/types/config.ts +8 -7
  257. package/src/types/provider-settings.ts +11 -7
  258. package/src/types/session.ts +2 -4
  259. package/src/types.ts +27 -1
  260. package/dist/hooks/persistent.d.ts +0 -64
  261. package/dist/hooks/persistent.d.ts.map +0 -1
  262. package/dist/runtime/rpc-runtime-ensure.d.ts +0 -65
  263. package/dist/runtime/rpc-runtime-ensure.d.ts.map +0 -1
  264. package/dist/runtime/rpc-spawn-lease.d.ts +0 -8
  265. package/dist/runtime/rpc-spawn-lease.d.ts.map +0 -1
  266. package/dist/session/rpc-session-service.d.ts +0 -16
  267. package/dist/session/rpc-session-service.d.ts.map +0 -1
  268. package/dist/session/sqlite-rpc-session-backend.d.ts +0 -31
  269. package/dist/session/sqlite-rpc-session-backend.d.ts.map +0 -1
  270. package/dist/transports/rpc.d.ts +0 -51
  271. package/dist/transports/rpc.d.ts.map +0 -1
  272. package/src/ClineCore.test.ts +0 -226
  273. package/src/account/cline-account-service.test.ts +0 -185
  274. package/src/account/featurebase-token.test.ts +0 -175
  275. package/src/account/rpc.test.ts +0 -63
  276. package/src/auth/bounded-ttl-cache.test.ts +0 -38
  277. package/src/auth/client.test.ts +0 -69
  278. package/src/auth/cline.test.ts +0 -267
  279. package/src/auth/codex.test.ts +0 -170
  280. package/src/auth/oca.test.ts +0 -340
  281. package/src/auth/server.test.ts +0 -287
  282. package/src/auth/utils.test.ts +0 -128
  283. package/src/extensions/config/agent-config-loader.test.ts +0 -236
  284. package/src/extensions/config/hooks-config-loader.test.ts +0 -20
  285. package/src/extensions/config/runtime-commands.test.ts +0 -115
  286. package/src/extensions/config/unified-config-file-watcher.test.ts +0 -196
  287. package/src/extensions/config/user-instruction-config-loader.test.ts +0 -246
  288. package/src/extensions/context/compaction.test.ts +0 -483
  289. package/src/extensions/mcp/config-loader.test.ts +0 -238
  290. package/src/extensions/mcp/manager.test.ts +0 -105
  291. package/src/extensions/plugin/plugin-config-loader.test.ts +0 -184
  292. package/src/extensions/plugin/plugin-loader.test.ts +0 -292
  293. package/src/extensions/plugin/plugin-sandbox.test.ts +0 -423
  294. package/src/extensions/tools/definitions.test.ts +0 -780
  295. package/src/extensions/tools/executors/bash.test.ts +0 -87
  296. package/src/extensions/tools/executors/editor.test.ts +0 -35
  297. package/src/extensions/tools/executors/file-read.test.ts +0 -125
  298. package/src/extensions/tools/model-tool-routing.test.ts +0 -86
  299. package/src/extensions/tools/presets.test.ts +0 -70
  300. package/src/extensions/tools/team/multi-agent.lifecycle.test.ts +0 -455
  301. package/src/extensions/tools/team/spawn-agent-tool.test.ts +0 -381
  302. package/src/extensions/tools/team/team-tools.test.ts +0 -918
  303. package/src/hooks/checkpoint-hooks.test.ts +0 -168
  304. package/src/hooks/hook-file-hooks.test.ts +0 -311
  305. package/src/hooks/persistent.ts +0 -661
  306. package/src/runtime/history.test.ts +0 -114
  307. package/src/runtime/host.test.ts +0 -230
  308. package/src/runtime/rpc-runtime-ensure.test.ts +0 -123
  309. package/src/runtime/rpc-runtime-ensure.ts +0 -659
  310. package/src/runtime/rpc-spawn-lease.test.ts +0 -81
  311. package/src/runtime/rpc-spawn-lease.ts +0 -156
  312. package/src/runtime/runtime-builder.team-persistence.test.ts +0 -245
  313. package/src/runtime/runtime-builder.test.ts +0 -615
  314. package/src/runtime/runtime-oauth-token-manager.test.ts +0 -137
  315. package/src/runtime/runtime-parity.test.ts +0 -143
  316. package/src/services/providers/local-provider-service.test.ts +0 -1062
  317. package/src/services/session-data.test.ts +0 -160
  318. package/src/services/storage/provider-settings-legacy-migration.test.ts +0 -424
  319. package/src/services/storage/provider-settings-manager.test.ts +0 -191
  320. package/src/services/telemetry/OpenTelemetryAdapter.test.ts +0 -157
  321. package/src/services/telemetry/OpenTelemetryProvider.test.ts +0 -326
  322. package/src/services/telemetry/TelemetryLoggerSink.test.ts +0 -42
  323. package/src/services/telemetry/TelemetryService.test.ts +0 -134
  324. package/src/services/telemetry/distinct-id.test.ts +0 -57
  325. package/src/services/workspace/file-indexer.d.ts +0 -11
  326. package/src/services/workspace/file-indexer.test.ts +0 -156
  327. package/src/services/workspace/mention-enricher.test.ts +0 -106
  328. package/src/session/persistence-service.test.ts +0 -300
  329. package/src/session/rpc-session-service.ts +0 -114
  330. package/src/session/session-service.team-persistence.test.ts +0 -48
  331. package/src/session/sqlite-rpc-session-backend.ts +0 -301
  332. package/src/transports/local.e2e.test.ts +0 -380
  333. package/src/transports/local.test.ts +0 -2559
  334. package/src/transports/rpc.test.ts +0 -82
  335. package/src/transports/rpc.ts +0 -665
@@ -2,17 +2,35 @@ import { existsSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
3
  import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
- import type { AgentConfig, HookStage, Tool } from "@clinebot/shared";
5
+ import type {
6
+ AgentConfig,
7
+ HookStage,
8
+ Tool,
9
+ WorkspaceInfo,
10
+ } from "@clinebot/shared";
6
11
  import { SubprocessSandbox } from "../../runtime/subprocess-sandbox";
7
12
  import type { PluginLoadDiagnostics } from "./plugin-load-report";
13
+ import type { PluginTargeting } from "./plugin-targeting";
8
14
 
9
- export interface PluginSandboxOptions {
15
+ export interface PluginSandboxOptions extends PluginTargeting {
10
16
  pluginPaths: string[];
11
17
  exportName?: string;
12
18
  importTimeoutMs?: number;
13
19
  hookTimeoutMs?: number;
14
20
  contributionTimeoutMs?: number;
15
21
  onEvent?: (event: { name: string; payload?: unknown }) => void;
22
+ /**
23
+ * The session's working directory. Forwarded to the sandbox subprocess so
24
+ * that `process.cwd()` returns the correct path inside the sandbox even
25
+ * when `--cwd` was passed without calling `process.chdir()` on the host.
26
+ */
27
+ cwd?: string;
28
+ /**
29
+ * Structured workspace and git metadata (branch, commit, remotes) generated
30
+ * at session startup. Forwarded to plugins via PluginSetupCtx.workspaceInfo
31
+ * so they can inspect git state without running their own commands.
32
+ */
33
+ workspaceInfo?: WorkspaceInfo;
16
34
  }
17
35
 
18
36
  type AgentExtension = NonNullable<AgentConfig["extensions"]>[number];
@@ -25,8 +43,6 @@ type SandboxedContributionDescriptor = {
25
43
  inputSchema?: unknown;
26
44
  timeoutMs?: number;
27
45
  retryable?: boolean;
28
- value?: string;
29
- defaultValue?: boolean | string | number;
30
46
  metadata?: Record<string, unknown>;
31
47
  };
32
48
 
@@ -38,10 +54,10 @@ type SandboxedPluginDescriptor = {
38
54
  contributions: {
39
55
  tools: SandboxedContributionDescriptor[];
40
56
  commands: SandboxedContributionDescriptor[];
41
- shortcuts: SandboxedContributionDescriptor[];
42
- flags: SandboxedContributionDescriptor[];
43
57
  messageBuilders: SandboxedContributionDescriptor[];
44
58
  providers: SandboxedContributionDescriptor[];
59
+ shortcuts?: SandboxedContributionDescriptor[];
60
+ flags?: SandboxedContributionDescriptor[];
45
61
  };
46
62
  };
47
63
 
@@ -49,6 +65,22 @@ type SandboxedInitializeResult = {
49
65
  plugins: SandboxedPluginDescriptor[];
50
66
  } & PluginLoadDiagnostics;
51
67
 
68
+ function normalizeDescriptor(
69
+ descriptor: SandboxedPluginDescriptor,
70
+ ): SandboxedPluginDescriptor {
71
+ return {
72
+ ...descriptor,
73
+ contributions: {
74
+ tools: descriptor.contributions?.tools ?? [],
75
+ commands: descriptor.contributions?.commands ?? [],
76
+ messageBuilders: descriptor.contributions?.messageBuilders ?? [],
77
+ providers: descriptor.contributions?.providers ?? [],
78
+ shortcuts: descriptor.contributions?.shortcuts ?? [],
79
+ flags: descriptor.contributions?.flags ?? [],
80
+ },
81
+ };
82
+ }
83
+
52
84
  function isUnknownPluginIdError(error: unknown): boolean {
53
85
  const message = error instanceof Error ? error.message : String(error);
54
86
  return message.includes("Unknown sandbox plugin id:");
@@ -181,6 +213,10 @@ export async function loadSandboxedPlugins(
181
213
  const initArgs = {
182
214
  pluginPaths: options.pluginPaths,
183
215
  exportName: options.exportName,
216
+ providerId: options.providerId,
217
+ modelId: options.modelId,
218
+ cwd: options.cwd,
219
+ workspaceInfo: options.workspaceInfo,
184
220
  };
185
221
 
186
222
  // Guard against concurrent re-initialization when multiple tools/hooks
@@ -208,7 +244,7 @@ export async function loadSandboxedPlugins(
208
244
  });
209
245
  throw error;
210
246
  }
211
- const descriptors = initialized.plugins;
247
+ const descriptors = initialized.plugins.map(normalizeDescriptor);
212
248
 
213
249
  const extensions: NonNullable<AgentConfig["extensions"]> = descriptors.map(
214
250
  (descriptor) => {
@@ -267,7 +303,7 @@ function registerTools(
267
303
  timeoutMs: number,
268
304
  reinitialize: () => Promise<void>,
269
305
  ): void {
270
- for (const td of descriptor.contributions.tools) {
306
+ for (const td of descriptor.contributions?.tools ?? []) {
271
307
  const tool: Tool = {
272
308
  name: td.name,
273
309
  description: td.description ?? "",
@@ -318,7 +354,7 @@ function registerCommands(
318
354
  timeoutMs: number,
319
355
  reinitialize: () => Promise<void>,
320
356
  ): void {
321
- for (const cd of descriptor.contributions.commands) {
357
+ for (const cd of descriptor.contributions?.commands ?? []) {
322
358
  api.registerCommand({
323
359
  name: cd.name,
324
360
  description: cd.description,
@@ -357,30 +393,14 @@ function registerSimpleContributions(
357
393
  api: AgentExtensionApi,
358
394
  descriptor: SandboxedPluginDescriptor,
359
395
  ): void {
360
- for (const sd of descriptor.contributions.shortcuts) {
361
- api.registerShortcut({
362
- name: sd.name,
363
- value: sd.value ?? "",
364
- description: sd.description,
365
- });
366
- }
367
-
368
- for (const fd of descriptor.contributions.flags) {
369
- api.registerFlag({
370
- name: fd.name,
371
- description: fd.description,
372
- defaultValue: fd.defaultValue,
373
- });
374
- }
375
-
376
- for (const rd of descriptor.contributions.messageBuilders) {
396
+ for (const rd of descriptor.contributions?.messageBuilders ?? []) {
377
397
  api.registerMessageBuilder({
378
398
  name: rd.name,
379
399
  build: (m) => m,
380
400
  });
381
401
  }
382
402
 
383
- for (const pd of descriptor.contributions.providers) {
403
+ for (const pd of descriptor.contributions?.providers ?? []) {
384
404
  api.registerProvider({
385
405
  name: pd.name,
386
406
  description: pd.description,
@@ -0,0 +1,32 @@
1
+ import type { PluginManifest } from "@clinebot/shared";
2
+
3
+ export interface PluginTargeting {
4
+ providerId?: string;
5
+ modelId?: string;
6
+ }
7
+
8
+ export function matchesPluginManifestTargeting(
9
+ manifest: PluginManifest | undefined,
10
+ targeting: PluginTargeting | undefined,
11
+ ): boolean {
12
+ if (!manifest) {
13
+ return true;
14
+ }
15
+
16
+ if (manifest.providerIds?.length) {
17
+ if (
18
+ !targeting?.providerId ||
19
+ !manifest.providerIds.includes(targeting.providerId)
20
+ ) {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ if (manifest.modelIds?.length) {
26
+ if (!targeting?.modelId || !manifest.modelIds.includes(targeting.modelId)) {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ return true;
32
+ }
@@ -350,67 +350,48 @@ export function createWebFetchTool(
350
350
  });
351
351
  }
352
352
 
353
- const APPLY_PATCH_TOOL_DESC = `This is a custom utility that makes it more convenient to add, remove, move, or edit code in a single file. \`apply_patch\` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the \`apply_patch\` command, you should pass a message of the following structure as "input":
353
+ const APPLY_PATCH_TOOL_DESC = `Use \`apply_patch\` to edit files with the canonical freeform patch grammar. Pass the patch text directly as the \`input\` string. Prefer the exact format below:
354
354
 
355
- %%bash
356
- apply_patch <<"EOF"
357
355
  *** Begin Patch
358
- [YOUR_PATCH]
356
+ *** Update File: path/to/file.ts
357
+ @@ optional section marker
358
+ [context before]
359
+ -[old line]
360
+ +[new line]
361
+ [context after]
359
362
  *** End Patch
360
- EOF
361
363
 
362
- Where [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.
364
+ Supported actions:
365
+ - \`*** Add File: <path>\`
366
+ - \`*** Update File: <path>\`
367
+ - \`*** Delete File: <path>\`
368
+ - optional \`*** Move to: <new path>\` immediately after an Update File header
363
369
 
364
- *** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete.
370
+ Rules:
371
+ - In an Add File section, every file-content line must start with \`+\`.
372
+ - In an Update section, use context lines plus \`-\` and \`+\` lines to describe the change.
373
+ - Use \`@@\` markers when extra context is needed to disambiguate repeated code blocks.
374
+ - Do not use line numbers; this format is context-based.
375
+ - Prefer sending the patch body directly. Legacy shell wrappers such as \`%%bash\` and \`apply_patch <<"EOF"\` are accepted for compatibility but are not preferred.
365
376
 
366
- In a Add File section, every line of the new file (including blank/empty lines) MUST start with a \`+\` prefix. Do not include any unprefixed lines inside an Add section
367
- In a Update/Delete section, repeat the following for each snippet of code that needs to be changed:
368
- [context_before] -> See below for further instructions on context.
369
- - [old_code] -> Precede the old code with a minus sign.
370
- + [new_code] -> Precede the new, replacement code with a plus sign.
371
- [context_after] -> See below for further instructions on context.
377
+ Example:
372
378
 
373
- For instructions on [context_before] and [context_after]:
374
- - By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.
375
- - If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:
376
- @@ class BaseClass
377
- [3 lines of pre-context]
378
- - [old_code]
379
- + [new_code]
380
- [3 lines of post-context]
381
-
382
- - If a code block is repeated so many times in a class or function such that even a single @@ statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple \`@@\` statements to jump to the right context. For instance:
383
-
384
- @@ class BaseClass
385
- @@ def method():
386
- [3 lines of pre-context]
387
- - [old_code]
388
- + [new_code]
389
- [3 lines of post-context]
390
-
391
- Note, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as "input" to this function, in order to apply a patch, is shown below.
392
-
393
- %%bash
394
- apply_patch <<"EOF"
395
379
  *** Begin Patch
396
- *** Update File: pygorithm/searching/binary_search.py
397
- @@ class BaseClass
398
- @@ def search():
399
- - pass
400
- + raise NotImplementedError()
401
-
402
- @@ class Subclass
403
- @@ def search():
404
- - pass
405
- + raise NotImplementedError()
406
-
407
- *** End Patch
408
- EOF`;
380
+ *** Update File: src/page.tsx
381
+ @@
382
+ return (
383
+ <div>
384
+ <button onClick={() => console.log("clicked")}>Click me</button>
385
+ + <button onClick={() => console.log("cancel clicked")}>Cancel</button>
386
+ </div>
387
+ );
388
+ }
389
+ *** End Patch`;
409
390
 
410
391
  /**
411
392
  * Create the apply_patch tool
412
393
  *
413
- * Applies the legacy Cline patch format to one or more files.
394
+ * Applies the canonical apply_patch format to one or more files.
414
395
  */
415
396
  export function createApplyPatchTool(
416
397
  executor: ApplyPatchExecutor,
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Apply Patch Executor
3
3
  *
4
- * Built-in implementation for the legacy apply_patch format.
4
+ * Built-in implementation for the documented GPT-5 apply_patch grammar.
5
+ * It accepts the freeform patch body directly and tolerates the legacy shell
6
+ * wrapper form used by older prompts.
5
7
  */
6
8
 
7
9
  import * as fs from "node:fs/promises";
@@ -25,6 +27,10 @@ interface FileChange {
25
27
  movePath?: string;
26
28
  }
27
29
 
30
+ interface NormalizedPatchInput {
31
+ lines: string[];
32
+ }
33
+
28
34
  /**
29
35
  * Options for the apply_patch executor
30
36
  */
@@ -63,104 +69,87 @@ function resolveFilePath(
63
69
  return resolved;
64
70
  }
65
71
 
66
- function stripBashWrapper(lines: string[]): string[] {
67
- const result: string[] = [];
68
- let insidePatch = false;
69
- let foundBegin = false;
70
- let foundContent = false;
71
-
72
- for (let i = 0; i < lines.length; i++) {
73
- const line = lines[i];
74
- if (
75
- !insidePatch &&
76
- BASH_WRAPPERS.some((wrapper) => line.startsWith(wrapper))
77
- ) {
78
- continue;
79
- }
80
-
81
- if (line.startsWith(PATCH_MARKERS.BEGIN)) {
82
- insidePatch = true;
83
- foundBegin = true;
84
- result.push(line);
85
- continue;
86
- }
72
+ function normalizeLineEndings(input: string): string[] {
73
+ return input.split("\n").map((line) => line.replace(/\r$/, ""));
74
+ }
87
75
 
88
- if (line === PATCH_MARKERS.END) {
89
- insidePatch = false;
90
- result.push(line);
91
- continue;
92
- }
76
+ function isWrapperLine(line: string): boolean {
77
+ if (line.trim() === "") {
78
+ return false;
79
+ }
80
+ return BASH_WRAPPERS.some((wrapper) => line.startsWith(wrapper));
81
+ }
93
82
 
94
- const isPatchContent =
95
- line.startsWith(PATCH_MARKERS.ADD) ||
96
- line.startsWith(PATCH_MARKERS.UPDATE) ||
97
- line.startsWith(PATCH_MARKERS.DELETE) ||
98
- line.startsWith(PATCH_MARKERS.MOVE) ||
99
- line.startsWith(PATCH_MARKERS.SECTION) ||
100
- line.startsWith("+") ||
101
- line.startsWith("-") ||
102
- line.startsWith(" ") ||
103
- line === "***";
104
-
105
- if (isPatchContent && i !== lines.length - 1) {
106
- foundContent = true;
107
- }
83
+ function trimWrapperLines(lines: string[]): string[] {
84
+ let start = 0;
85
+ let end = lines.length;
108
86
 
109
- if (
110
- insidePatch ||
111
- (!foundBegin && isPatchContent) ||
112
- (line === "" && foundContent)
113
- ) {
114
- result.push(line);
115
- }
87
+ while (start < end && isWrapperLine(lines[start] ?? "")) {
88
+ start++;
116
89
  }
117
90
 
118
- while (result.length > 0 && result[result.length - 1] === "") {
119
- result.pop();
91
+ while (end > start && isWrapperLine(lines[end - 1] ?? "")) {
92
+ end--;
120
93
  }
121
94
 
122
- return !foundBegin && !foundContent ? lines : result;
95
+ return lines.slice(start, end);
123
96
  }
124
97
 
125
- function preprocessLines(input: string): string[] {
126
- let lines = input.split("\n").map((line) => line.replace(/\r$/, ""));
127
- lines = stripBashWrapper(lines);
98
+ function normalizePatchInput(input: string): NormalizedPatchInput {
99
+ const rawLines = normalizeLineEndings(input);
100
+ const beginIndex = rawLines.findIndex((line) =>
101
+ line.startsWith(PATCH_MARKERS.BEGIN),
102
+ );
103
+ let endIndex = -1;
104
+ for (let i = rawLines.length - 1; i >= 0; i--) {
105
+ if (rawLines[i]?.startsWith(PATCH_MARKERS.END)) {
106
+ endIndex = i;
107
+ break;
108
+ }
109
+ }
110
+
111
+ if (beginIndex !== -1 || endIndex !== -1) {
112
+ if (beginIndex === -1 || endIndex === -1 || endIndex < beginIndex) {
113
+ throw new DiffError(
114
+ "Invalid patch text - incomplete sentinels. Try breaking it into smaller patches.",
115
+ );
116
+ }
117
+ const lines = rawLines.slice(beginIndex, endIndex + 1);
118
+ return {
119
+ lines,
120
+ };
121
+ }
128
122
 
129
- const hasBegin = lines.length > 0 && lines[0].startsWith(PATCH_MARKERS.BEGIN);
130
- const hasEnd =
131
- lines.length > 0 && lines[lines.length - 1] === PATCH_MARKERS.END;
132
- if (!hasBegin && !hasEnd) {
133
- return [PATCH_MARKERS.BEGIN, ...lines, PATCH_MARKERS.END];
123
+ const stripped = trimWrapperLines(rawLines);
124
+ while (stripped.length > 0 && stripped[0] === "") {
125
+ stripped.shift();
134
126
  }
135
- if (hasBegin && hasEnd) {
136
- return lines;
127
+ while (stripped.length > 0 && stripped[stripped.length - 1] === "") {
128
+ stripped.pop();
137
129
  }
138
- throw new DiffError(
139
- "Invalid patch text - incomplete sentinels. Try breaking it into smaller patches.",
140
- );
130
+
131
+ const lines = [PATCH_MARKERS.BEGIN, ...stripped, PATCH_MARKERS.END];
132
+ return {
133
+ lines,
134
+ };
141
135
  }
142
136
 
143
137
  function extractFilesForOperations(
144
- text: string,
138
+ lines: readonly string[],
145
139
  markers: readonly string[],
146
140
  ): string[] {
147
- const lines = stripBashWrapper(text.split("\n"));
148
- const files: string[] = [];
141
+ const files = new Set<string>();
149
142
 
150
143
  for (const line of lines) {
151
144
  for (const marker of markers) {
152
- if (!line.startsWith(marker)) {
153
- continue;
154
- }
155
- const file = line.substring(marker.length).trim();
156
- if (!text.trim().endsWith(file)) {
157
- files.push(file);
145
+ if (line.startsWith(marker)) {
146
+ files.add(line.substring(marker.length).trim());
147
+ break;
158
148
  }
159
- break;
160
149
  }
161
150
  }
162
151
 
163
- return files;
152
+ return [...files];
164
153
  }
165
154
 
166
155
  function applyChunks(
@@ -197,12 +186,12 @@ function applyChunks(
197
186
  }
198
187
 
199
188
  async function loadFiles(
200
- rawInput: string,
189
+ lines: readonly string[],
201
190
  cwd: string,
202
191
  encoding: BufferEncoding,
203
192
  restrictToCwd: boolean,
204
193
  ): Promise<Record<string, string>> {
205
- const filesToLoad = extractFilesForOperations(rawInput, [
194
+ const filesToLoad = extractFilesForOperations(lines, [
206
195
  PATCH_MARKERS.UPDATE,
207
196
  PATCH_MARKERS.DELETE,
208
197
  ]);
@@ -328,14 +317,14 @@ export function createApplyPatchExecutor(
328
317
  cwd: string,
329
318
  _context: ToolContext,
330
319
  ): Promise<string> => {
331
- const lines = preprocessLines(input.input);
320
+ const normalizedInput = normalizePatchInput(input.input);
332
321
  const currentFiles = await loadFiles(
333
- input.input,
322
+ normalizedInput.lines,
334
323
  cwd,
335
324
  encoding,
336
325
  restrictToCwd,
337
326
  );
338
- const parser = new PatchParser(lines, currentFiles);
327
+ const parser = new PatchParser(normalizedInput.lines, currentFiles);
339
328
  const { patch, fuzz } = parser.parse();
340
329
  const changes = patchToChanges(patch, currentFiles);
341
330
  const touched = await applyChanges(changes, cwd, encoding, restrictToCwd);