aws-runtime-bridge 1.9.78 → 1.9.80

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 (596) hide show
  1. package/dist/adapter/AcodeSdkAdapter.d.ts +0 -1
  2. package/dist/adapter/AcodeSdkAdapter.js +11 -1986
  3. package/dist/adapter/AdapterRegistry.d.ts +0 -1
  4. package/dist/adapter/AdapterRegistry.js +2 -100
  5. package/dist/adapter/ClaudeSdkAdapter.d.ts +0 -1
  6. package/dist/adapter/ClaudeSdkAdapter.js +4 -1300
  7. package/dist/adapter/CodexSdkAdapter.d.ts +0 -1
  8. package/dist/adapter/CodexSdkAdapter.js +4 -836
  9. package/dist/adapter/OpencodeSdkAdapter.d.ts +0 -1
  10. package/dist/adapter/OpencodeSdkAdapter.js +4 -879
  11. package/dist/adapter/SdkProviderSpi.d.ts +0 -1
  12. package/dist/adapter/SdkProviderSpi.js +2 -55
  13. package/dist/adapter/acode-tool-names.d.ts +0 -1
  14. package/dist/adapter/acode-tool-names.js +2 -37
  15. package/dist/adapter/idle-poll-loop.d.ts +0 -1
  16. package/dist/adapter/idle-poll-loop.js +2 -59
  17. package/dist/adapter/index.d.ts +0 -1
  18. package/dist/adapter/index.js +2 -11
  19. package/dist/adapter/instance-ai-config-resolver.d.ts +0 -1
  20. package/dist/adapter/instance-ai-config-resolver.js +2 -46
  21. package/dist/adapter/types.d.ts +0 -1
  22. package/dist/adapter/types.js +2 -443
  23. package/dist/adapters/cc-switch/common.d.ts +0 -1
  24. package/dist/adapters/cc-switch/common.js +2 -61
  25. package/dist/adapters/cc-switch/index.d.ts +0 -1
  26. package/dist/adapters/cc-switch/index.js +2 -57
  27. package/dist/adapters/cc-switch/mcp-acode.d.ts +0 -1
  28. package/dist/adapters/cc-switch/mcp-acode.js +2 -71
  29. package/dist/adapters/cc-switch/mcp-claude.d.ts +0 -1
  30. package/dist/adapters/cc-switch/mcp-claude.js +2 -89
  31. package/dist/adapters/cc-switch/mcp-claudecode.d.ts +0 -1
  32. package/dist/adapters/cc-switch/mcp-claudecode.js +2 -77
  33. package/dist/adapters/cc-switch/mcp-codex.d.ts +0 -1
  34. package/dist/adapters/cc-switch/mcp-codex.js +11 -249
  35. package/dist/adapters/cc-switch/mcp-opencode.d.ts +0 -1
  36. package/dist/adapters/cc-switch/mcp-opencode.js +2 -97
  37. package/dist/adapters/cc-switch/mcp-placeholder.d.ts +0 -1
  38. package/dist/adapters/cc-switch/mcp-placeholder.js +2 -19
  39. package/dist/adapters/cc-switch/skill-acode.d.ts +0 -1
  40. package/dist/adapters/cc-switch/skill-acode.js +2 -12
  41. package/dist/adapters/cc-switch/skill-claude.d.ts +0 -1
  42. package/dist/adapters/cc-switch/skill-claude.js +2 -11
  43. package/dist/adapters/cc-switch/skill-claudecode.d.ts +0 -1
  44. package/dist/adapters/cc-switch/skill-claudecode.js +2 -11
  45. package/dist/adapters/cc-switch/skill-codex.d.ts +0 -1
  46. package/dist/adapters/cc-switch/skill-codex.js +2 -6
  47. package/dist/adapters/cc-switch/skill-directory.d.ts +0 -1
  48. package/dist/adapters/cc-switch/skill-directory.js +3 -137
  49. package/dist/adapters/cc-switch/skill-opencode.d.ts +0 -1
  50. package/dist/adapters/cc-switch/skill-opencode.js +2 -11
  51. package/dist/adapters/cc-switch/skill-placeholder.d.ts +0 -1
  52. package/dist/adapters/cc-switch/skill-placeholder.js +2 -19
  53. package/dist/config.d.ts +0 -1
  54. package/dist/config.js +2 -290
  55. package/dist/index.d.ts +0 -1
  56. package/dist/index.js +2 -573
  57. package/dist/middleware/auth.d.ts +0 -1
  58. package/dist/middleware/auth.js +2 -98
  59. package/dist/routes/acode-todos.d.ts +0 -1
  60. package/dist/routes/acode-todos.js +2 -75
  61. package/dist/routes/ai-sources.d.ts +0 -1
  62. package/dist/routes/ai-sources.js +2 -132
  63. package/dist/routes/dashboard.d.ts +0 -1
  64. package/dist/routes/dashboard.js +182 -649
  65. package/dist/routes/events.d.ts +0 -1
  66. package/dist/routes/events.js +2 -22
  67. package/dist/routes/file-browser.d.ts +0 -1
  68. package/dist/routes/file-browser.js +2 -781
  69. package/dist/routes/file-diff-rollback.d.ts +0 -1
  70. package/dist/routes/file-diff-rollback.js +2 -301
  71. package/dist/routes/file-snapshot.d.ts +0 -1
  72. package/dist/routes/file-snapshot.js +2 -156
  73. package/dist/routes/git.d.ts +0 -1
  74. package/dist/routes/git.js +28 -1900
  75. package/dist/routes/instance.d.ts +0 -1
  76. package/dist/routes/instance.js +3 -748
  77. package/dist/routes/mcp.d.ts +0 -1
  78. package/dist/routes/mcp.js +2 -196
  79. package/dist/routes/processes.d.ts +0 -1
  80. package/dist/routes/processes.js +2 -252
  81. package/dist/routes/properties.d.ts +0 -1
  82. package/dist/routes/properties.js +2 -72
  83. package/dist/routes/pty.d.ts +0 -1
  84. package/dist/routes/pty.js +6 -560
  85. package/dist/routes/runtime-binding.d.ts +0 -1
  86. package/dist/routes/runtime-binding.js +2 -263
  87. package/dist/routes/sessions.d.ts +0 -1
  88. package/dist/routes/sessions.js +2 -758
  89. package/dist/routes/skills.d.ts +0 -1
  90. package/dist/routes/skills.js +2 -187
  91. package/dist/routes/sub-agents.d.ts +0 -1
  92. package/dist/routes/sub-agents.js +20 -279
  93. package/dist/routes/system-metrics.d.ts +0 -1
  94. package/dist/routes/system-metrics.js +2 -20
  95. package/dist/routes/task-context.d.ts +0 -1
  96. package/dist/routes/task-context.js +2 -78
  97. package/dist/routes/terminal.d.ts +0 -1
  98. package/dist/routes/terminal.js +54 -2882
  99. package/dist/routes/yml.d.ts +0 -1
  100. package/dist/routes/yml.js +2 -223
  101. package/dist/services/acode-package.d.ts +0 -1
  102. package/dist/services/acode-package.js +2 -111
  103. package/dist/services/agent-event-store.d.ts +0 -1
  104. package/dist/services/agent-event-store.js +2 -81
  105. package/dist/services/agent-process-manager.d.ts +0 -1
  106. package/dist/services/agent-process-manager.js +2 -796
  107. package/dist/services/ai-source-apply.d.ts +0 -1
  108. package/dist/services/ai-source-apply.js +2 -83
  109. package/dist/services/auto-register.d.ts +0 -1
  110. package/dist/services/auto-register.js +2 -1053
  111. package/dist/services/aws-client-agent-mcp.d.ts +0 -1
  112. package/dist/services/aws-client-agent-mcp.js +3 -337
  113. package/dist/services/bridge-package-publish-hooks.d.ts +0 -1
  114. package/dist/services/bridge-package-publish-hooks.js +2 -115
  115. package/dist/services/cc-switch-sdk.d.ts +0 -1
  116. package/dist/services/cc-switch-sdk.js +2 -135
  117. package/dist/services/cli-commands.d.ts +6 -1
  118. package/dist/services/cli-commands.js +6 -645
  119. package/dist/services/event-delta-pusher.d.ts +0 -1
  120. package/dist/services/event-delta-pusher.js +2 -95
  121. package/dist/services/fileSnapshotStore.d.ts +0 -1
  122. package/dist/services/fileSnapshotStore.js +2 -500
  123. package/dist/services/instance-ai-config-service.d.ts +0 -1
  124. package/dist/services/instance-ai-config-service.js +2 -174
  125. package/dist/services/instance-init-service.d.ts +0 -1
  126. package/dist/services/instance-init-service.js +2 -193
  127. package/dist/services/instance-service.d.ts +0 -1
  128. package/dist/services/instance-service.js +2 -237
  129. package/dist/services/instance-state.d.ts +0 -1
  130. package/dist/services/instance-state.js +2 -94
  131. package/dist/services/legacy-path-migration.d.ts +0 -1
  132. package/dist/services/legacy-path-migration.js +2 -66
  133. package/dist/services/lifecycle-state.d.ts +0 -1
  134. package/dist/services/lifecycle-state.js +3 -110
  135. package/dist/services/mcp-launch-binding-queue.d.ts +0 -1
  136. package/dist/services/mcp-launch-binding-queue.js +2 -175
  137. package/dist/services/orphan-monitor.d.ts +0 -1
  138. package/dist/services/orphan-monitor.js +2 -382
  139. package/dist/services/panel-auth.d.ts +0 -1
  140. package/dist/services/panel-auth.js +2 -168
  141. package/dist/services/process-detector.d.ts +0 -1
  142. package/dist/services/process-detector.js +18 -1019
  143. package/dist/services/process-registry.d.ts +0 -1
  144. package/dist/services/process-registry.js +2 -375
  145. package/dist/services/ring-buffer.d.ts +0 -1
  146. package/dist/services/ring-buffer.js +2 -103
  147. package/dist/services/runtime-binding.d.ts +0 -1
  148. package/dist/services/runtime-binding.js +6 -363
  149. package/dist/services/runtime-lifecycle-policy.d.ts +0 -1
  150. package/dist/services/runtime-lifecycle-policy.js +2 -35
  151. package/dist/services/session-output.d.ts +0 -1
  152. package/dist/services/session-output.js +5 -539
  153. package/dist/services/startup-config-wizard.d.ts +0 -1
  154. package/dist/services/startup-config-wizard.js +14 -258
  155. package/dist/services/sub-agent-manager-instance.d.ts +0 -1
  156. package/dist/services/sub-agent-manager-instance.js +2 -12
  157. package/dist/services/system-metrics.d.ts +0 -1
  158. package/dist/services/system-metrics.js +2 -252
  159. package/dist/services/terminal-persistence.d.ts +0 -1
  160. package/dist/services/terminal-persistence.js +2 -176
  161. package/dist/services/tool-installer.d.ts +0 -1
  162. package/dist/services/tool-installer.js +5 -751
  163. package/dist/services/tunnel-client.d.ts +0 -1
  164. package/dist/services/tunnel-client.js +2 -402
  165. package/dist/services/windows-service-manager.d.ts +3 -2
  166. package/dist/services/windows-service-manager.js +2 -54
  167. package/dist/services/workspace-files.d.ts +0 -1
  168. package/dist/services/workspace-files.js +2 -1275
  169. package/dist/services/workspace-watch.d.ts +0 -1
  170. package/dist/services/workspace-watch.js +2 -123
  171. package/dist/services/workspaceTaskChangeWatcher.d.ts +0 -1
  172. package/dist/services/workspaceTaskChangeWatcher.js +2 -483
  173. package/dist/types.d.ts +0 -1
  174. package/dist/types.js +1 -1
  175. package/dist/utils/file-utils.d.ts +0 -1
  176. package/dist/utils/file-utils.js +3 -208
  177. package/dist/utils/instance-ai-config-debug-logger.d.ts +0 -1
  178. package/dist/utils/instance-ai-config-debug-logger.js +4 -63
  179. package/dist/utils/logger.d.ts +0 -1
  180. package/dist/utils/logger.js +2 -154
  181. package/dist/utils/mcp-utils.d.ts +0 -1
  182. package/dist/utils/mcp-utils.js +2 -187
  183. package/dist/utils/path-utils.d.ts +0 -1
  184. package/dist/utils/path-utils.js +2 -44
  185. package/dist/utils/sdk-package-loader.d.ts +0 -1
  186. package/dist/utils/sdk-package-loader.js +2 -78
  187. package/dist/utils/validation.d.ts +0 -1
  188. package/dist/utils/validation.js +2 -53
  189. package/dist/utils/yaml-utils.d.ts +0 -1
  190. package/dist/utils/yaml-utils.js +2 -312
  191. package/node_modules/@cc-switch/sdk/dist/constants.d.ts +0 -1
  192. package/node_modules/@cc-switch/sdk/dist/constants.js +2 -63
  193. package/node_modules/@cc-switch/sdk/dist/errors.d.ts +0 -1
  194. package/node_modules/@cc-switch/sdk/dist/errors.js +2 -8
  195. package/node_modules/@cc-switch/sdk/dist/index.d.ts +0 -1
  196. package/node_modules/@cc-switch/sdk/dist/index.js +2 -9
  197. package/node_modules/@cc-switch/sdk/dist/schemas.d.ts +0 -1
  198. package/node_modules/@cc-switch/sdk/dist/schemas.js +2 -38
  199. package/node_modules/@cc-switch/sdk/dist/sdk.d.ts +0 -1
  200. package/node_modules/@cc-switch/sdk/dist/sdk.js +2 -470
  201. package/node_modules/@cc-switch/sdk/dist/services/ai-config-service.d.ts +0 -1
  202. package/node_modules/@cc-switch/sdk/dist/services/ai-config-service.js +4 -307
  203. package/node_modules/@cc-switch/sdk/dist/services/mcp-model.d.ts +0 -1
  204. package/node_modules/@cc-switch/sdk/dist/services/mcp-model.js +2 -37
  205. package/node_modules/@cc-switch/sdk/dist/services/mcp-service.d.ts +0 -1
  206. package/node_modules/@cc-switch/sdk/dist/services/mcp-service.js +2 -9
  207. package/node_modules/@cc-switch/sdk/dist/services/skill-model.d.ts +0 -1
  208. package/node_modules/@cc-switch/sdk/dist/services/skill-model.js +2 -41
  209. package/node_modules/@cc-switch/sdk/dist/services/skill-service.d.ts +0 -1
  210. package/node_modules/@cc-switch/sdk/dist/services/skill-service.js +2 -9
  211. package/node_modules/@cc-switch/sdk/dist/state.d.ts +0 -1
  212. package/node_modules/@cc-switch/sdk/dist/state.js +2 -19
  213. package/node_modules/@cc-switch/sdk/dist/types.d.ts +0 -1
  214. package/node_modules/@cc-switch/sdk/dist/types.js +1 -1
  215. package/node_modules/@cc-switch/sdk/dist/utils/fs.d.ts +0 -1
  216. package/node_modules/@cc-switch/sdk/dist/utils/fs.js +3 -114
  217. package/node_modules/@cc-switch/sdk/dist/utils/id.d.ts +0 -1
  218. package/node_modules/@cc-switch/sdk/dist/utils/id.js +2 -12
  219. package/node_modules/@cc-switch/sdk/package.json +1 -1
  220. package/package/acode/dist/ask-user-question-tool.d.ts +0 -1
  221. package/package/acode/dist/ask-user-question-tool.js +4 -233
  222. package/package/acode/dist/built-in-file-tools.d.ts +0 -1
  223. package/package/acode/dist/built-in-file-tools.js +4 -966
  224. package/package/acode/dist/built-in-symbols-tool.d.ts +0 -1
  225. package/package/acode/dist/built-in-symbols-tool.js +2 -117
  226. package/package/acode/dist/builtins/commandArtifacts.d.ts +0 -1
  227. package/package/acode/dist/builtins/commandArtifacts.js +9 -97
  228. package/package/acode/dist/builtins/commandOutputEvents.d.ts +0 -1
  229. package/package/acode/dist/builtins/commandOutputEvents.js +2 -56
  230. package/package/acode/dist/builtins/shellCommandPreparation.d.ts +0 -1
  231. package/package/acode/dist/builtins/shellCommandPreparation.js +5 -44
  232. package/package/acode/dist/builtins/shellCommandResult.d.ts +0 -1
  233. package/package/acode/dist/builtins/shellCommandResult.js +2 -71
  234. package/package/acode/dist/builtins/shellCommandRunner.d.ts +0 -1
  235. package/package/acode/dist/builtins/shellCommandRunner.js +2 -115
  236. package/package/acode/dist/builtins/shellOutputDecoder.d.ts +0 -1
  237. package/package/acode/dist/builtins/shellOutputDecoder.js +2 -94
  238. package/package/acode/dist/cli.d.ts +0 -1
  239. package/package/acode/dist/cli.js +4 -38
  240. package/package/acode/dist/commands/commandLoader.d.ts +0 -1
  241. package/package/acode/dist/commands/commandLoader.js +2 -33
  242. package/package/acode/dist/commands/commandParser.d.ts +0 -1
  243. package/package/acode/dist/commands/commandParser.js +3 -77
  244. package/package/acode/dist/commands/commandRegistry.d.ts +0 -1
  245. package/package/acode/dist/commands/commandRegistry.js +2 -30
  246. package/package/acode/dist/compaction.d.ts +0 -1
  247. package/package/acode/dist/compaction.js +7 -919
  248. package/package/acode/dist/config.d.ts +0 -1
  249. package/package/acode/dist/config.js +5 -105
  250. package/package/acode/dist/fs-utils.d.ts +0 -1
  251. package/package/acode/dist/fs-utils.js +2 -79
  252. package/package/acode/dist/hooks/hookBus.d.ts +0 -1
  253. package/package/acode/dist/hooks/hookBus.js +2 -40
  254. package/package/acode/dist/index.d.ts +0 -1
  255. package/package/acode/dist/index.js +2 -19
  256. package/package/acode/dist/mcpToolNames.d.ts +0 -1
  257. package/package/acode/dist/mcpToolNames.js +2 -17
  258. package/package/acode/dist/parsers/ast-cache.d.ts +0 -1
  259. package/package/acode/dist/parsers/ast-cache.js +2 -76
  260. package/package/acode/dist/parsers/language-detector.d.ts +0 -1
  261. package/package/acode/dist/parsers/language-detector.js +2 -44
  262. package/package/acode/dist/parsers/language-queries.d.ts +0 -1
  263. package/package/acode/dist/parsers/language-queries.js +12 -602
  264. package/package/acode/dist/parsers/symbol-extractor.d.ts +0 -1
  265. package/package/acode/dist/parsers/symbol-extractor.js +3 -164
  266. package/package/acode/dist/parsers/tree-sitter-loader.d.ts +0 -1
  267. package/package/acode/dist/parsers/tree-sitter-loader.js +2 -64
  268. package/package/acode/dist/parsers/types.d.ts +0 -1
  269. package/package/acode/dist/parsers/types.js +1 -7
  270. package/package/acode/dist/runtime.d.ts +0 -1
  271. package/package/acode/dist/runtime.js +86 -3771
  272. package/package/acode/dist/skill-tool.d.ts +0 -1
  273. package/package/acode/dist/skill-tool.js +5 -174
  274. package/package/acode/dist/sub-agent-manager.d.ts +0 -1
  275. package/package/acode/dist/sub-agent-manager.js +2 -1159
  276. package/package/acode/dist/sub-agent-store.d.ts +0 -1
  277. package/package/acode/dist/sub-agent-store.js +4 -236
  278. package/package/acode/dist/sub-agent-tools.d.ts +0 -1
  279. package/package/acode/dist/sub-agent-tools.js +15 -369
  280. package/package/acode/dist/sub-agent-types.d.ts +0 -1
  281. package/package/acode/dist/sub-agent-types.js +1 -8
  282. package/package/acode/dist/todo-store.d.ts +0 -1
  283. package/package/acode/dist/todo-store.js +2 -73
  284. package/package/acode/dist/todo-tool.d.ts +0 -1
  285. package/package/acode/dist/todo-tool.js +5 -121
  286. package/package/acode/dist/types.d.ts +0 -1
  287. package/package/acode/dist/types.js +1 -1
  288. package/package/acode/package.json +2 -2
  289. package/package/aws-client-agent-mcp/dist/agent-client.d.ts +0 -1
  290. package/package/aws-client-agent-mcp/dist/agent-client.js +2 -890
  291. package/package/aws-client-agent-mcp/dist/agent-client.test.d.ts +0 -1
  292. package/package/aws-client-agent-mcp/dist/agent-client.test.js +0 -1
  293. package/package/aws-client-agent-mcp/dist/config.d.ts +0 -1
  294. package/package/aws-client-agent-mcp/dist/config.js +2 -243
  295. package/package/aws-client-agent-mcp/dist/config.test.d.ts +0 -1
  296. package/package/aws-client-agent-mcp/dist/config.test.js +0 -1
  297. package/package/aws-client-agent-mcp/dist/constants.d.ts +0 -1
  298. package/package/aws-client-agent-mcp/dist/constants.js +2 -24
  299. package/package/aws-client-agent-mcp/dist/context-manager.d.ts +0 -1
  300. package/package/aws-client-agent-mcp/dist/context-manager.js +2 -477
  301. package/package/aws-client-agent-mcp/dist/context-manager.test.d.ts +0 -1
  302. package/package/aws-client-agent-mcp/dist/context-manager.test.js +0 -1
  303. package/package/aws-client-agent-mcp/dist/http-client.d.ts +0 -1
  304. package/package/aws-client-agent-mcp/dist/http-client.js +2 -446
  305. package/package/aws-client-agent-mcp/dist/http-client.test.d.ts +0 -1
  306. package/package/aws-client-agent-mcp/dist/http-client.test.js +0 -1
  307. package/package/aws-client-agent-mcp/dist/index.d.ts +0 -1
  308. package/package/aws-client-agent-mcp/dist/index.js +2 -34
  309. package/package/aws-client-agent-mcp/dist/logger.d.ts +0 -1
  310. package/package/aws-client-agent-mcp/dist/logger.js +3 -178
  311. package/package/aws-client-agent-mcp/dist/logger.test.d.ts +0 -1
  312. package/package/aws-client-agent-mcp/dist/logger.test.js +0 -1
  313. package/package/aws-client-agent-mcp/dist/mcp-server.d.ts +0 -1
  314. package/package/aws-client-agent-mcp/dist/mcp-server.js +38 -2709
  315. package/package/aws-client-agent-mcp/dist/mcp-server.test.d.ts +0 -1
  316. package/package/aws-client-agent-mcp/dist/mcp-server.test.js +0 -1
  317. package/package/aws-client-agent-mcp/dist/mcp-tools.d.ts +0 -1
  318. package/package/aws-client-agent-mcp/dist/mcp-tools.js +22 -562
  319. package/package/aws-client-agent-mcp/dist/mcp-tools.test.d.ts +0 -1
  320. package/package/aws-client-agent-mcp/dist/mcp-tools.test.js +0 -1
  321. package/package/aws-client-agent-mcp/dist/memory-store.d.ts +0 -1
  322. package/package/aws-client-agent-mcp/dist/memory-store.js +4 -826
  323. package/package/aws-client-agent-mcp/dist/memory-store.test.d.ts +0 -1
  324. package/package/aws-client-agent-mcp/dist/memory-store.test.js +0 -1
  325. package/package/aws-client-agent-mcp/dist/memory-tools.d.ts +0 -1
  326. package/package/aws-client-agent-mcp/dist/memory-tools.js +31 -294
  327. package/package/aws-client-agent-mcp/dist/message-buffer.d.ts +0 -1
  328. package/package/aws-client-agent-mcp/dist/message-buffer.js +2 -288
  329. package/package/aws-client-agent-mcp/dist/message-buffer.test.d.ts +0 -1
  330. package/package/aws-client-agent-mcp/dist/message-buffer.test.js +0 -1
  331. package/package/aws-client-agent-mcp/dist/messageContent.d.ts +0 -1
  332. package/package/aws-client-agent-mcp/dist/messageContent.js +2 -125
  333. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.d.ts +0 -1
  334. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.js +2 -103
  335. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.test.d.ts +0 -1
  336. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.test.js +0 -1
  337. package/package/aws-client-agent-mcp/dist/server-memory-store.d.ts +0 -1
  338. package/package/aws-client-agent-mcp/dist/server-memory-store.js +2 -96
  339. package/package/aws-client-agent-mcp/dist/status-reporter.d.ts +0 -1
  340. package/package/aws-client-agent-mcp/dist/status-reporter.js +3 -327
  341. package/package/aws-client-agent-mcp/dist/status-reporter.test.d.ts +0 -1
  342. package/package/aws-client-agent-mcp/dist/status-reporter.test.js +0 -1
  343. package/package/aws-client-agent-mcp/dist/types.d.ts +0 -1
  344. package/package/aws-client-agent-mcp/dist/types.js +2 -9
  345. package/package/aws-client-agent-mcp/dist/websocket-client.d.ts +0 -1
  346. package/package/aws-client-agent-mcp/dist/websocket-client.js +2 -677
  347. package/package/aws-client-agent-mcp/dist/websocket-client.test.d.ts +0 -1
  348. package/package/aws-client-agent-mcp/dist/websocket-client.test.js +0 -1
  349. package/package/aws-client-agent-mcp/package.json +1 -1
  350. package/package/cc-switch-sdk/dist/constants.d.ts +0 -1
  351. package/package/cc-switch-sdk/dist/constants.js +2 -63
  352. package/package/cc-switch-sdk/dist/errors.d.ts +0 -1
  353. package/package/cc-switch-sdk/dist/errors.js +2 -8
  354. package/package/cc-switch-sdk/dist/index.d.ts +0 -1
  355. package/package/cc-switch-sdk/dist/index.js +2 -9
  356. package/package/cc-switch-sdk/dist/schemas.d.ts +0 -1
  357. package/package/cc-switch-sdk/dist/schemas.js +2 -38
  358. package/package/cc-switch-sdk/dist/sdk.d.ts +0 -1
  359. package/package/cc-switch-sdk/dist/sdk.js +2 -470
  360. package/package/cc-switch-sdk/dist/services/ai-config-service.d.ts +0 -1
  361. package/package/cc-switch-sdk/dist/services/ai-config-service.js +4 -307
  362. package/package/cc-switch-sdk/dist/services/mcp-model.d.ts +0 -1
  363. package/package/cc-switch-sdk/dist/services/mcp-model.js +2 -37
  364. package/package/cc-switch-sdk/dist/services/mcp-service.d.ts +0 -1
  365. package/package/cc-switch-sdk/dist/services/mcp-service.js +2 -9
  366. package/package/cc-switch-sdk/dist/services/skill-model.d.ts +0 -1
  367. package/package/cc-switch-sdk/dist/services/skill-model.js +2 -41
  368. package/package/cc-switch-sdk/dist/services/skill-service.d.ts +0 -1
  369. package/package/cc-switch-sdk/dist/services/skill-service.js +2 -9
  370. package/package/cc-switch-sdk/dist/state.d.ts +0 -1
  371. package/package/cc-switch-sdk/dist/state.js +2 -19
  372. package/package/cc-switch-sdk/dist/types.d.ts +0 -1
  373. package/package/cc-switch-sdk/dist/types.js +1 -1
  374. package/package/cc-switch-sdk/dist/utils/fs.d.ts +0 -1
  375. package/package/cc-switch-sdk/dist/utils/fs.js +3 -114
  376. package/package/cc-switch-sdk/dist/utils/id.d.ts +0 -1
  377. package/package/cc-switch-sdk/dist/utils/id.js +2 -12
  378. package/package/cc-switch-sdk/package.json +1 -1
  379. package/package.json +4 -2
  380. package/dist/adapter/AcodeSdkAdapter.d.ts.map +0 -1
  381. package/dist/adapter/AdapterRegistry.d.ts.map +0 -1
  382. package/dist/adapter/ClaudeSdkAdapter.d.ts.map +0 -1
  383. package/dist/adapter/CodexSdkAdapter.d.ts.map +0 -1
  384. package/dist/adapter/OpencodeSdkAdapter.d.ts.map +0 -1
  385. package/dist/adapter/SdkProviderSpi.d.ts.map +0 -1
  386. package/dist/adapter/acode-tool-names.d.ts.map +0 -1
  387. package/dist/adapter/idle-poll-loop.d.ts.map +0 -1
  388. package/dist/adapter/index.d.ts.map +0 -1
  389. package/dist/adapter/instance-ai-config-resolver.d.ts.map +0 -1
  390. package/dist/adapter/types.d.ts.map +0 -1
  391. package/dist/adapters/cc-switch/common.d.ts.map +0 -1
  392. package/dist/adapters/cc-switch/index.d.ts.map +0 -1
  393. package/dist/adapters/cc-switch/mcp-acode.d.ts.map +0 -1
  394. package/dist/adapters/cc-switch/mcp-claude.d.ts.map +0 -1
  395. package/dist/adapters/cc-switch/mcp-claudecode.d.ts.map +0 -1
  396. package/dist/adapters/cc-switch/mcp-codex.d.ts.map +0 -1
  397. package/dist/adapters/cc-switch/mcp-opencode.d.ts.map +0 -1
  398. package/dist/adapters/cc-switch/mcp-placeholder.d.ts.map +0 -1
  399. package/dist/adapters/cc-switch/skill-acode.d.ts.map +0 -1
  400. package/dist/adapters/cc-switch/skill-claude.d.ts.map +0 -1
  401. package/dist/adapters/cc-switch/skill-claudecode.d.ts.map +0 -1
  402. package/dist/adapters/cc-switch/skill-codex.d.ts.map +0 -1
  403. package/dist/adapters/cc-switch/skill-directory.d.ts.map +0 -1
  404. package/dist/adapters/cc-switch/skill-opencode.d.ts.map +0 -1
  405. package/dist/adapters/cc-switch/skill-placeholder.d.ts.map +0 -1
  406. package/dist/config.d.ts.map +0 -1
  407. package/dist/index.d.ts.map +0 -1
  408. package/dist/middleware/auth.d.ts.map +0 -1
  409. package/dist/routes/acode-todos.d.ts.map +0 -1
  410. package/dist/routes/ai-sources.d.ts.map +0 -1
  411. package/dist/routes/dashboard.d.ts.map +0 -1
  412. package/dist/routes/events.d.ts.map +0 -1
  413. package/dist/routes/file-browser.d.ts.map +0 -1
  414. package/dist/routes/file-diff-rollback.d.ts.map +0 -1
  415. package/dist/routes/file-snapshot.d.ts.map +0 -1
  416. package/dist/routes/git.d.ts.map +0 -1
  417. package/dist/routes/instance.d.ts.map +0 -1
  418. package/dist/routes/mcp.d.ts.map +0 -1
  419. package/dist/routes/processes.d.ts.map +0 -1
  420. package/dist/routes/properties.d.ts.map +0 -1
  421. package/dist/routes/pty.d.ts.map +0 -1
  422. package/dist/routes/runtime-binding.d.ts.map +0 -1
  423. package/dist/routes/sessions.d.ts.map +0 -1
  424. package/dist/routes/skills.d.ts.map +0 -1
  425. package/dist/routes/sub-agents.d.ts.map +0 -1
  426. package/dist/routes/system-metrics.d.ts.map +0 -1
  427. package/dist/routes/task-context.d.ts.map +0 -1
  428. package/dist/routes/terminal.d.ts.map +0 -1
  429. package/dist/routes/yml.d.ts.map +0 -1
  430. package/dist/services/acode-package.d.ts.map +0 -1
  431. package/dist/services/agent-event-store.d.ts.map +0 -1
  432. package/dist/services/agent-process-manager.d.ts.map +0 -1
  433. package/dist/services/ai-source-apply.d.ts.map +0 -1
  434. package/dist/services/auto-register.d.ts.map +0 -1
  435. package/dist/services/aws-client-agent-mcp.d.ts.map +0 -1
  436. package/dist/services/bridge-package-publish-hooks.d.ts.map +0 -1
  437. package/dist/services/cc-switch-sdk.d.ts.map +0 -1
  438. package/dist/services/cli-commands.d.ts.map +0 -1
  439. package/dist/services/event-delta-pusher.d.ts.map +0 -1
  440. package/dist/services/fileSnapshotStore.d.ts.map +0 -1
  441. package/dist/services/instance-ai-config-service.d.ts.map +0 -1
  442. package/dist/services/instance-init-service.d.ts.map +0 -1
  443. package/dist/services/instance-service.d.ts.map +0 -1
  444. package/dist/services/instance-state.d.ts.map +0 -1
  445. package/dist/services/legacy-path-migration.d.ts.map +0 -1
  446. package/dist/services/lifecycle-state.d.ts.map +0 -1
  447. package/dist/services/mcp-launch-binding-queue.d.ts.map +0 -1
  448. package/dist/services/orphan-monitor.d.ts.map +0 -1
  449. package/dist/services/panel-auth.d.ts.map +0 -1
  450. package/dist/services/process-detector.d.ts.map +0 -1
  451. package/dist/services/process-registry.d.ts.map +0 -1
  452. package/dist/services/ring-buffer.d.ts.map +0 -1
  453. package/dist/services/runtime-binding.d.ts.map +0 -1
  454. package/dist/services/runtime-lifecycle-policy.d.ts.map +0 -1
  455. package/dist/services/session-output.d.ts.map +0 -1
  456. package/dist/services/startup-config-wizard.d.ts.map +0 -1
  457. package/dist/services/sub-agent-manager-instance.d.ts.map +0 -1
  458. package/dist/services/system-metrics.d.ts.map +0 -1
  459. package/dist/services/terminal-persistence.d.ts.map +0 -1
  460. package/dist/services/tool-installer.d.ts.map +0 -1
  461. package/dist/services/tunnel-client.d.ts.map +0 -1
  462. package/dist/services/windows-service-manager.d.ts.map +0 -1
  463. package/dist/services/workspace-files.d.ts.map +0 -1
  464. package/dist/services/workspace-watch.d.ts.map +0 -1
  465. package/dist/services/workspaceTaskChangeWatcher.d.ts.map +0 -1
  466. package/dist/types.d.ts.map +0 -1
  467. package/dist/utils/file-utils.d.ts.map +0 -1
  468. package/dist/utils/instance-ai-config-debug-logger.d.ts.map +0 -1
  469. package/dist/utils/logger.d.ts.map +0 -1
  470. package/dist/utils/mcp-utils.d.ts.map +0 -1
  471. package/dist/utils/path-utils.d.ts.map +0 -1
  472. package/dist/utils/sdk-package-loader.d.ts.map +0 -1
  473. package/dist/utils/validation.d.ts.map +0 -1
  474. package/dist/utils/yaml-utils.d.ts.map +0 -1
  475. package/node_modules/@cc-switch/sdk/dist/constants.d.ts.map +0 -1
  476. package/node_modules/@cc-switch/sdk/dist/errors.d.ts.map +0 -1
  477. package/node_modules/@cc-switch/sdk/dist/index.d.ts.map +0 -1
  478. package/node_modules/@cc-switch/sdk/dist/schemas.d.ts.map +0 -1
  479. package/node_modules/@cc-switch/sdk/dist/sdk.d.ts.map +0 -1
  480. package/node_modules/@cc-switch/sdk/dist/services/ai-config-service.d.ts.map +0 -1
  481. package/node_modules/@cc-switch/sdk/dist/services/mcp-model.d.ts.map +0 -1
  482. package/node_modules/@cc-switch/sdk/dist/services/mcp-service.d.ts.map +0 -1
  483. package/node_modules/@cc-switch/sdk/dist/services/skill-model.d.ts.map +0 -1
  484. package/node_modules/@cc-switch/sdk/dist/services/skill-service.d.ts.map +0 -1
  485. package/node_modules/@cc-switch/sdk/dist/state.d.ts.map +0 -1
  486. package/node_modules/@cc-switch/sdk/dist/types.d.ts.map +0 -1
  487. package/node_modules/@cc-switch/sdk/dist/utils/fs.d.ts.map +0 -1
  488. package/node_modules/@cc-switch/sdk/dist/utils/id.d.ts.map +0 -1
  489. package/package/acode/dist/ask-user-question-tool.d.ts.map +0 -1
  490. package/package/acode/dist/built-in-file-tools.d.ts.map +0 -1
  491. package/package/acode/dist/built-in-symbols-tool.d.ts.map +0 -1
  492. package/package/acode/dist/builtins/commandArtifacts.d.ts.map +0 -1
  493. package/package/acode/dist/builtins/commandOutputEvents.d.ts.map +0 -1
  494. package/package/acode/dist/builtins/shellCommandPreparation.d.ts.map +0 -1
  495. package/package/acode/dist/builtins/shellCommandResult.d.ts.map +0 -1
  496. package/package/acode/dist/builtins/shellCommandRunner.d.ts.map +0 -1
  497. package/package/acode/dist/builtins/shellOutputDecoder.d.ts.map +0 -1
  498. package/package/acode/dist/cli.d.ts.map +0 -1
  499. package/package/acode/dist/commands/commandLoader.d.ts.map +0 -1
  500. package/package/acode/dist/commands/commandParser.d.ts.map +0 -1
  501. package/package/acode/dist/commands/commandRegistry.d.ts.map +0 -1
  502. package/package/acode/dist/compaction.d.ts.map +0 -1
  503. package/package/acode/dist/config.d.ts.map +0 -1
  504. package/package/acode/dist/fs-utils.d.ts.map +0 -1
  505. package/package/acode/dist/hooks/hookBus.d.ts.map +0 -1
  506. package/package/acode/dist/index.d.ts.map +0 -1
  507. package/package/acode/dist/mcpToolNames.d.ts.map +0 -1
  508. package/package/acode/dist/parsers/ast-cache.d.ts.map +0 -1
  509. package/package/acode/dist/parsers/language-detector.d.ts.map +0 -1
  510. package/package/acode/dist/parsers/language-queries.d.ts.map +0 -1
  511. package/package/acode/dist/parsers/symbol-extractor.d.ts.map +0 -1
  512. package/package/acode/dist/parsers/tree-sitter-loader.d.ts.map +0 -1
  513. package/package/acode/dist/parsers/types.d.ts.map +0 -1
  514. package/package/acode/dist/runtime.d.ts.map +0 -1
  515. package/package/acode/dist/skill-tool.d.ts.map +0 -1
  516. package/package/acode/dist/sub-agent-manager.d.ts.map +0 -1
  517. package/package/acode/dist/sub-agent-store.d.ts.map +0 -1
  518. package/package/acode/dist/sub-agent-tools.d.ts.map +0 -1
  519. package/package/acode/dist/sub-agent-types.d.ts.map +0 -1
  520. package/package/acode/dist/todo-store.d.ts.map +0 -1
  521. package/package/acode/dist/todo-tool.d.ts.map +0 -1
  522. package/package/acode/dist/types.d.ts.map +0 -1
  523. package/package/aws-client-agent-mcp/dist/agent-client.d.ts.map +0 -1
  524. package/package/aws-client-agent-mcp/dist/agent-client.js.map +0 -1
  525. package/package/aws-client-agent-mcp/dist/agent-client.test.d.ts.map +0 -1
  526. package/package/aws-client-agent-mcp/dist/agent-client.test.js.map +0 -1
  527. package/package/aws-client-agent-mcp/dist/config.d.ts.map +0 -1
  528. package/package/aws-client-agent-mcp/dist/config.js.map +0 -1
  529. package/package/aws-client-agent-mcp/dist/config.test.d.ts.map +0 -1
  530. package/package/aws-client-agent-mcp/dist/config.test.js.map +0 -1
  531. package/package/aws-client-agent-mcp/dist/constants.d.ts.map +0 -1
  532. package/package/aws-client-agent-mcp/dist/constants.js.map +0 -1
  533. package/package/aws-client-agent-mcp/dist/context-manager.d.ts.map +0 -1
  534. package/package/aws-client-agent-mcp/dist/context-manager.js.map +0 -1
  535. package/package/aws-client-agent-mcp/dist/context-manager.test.d.ts.map +0 -1
  536. package/package/aws-client-agent-mcp/dist/context-manager.test.js.map +0 -1
  537. package/package/aws-client-agent-mcp/dist/http-client.d.ts.map +0 -1
  538. package/package/aws-client-agent-mcp/dist/http-client.js.map +0 -1
  539. package/package/aws-client-agent-mcp/dist/http-client.test.d.ts.map +0 -1
  540. package/package/aws-client-agent-mcp/dist/http-client.test.js.map +0 -1
  541. package/package/aws-client-agent-mcp/dist/index.d.ts.map +0 -1
  542. package/package/aws-client-agent-mcp/dist/index.js.map +0 -1
  543. package/package/aws-client-agent-mcp/dist/logger.d.ts.map +0 -1
  544. package/package/aws-client-agent-mcp/dist/logger.js.map +0 -1
  545. package/package/aws-client-agent-mcp/dist/logger.test.d.ts.map +0 -1
  546. package/package/aws-client-agent-mcp/dist/logger.test.js.map +0 -1
  547. package/package/aws-client-agent-mcp/dist/mcp-server.d.ts.map +0 -1
  548. package/package/aws-client-agent-mcp/dist/mcp-server.js.map +0 -1
  549. package/package/aws-client-agent-mcp/dist/mcp-server.test.d.ts.map +0 -1
  550. package/package/aws-client-agent-mcp/dist/mcp-server.test.js.map +0 -1
  551. package/package/aws-client-agent-mcp/dist/mcp-tools.d.ts.map +0 -1
  552. package/package/aws-client-agent-mcp/dist/mcp-tools.js.map +0 -1
  553. package/package/aws-client-agent-mcp/dist/mcp-tools.test.d.ts.map +0 -1
  554. package/package/aws-client-agent-mcp/dist/mcp-tools.test.js.map +0 -1
  555. package/package/aws-client-agent-mcp/dist/memory-store.d.ts.map +0 -1
  556. package/package/aws-client-agent-mcp/dist/memory-store.js.map +0 -1
  557. package/package/aws-client-agent-mcp/dist/memory-store.test.d.ts.map +0 -1
  558. package/package/aws-client-agent-mcp/dist/memory-store.test.js.map +0 -1
  559. package/package/aws-client-agent-mcp/dist/memory-tools.d.ts.map +0 -1
  560. package/package/aws-client-agent-mcp/dist/memory-tools.js.map +0 -1
  561. package/package/aws-client-agent-mcp/dist/message-buffer.d.ts.map +0 -1
  562. package/package/aws-client-agent-mcp/dist/message-buffer.js.map +0 -1
  563. package/package/aws-client-agent-mcp/dist/message-buffer.test.d.ts.map +0 -1
  564. package/package/aws-client-agent-mcp/dist/message-buffer.test.js.map +0 -1
  565. package/package/aws-client-agent-mcp/dist/messageContent.d.ts.map +0 -1
  566. package/package/aws-client-agent-mcp/dist/messageContent.js.map +0 -1
  567. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.d.ts.map +0 -1
  568. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.js.map +0 -1
  569. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.test.d.ts.map +0 -1
  570. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.test.js.map +0 -1
  571. package/package/aws-client-agent-mcp/dist/server-memory-store.d.ts.map +0 -1
  572. package/package/aws-client-agent-mcp/dist/server-memory-store.js.map +0 -1
  573. package/package/aws-client-agent-mcp/dist/status-reporter.d.ts.map +0 -1
  574. package/package/aws-client-agent-mcp/dist/status-reporter.js.map +0 -1
  575. package/package/aws-client-agent-mcp/dist/status-reporter.test.d.ts.map +0 -1
  576. package/package/aws-client-agent-mcp/dist/status-reporter.test.js.map +0 -1
  577. package/package/aws-client-agent-mcp/dist/types.d.ts.map +0 -1
  578. package/package/aws-client-agent-mcp/dist/types.js.map +0 -1
  579. package/package/aws-client-agent-mcp/dist/websocket-client.d.ts.map +0 -1
  580. package/package/aws-client-agent-mcp/dist/websocket-client.js.map +0 -1
  581. package/package/aws-client-agent-mcp/dist/websocket-client.test.d.ts.map +0 -1
  582. package/package/aws-client-agent-mcp/dist/websocket-client.test.js.map +0 -1
  583. package/package/cc-switch-sdk/dist/constants.d.ts.map +0 -1
  584. package/package/cc-switch-sdk/dist/errors.d.ts.map +0 -1
  585. package/package/cc-switch-sdk/dist/index.d.ts.map +0 -1
  586. package/package/cc-switch-sdk/dist/schemas.d.ts.map +0 -1
  587. package/package/cc-switch-sdk/dist/sdk.d.ts.map +0 -1
  588. package/package/cc-switch-sdk/dist/services/ai-config-service.d.ts.map +0 -1
  589. package/package/cc-switch-sdk/dist/services/mcp-model.d.ts.map +0 -1
  590. package/package/cc-switch-sdk/dist/services/mcp-service.d.ts.map +0 -1
  591. package/package/cc-switch-sdk/dist/services/skill-model.d.ts.map +0 -1
  592. package/package/cc-switch-sdk/dist/services/skill-service.d.ts.map +0 -1
  593. package/package/cc-switch-sdk/dist/state.d.ts.map +0 -1
  594. package/package/cc-switch-sdk/dist/types.d.ts.map +0 -1
  595. package/package/cc-switch-sdk/dist/utils/fs.d.ts.map +0 -1
  596. package/package/cc-switch-sdk/dist/utils/id.d.ts.map +0 -1
@@ -1,966 +1,4 @@
1
- import { randomUUID } from "node:crypto";
2
- import { promises as fs, createReadStream } from "node:fs";
3
- import path from "node:path";
4
- import readline from "node:readline";
5
- import { runShellCommand, } from "./builtins/shellCommandRunner.js";
6
- import { symbolsTool } from "./built-in-symbols-tool.js";
7
- // ── read_file pagination & truncation constants ──────────────────────────────
8
- const DEFAULT_READ_LIMIT = 2000;
9
- const MAX_LINE_LENGTH = 2000;
10
- const MAX_READ_BYTES = 50 * 1024; // 50 KB
11
- const BINARY_SAMPLE_BYTES = 4096;
12
- const BINARY_NON_PRINTABLE_RATIO = 0.3;
13
- const BINARY_EXTENSIONS = new Set([
14
- ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".webp", ".tiff", ".tif",
15
- ".zip", ".gz", ".tar", ".rar", ".7z", ".bz2", ".xz", ".lz",
16
- ".exe", ".dll", ".so", ".dylib", ".bin", ".o", ".a",
17
- ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",
18
- ".mp3", ".mp4", ".avi", ".mov", ".wav", ".flv", ".mkv", ".ogg",
19
- ".woff", ".woff2", ".ttf", ".otf", ".eot",
20
- ".class", ".jar", ".war", ".ear",
21
- ".pyc", ".pyo", ".node",
22
- ".sqlite", ".db", ".mdb",
23
- ".wasm",
24
- ]);
25
- // ─────────────────────────────────────────────────────────────────────────────
26
- // ── grep search constants ────────────────────────────────────────────────────
27
- const MAX_GREP_FILES = 1000;
28
- const MAX_GREP_FILE_SIZE = 1024 * 1024; // 1 MB – skip larger files
29
- const MAX_GREP_OUTPUT_BYTES = 256 * 1024; // 256 KB – cap total output
30
- const DEFAULT_GREP_MAX_RESULTS = 1000;
31
- const GREP_SKIP_DIRS = new Set([
32
- ".git", "node_modules", "dist", "build", ".next", ".nuxt",
33
- ".cache", ".turbo", ".output", "coverage", ".nyc_output",
34
- ]);
35
- function toDisplayPath(targetPath) {
36
- return targetPath.replace(/\\/g, "/");
37
- }
38
- async function pathExists(targetPath) {
39
- try {
40
- await fs.access(targetPath);
41
- return true;
42
- }
43
- catch {
44
- return false;
45
- }
46
- }
47
- function countOccurrences(content, search) {
48
- if (!search) {
49
- return 0;
50
- }
51
- let count = 0;
52
- let index = content.indexOf(search);
53
- while (index >= 0) {
54
- count += 1;
55
- index = content.indexOf(search, index + search.length);
56
- }
57
- return count;
58
- }
59
- function readStringArg(args, names, label) {
60
- for (const name of names) {
61
- const value = args[name];
62
- if (typeof value === "string") {
63
- return value;
64
- }
65
- }
66
- throw new Error(`${label} is required`);
67
- }
68
- function readOptionalStringArg(args, names) {
69
- for (const name of names) {
70
- const value = args[name];
71
- if (typeof value === "string" && value.trim()) {
72
- return value;
73
- }
74
- }
75
- return undefined;
76
- }
77
- function readOptionalPositiveIntegerArg(args, names, fallback) {
78
- for (const name of names) {
79
- const value = args[name];
80
- const numeric = typeof value === "number"
81
- ? value
82
- : typeof value === "string"
83
- ? Number(value)
84
- : NaN;
85
- if (Number.isFinite(numeric) && numeric > 0) {
86
- return Math.floor(numeric);
87
- }
88
- }
89
- return fallback;
90
- }
91
- /**
92
- * 检测文件是否为二进制文件。
93
- * 主流程:先查扩展名黑名单 -> 再采样前 4KB 检测 NUL 字节或高比例不可见字符。
94
- */
95
- async function isBinaryFile(filePath) {
96
- const ext = path.extname(filePath).toLowerCase();
97
- if (BINARY_EXTENSIONS.has(ext)) {
98
- return true;
99
- }
100
- const handle = await fs.open(filePath, "r");
101
- try {
102
- const buffer = Buffer.alloc(BINARY_SAMPLE_BYTES);
103
- const { bytesRead } = await handle.read(buffer, 0, BINARY_SAMPLE_BYTES, 0);
104
- if (bytesRead === 0) {
105
- return false;
106
- }
107
- const sample = buffer.subarray(0, bytesRead);
108
- // NUL byte = definitely binary
109
- if (sample.includes(0)) {
110
- return true;
111
- }
112
- // >30% non-printable characters = likely binary
113
- let nonPrintable = 0;
114
- for (let i = 0; i < bytesRead; i++) {
115
- const byte = sample[i];
116
- // Allow: tab(0x09), LF(0x0a), CR(0x0d), printable ASCII (0x20-0x7e), UTF-8 high bytes (0x80-0xff)
117
- if (byte < 0x09 || (byte > 0x0d && byte < 0x20)) {
118
- nonPrintable++;
119
- }
120
- }
121
- return nonPrintable / bytesRead > BINARY_NON_PRINTABLE_RATIO;
122
- }
123
- finally {
124
- await handle.close();
125
- }
126
- }
127
- export function ensureInsideWorkspace(workspaceRoot, targetPath) {
128
- const resolvedTargetPath = path.resolve(targetPath);
129
- const relativePath = path.relative(workspaceRoot, resolvedTargetPath);
130
- if (relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
131
- throw new Error(`Target path is outside workspace: ${resolvedTargetPath}`);
132
- }
133
- return resolvedTargetPath;
134
- }
135
- async function resolveWorkspaceDirectory(workingDirectory, rawCwd) {
136
- const requestedRoot = path.resolve(String(workingDirectory || "").trim());
137
- const workspaceRoot = await fs.realpath(requestedRoot);
138
- const workspaceStat = await fs.stat(workspaceRoot);
139
- if (!workspaceStat.isDirectory()) {
140
- throw new Error(`Workspace path is not a directory: ${requestedRoot}`);
141
- }
142
- if (!rawCwd?.trim()) {
143
- return { workspaceRoot, cwd: workspaceRoot };
144
- }
145
- const requestedCwd = rawCwd.trim();
146
- const candidatePath = path.isAbsolute(requestedCwd)
147
- ? path.resolve(requestedCwd)
148
- : path.resolve(requestedRoot, requestedCwd);
149
- const requestedRelativePath = path.relative(requestedRoot, candidatePath);
150
- if (requestedRelativePath.startsWith("..") ||
151
- path.isAbsolute(requestedRelativePath)) {
152
- throw new Error(`Command cwd is outside workspace: ${candidatePath}`);
153
- }
154
- const realCwd = ensureInsideWorkspace(workspaceRoot, await fs.realpath(candidatePath));
155
- const cwdStat = await fs.stat(realCwd);
156
- if (!cwdStat.isDirectory()) {
157
- throw new Error(`Command cwd is not a directory: ${realCwd}`);
158
- }
159
- return { workspaceRoot, cwd: realCwd };
160
- }
161
- async function ensureWritableTarget(workspaceRoot, targetPath) {
162
- const realParentPath = await fs.realpath(path.dirname(targetPath));
163
- ensureInsideWorkspace(workspaceRoot, realParentPath);
164
- try {
165
- const targetLinkStat = await fs.lstat(targetPath);
166
- if (targetLinkStat.isSymbolicLink()) {
167
- throw new Error(`Refusing to write through symbolic link: ${targetPath}`);
168
- }
169
- }
170
- catch (error) {
171
- const errorCode = typeof error === "object" && error !== null
172
- ? Reflect.get(error, "code")
173
- : undefined;
174
- if (errorCode !== "ENOENT") {
175
- throw error;
176
- }
177
- }
178
- }
179
- /**
180
- * 解析内置文件工具目标路径。
181
- * 主流程:同时校验请求路径与 realpath 工作区边界,防止绝对路径、`..` 与符号链接目录穿透。
182
- */
183
- export async function resolveWorkspaceTarget(workingDirectory, rawFilePath) {
184
- const requestedRoot = path.resolve(String(workingDirectory || "").trim());
185
- const workspaceRoot = await fs.realpath(requestedRoot);
186
- const workspaceStat = await fs.stat(workspaceRoot);
187
- if (!workspaceStat.isDirectory()) {
188
- throw new Error(`Workspace path is not a directory: ${requestedRoot}`);
189
- }
190
- const normalizedFilePath = rawFilePath.trim();
191
- if (!normalizedFilePath) {
192
- throw new Error("file_path is required");
193
- }
194
- const requestedPath = path.isAbsolute(normalizedFilePath)
195
- ? path.resolve(normalizedFilePath)
196
- : path.resolve(requestedRoot, normalizedFilePath);
197
- const requestedRelativePath = path.relative(requestedRoot, requestedPath);
198
- if (requestedRelativePath.startsWith("..") ||
199
- path.isAbsolute(requestedRelativePath)) {
200
- throw new Error(`Target path is outside workspace: ${requestedPath}`);
201
- }
202
- return {
203
- workspaceRoot,
204
- requestedPath,
205
- targetPath: ensureInsideWorkspace(workspaceRoot, path.join(workspaceRoot, requestedRelativePath)),
206
- };
207
- }
208
- /**
209
- * 原子写入完整文件内容。
210
- * 主流程:创建父目录 -> 校验 realpath 边界和符号链接 -> 写同目录临时文件 -> rename 覆盖目标。
211
- */
212
- async function writeFileAtomically(workingDirectory, filePath, content) {
213
- const target = await resolveWorkspaceTarget(workingDirectory, filePath);
214
- const parentPath = path.dirname(target.targetPath);
215
- const createdParentDirectory = !(await pathExists(parentPath));
216
- await fs.mkdir(parentPath, { recursive: true });
217
- await ensureWritableTarget(target.workspaceRoot, target.targetPath);
218
- const temporaryPath = path.join(parentPath, `.${path.basename(target.targetPath)}.${process.pid}.${randomUUID()}.tmp`);
219
- try {
220
- await fs.writeFile(temporaryPath, content, "utf-8");
221
- await fs.rename(temporaryPath, target.targetPath);
222
- }
223
- catch (error) {
224
- await fs.rm(temporaryPath, { force: true });
225
- throw error;
226
- }
227
- return {
228
- workspaceRoot: target.workspaceRoot,
229
- targetPath: target.targetPath,
230
- bytes: Buffer.byteLength(content, "utf-8"),
231
- createdParentDirectory,
232
- };
233
- }
234
- async function readFileInsideWorkspace(workingDirectory, filePath) {
235
- const target = await resolveWorkspaceTarget(workingDirectory, filePath);
236
- const realTargetPath = ensureInsideWorkspace(target.workspaceRoot, await fs.realpath(target.targetPath));
237
- const stat = await fs.stat(realTargetPath);
238
- if (!stat.isFile()) {
239
- throw new Error(`Path is not a file: ${realTargetPath}`);
240
- }
241
- return {
242
- workspaceRoot: target.workspaceRoot,
243
- targetPath: realTargetPath,
244
- content: await fs.readFile(realTargetPath, "utf-8"),
245
- };
246
- }
247
- /**
248
- * 分页流式读取工作区内文本文件,带行号前缀、双重截断上限和续读提示。
249
- *
250
- * 主流程:
251
- * 1. 路径解析与安全校验(复用 resolveWorkspaceTarget + ensureInsideWorkspace + realpath)
252
- * 2. 二进制检测(扩展名黑名单 + 4KB 采样)
253
- * 3. createReadStream + readline 逐行流式读取,跳过 offset 前行
254
- * 4. 收集 limit 行,同时持续计数总行数(用于底部提示)
255
- * 5. 双重上限:行数 2000 + 字节 50KB,先触发先截断
256
- * 6. 拼装行号前缀 + 底部续读提示
257
- *
258
- * 不修改 readFileInsideWorkspace,edit_file 仍使用全量读取。
259
- */
260
- async function readFileWithPagination(workingDirectory, filePath, offset, limit) {
261
- const target = await resolveWorkspaceTarget(workingDirectory, filePath);
262
- const realTargetPath = ensureInsideWorkspace(target.workspaceRoot, await fs.realpath(target.targetPath));
263
- const stat = await fs.stat(realTargetPath);
264
- if (!stat.isFile()) {
265
- throw new Error(`Path is not a file: ${realTargetPath}`);
266
- }
267
- // ── 二进制检测 ──
268
- if (await isBinaryFile(realTargetPath)) {
269
- return {
270
- workspaceRoot: target.workspaceRoot,
271
- targetPath: realTargetPath,
272
- content: "[Binary file, content skipped]",
273
- isBinary: true,
274
- truncated: false,
275
- totalLines: 0,
276
- shownFromLine: 0,
277
- shownToLine: 0,
278
- };
279
- }
280
- // ── 流式逐行读取 ──
281
- const stream = createReadStream(realTargetPath, { encoding: "utf-8" });
282
- const rl = readline.createInterface({
283
- input: stream,
284
- crlfDelay: Infinity,
285
- });
286
- try {
287
- const outputLines = [];
288
- let lineNumber = 0; // 0-indexed 内部计数
289
- let totalLines = 0;
290
- let bytes = 0;
291
- let truncatedByLines = false;
292
- let truncatedByBytes = false;
293
- const startIndex = offset - 1; // 转为 0-indexed
294
- for await (const text of rl) {
295
- totalLines++;
296
- // 跳过 offset 前的行
297
- if (lineNumber < startIndex) {
298
- lineNumber++;
299
- continue;
300
- }
301
- // 已达 limit 上限:停止收集但继续计数
302
- if (outputLines.length >= limit) {
303
- truncatedByLines = true;
304
- lineNumber++;
305
- continue;
306
- }
307
- // 单行截断
308
- let line = text;
309
- if (line.length > MAX_LINE_LENGTH) {
310
- line =
311
- line.slice(0, MAX_LINE_LENGTH) +
312
- `... (line truncated to ${MAX_LINE_LENGTH} chars)`;
313
- }
314
- const numberedLine = `${lineNumber + 1}: ${line}`;
315
- const lineBytes = Buffer.byteLength(numberedLine, "utf-8") + 1; // +1 for \n
316
- // 字节上限:停止读取(totalLines 不再准确)
317
- if (bytes + lineBytes > MAX_READ_BYTES) {
318
- truncatedByBytes = true;
319
- break;
320
- }
321
- outputLines.push(numberedLine);
322
- bytes += lineBytes;
323
- lineNumber++;
324
- }
325
- // offset 超出文件总行数(空文件除外)
326
- if (totalLines > 0 &&
327
- outputLines.length === 0 &&
328
- !truncatedByLines &&
329
- !truncatedByBytes &&
330
- startIndex >= totalLines) {
331
- throw new Error(`offset ${offset} exceeds total line count ${totalLines} in file: ${realTargetPath}`);
332
- }
333
- const shownFromLine = outputLines.length > 0 ? offset : 0;
334
- const shownToLine = outputLines.length > 0 ? offset + outputLines.length - 1 : 0;
335
- // ── 底部续读提示 ──
336
- let footer;
337
- if (truncatedByBytes) {
338
- footer = `Output capped at 50 KB. Showing lines ${shownFromLine}-${shownToLine}. Use offset=${shownToLine + 1} to continue.`;
339
- }
340
- else if (truncatedByLines) {
341
- footer = `Showing lines ${shownFromLine}-${shownToLine} of ${totalLines}. Use offset=${shownToLine + 1} to continue.`;
342
- }
343
- else {
344
- footer = `End of file - total ${totalLines} lines`;
345
- }
346
- const content = outputLines.length > 0
347
- ? outputLines.join("\n") + "\n" + footer
348
- : footer;
349
- return {
350
- workspaceRoot: target.workspaceRoot,
351
- targetPath: realTargetPath,
352
- content,
353
- isBinary: false,
354
- truncated: truncatedByLines || truncatedByBytes,
355
- totalLines: truncatedByBytes ? -1 : totalLines,
356
- shownFromLine,
357
- shownToLine,
358
- };
359
- }
360
- finally {
361
- rl.close();
362
- stream.destroy();
363
- }
364
- }
365
- // ── grep helpers ──────────────────────────────────────────────────────────────
366
- /**
367
- * 将 glob 通配符转换为 RegExp(匹配文件 basename)。
368
- * 支持:* (不跨 / ), ? (单个非 / 字符), {a,b} (分组), [abc] (字符类)。
369
- */
370
- function globToRegex(pattern) {
371
- let regex = "";
372
- let i = 0;
373
- while (i < pattern.length) {
374
- const char = pattern[i];
375
- if (char === "*") {
376
- regex += "[^/]*";
377
- }
378
- else if (char === "?") {
379
- regex += "[^/]";
380
- }
381
- else if (char === "{") {
382
- const end = pattern.indexOf("}", i);
383
- if (end >= 0) {
384
- const content = pattern.slice(i + 1, end);
385
- regex += `(${content.split(",").join("|")})`;
386
- i = end;
387
- }
388
- else {
389
- regex += "\\{";
390
- }
391
- }
392
- else if (char === "[") {
393
- const end = pattern.indexOf("]", i);
394
- if (end >= 0) {
395
- regex += pattern.slice(i, end + 1);
396
- i = end;
397
- }
398
- else {
399
- regex += "\\[";
400
- }
401
- }
402
- else if ("+^$.()|\\".includes(char)) {
403
- regex += "\\" + char;
404
- }
405
- else {
406
- regex += char;
407
- }
408
- i++;
409
- }
410
- return new RegExp(`^${regex}$`);
411
- }
412
- /**
413
- * 递归遍历目录,返回所有匹配 include/exclude 的文件路径。
414
- * 主流程:readdir -> 跳过 GREP_SKIP_DIRS 和隐藏目录 -> 递归子目录 -> 过滤文件名。
415
- */
416
- async function walkDirectory(dir, includeRegex, excludeRegex, maxFiles) {
417
- const results = [];
418
- async function walk(currentDir) {
419
- if (results.length >= maxFiles)
420
- return;
421
- const entries = await fs.readdir(currentDir, { withFileTypes: true });
422
- for (const entry of entries) {
423
- if (results.length >= maxFiles)
424
- return;
425
- if (entry.name.startsWith(".") && entry.isDirectory())
426
- continue;
427
- const fullPath = path.join(currentDir, entry.name);
428
- if (entry.isDirectory()) {
429
- if (GREP_SKIP_DIRS.has(entry.name))
430
- continue;
431
- await walk(fullPath);
432
- }
433
- else if (entry.isFile()) {
434
- if (includeRegex && !includeRegex.test(entry.name))
435
- continue;
436
- if (excludeRegex && excludeRegex.test(entry.name))
437
- continue;
438
- results.push(fullPath);
439
- }
440
- }
441
- }
442
- await walk(dir);
443
- return results;
444
- }
445
- /**
446
- * 在单个文件中搜索正则匹配,返回匹配行(含行号)或计数。
447
- * 主流程:文件大小检查 -> 二进制检测 -> 流式逐行读取 -> 正则匹配 -> 收集结果。
448
- */
449
- async function searchInFile(filePath, workspaceRoot, options) {
450
- const stat = await fs.stat(filePath);
451
- if (stat.size > MAX_GREP_FILE_SIZE) {
452
- return { matches: [], count: 0 };
453
- }
454
- if (await isBinaryFile(filePath)) {
455
- return { matches: [], count: 0 };
456
- }
457
- const relativePath = path.relative(workspaceRoot, filePath).replace(/\\/g, "/");
458
- const matches = [];
459
- let count = 0;
460
- const stream = createReadStream(filePath, { encoding: "utf-8" });
461
- const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
462
- try {
463
- let lineNumber = 0;
464
- for await (const text of rl) {
465
- lineNumber++;
466
- if (options.regex.test(text)) {
467
- count++;
468
- if (options.collectContent) {
469
- let content = text;
470
- if (content.length > MAX_LINE_LENGTH) {
471
- content =
472
- content.slice(0, MAX_LINE_LENGTH) +
473
- `... (line truncated to ${MAX_LINE_LENGTH} chars)`;
474
- }
475
- matches.push({ file: relativePath, line: lineNumber, content });
476
- if (matches.length >= options.maxResults)
477
- break;
478
- }
479
- if (options.stopOnFirstMatch)
480
- break;
481
- }
482
- }
483
- }
484
- finally {
485
- rl.close();
486
- stream.destroy();
487
- }
488
- return { matches, count };
489
- }
490
- const MAX_COMMAND_TIMEOUT_MS = 10 * 60_000;
491
- const DEFAULT_COMMAND_TIMEOUT_MS = MAX_COMMAND_TIMEOUT_MS;
492
- const DEFAULT_COMMAND_INACTIVITY_TIMEOUT_MS = 60_000;
493
- const MAX_COMMAND_INACTIVITY_TIMEOUT_MS = 10 * 60_000;
494
- function writeFileTool(workingDirectory, onFileChange) {
495
- return {
496
- kind: "builtin",
497
- toolName: "write_file",
498
- exposedName: "write_file",
499
- description: "Create or overwrite a UTF-8 text file inside the current workspace. Parent directories are created automatically.",
500
- inputSchema: {
501
- type: "object",
502
- properties: {
503
- file_path: {
504
- type: "string",
505
- description: "Workspace-relative file path to write.",
506
- },
507
- content: {
508
- type: "string",
509
- description: "Complete UTF-8 file content.",
510
- },
511
- },
512
- required: ["file_path", "content"],
513
- additionalProperties: false,
514
- },
515
- async execute(args) {
516
- const filePath = readStringArg(args, ["file_path", "filePath"], "file_path");
517
- const content = readStringArg(args, ["content"], "content");
518
- const target = await resolveWorkspaceTarget(workingDirectory, filePath);
519
- const existed = await pathExists(target.targetPath);
520
- const beforeContent = existed
521
- ? await fs.readFile(target.targetPath, "utf-8").catch(() => null)
522
- : null;
523
- const result = await writeFileAtomically(workingDirectory, filePath, content);
524
- if (onFileChange) {
525
- const relativePath = path
526
- .relative(result.workspaceRoot, result.targetPath)
527
- .replace(/\\/g, "/");
528
- await onFileChange({
529
- filePath: relativePath,
530
- operation: existed ? "UPDATE" : "CREATE",
531
- beforeContent,
532
- afterContent: content,
533
- });
534
- }
535
- return {
536
- ok: true,
537
- tool: "write_file",
538
- workspacePath: toDisplayPath(result.workspaceRoot),
539
- filePath: toDisplayPath(result.targetPath),
540
- bytes: result.bytes,
541
- createdParentDirectory: result.createdParentDirectory,
542
- };
543
- },
544
- };
545
- }
546
- function editFileTool(workingDirectory, onFileChange) {
547
- return {
548
- kind: "builtin",
549
- toolName: "edit_file",
550
- exposedName: "edit_file",
551
- description: "Replace exactly one occurrence of old_string with new_string in a UTF-8 workspace text file.",
552
- inputSchema: {
553
- type: "object",
554
- properties: {
555
- file_path: {
556
- type: "string",
557
- description: "Workspace-relative file path to edit.",
558
- },
559
- old_string: {
560
- type: "string",
561
- description: "Existing text to replace. Must occur exactly once.",
562
- },
563
- new_string: { type: "string", description: "Replacement text." },
564
- },
565
- required: ["file_path", "old_string", "new_string"],
566
- additionalProperties: false,
567
- },
568
- async execute(args) {
569
- const filePath = readStringArg(args, ["file_path", "filePath"], "file_path");
570
- const oldString = readStringArg(args, ["old_string", "oldString"], "old_string");
571
- const newString = readStringArg(args, ["new_string", "newString"], "new_string");
572
- if (!oldString) {
573
- throw new Error("old_string must not be empty");
574
- }
575
- const current = await readFileInsideWorkspace(workingDirectory, filePath);
576
- const occurrences = countOccurrences(current.content, oldString);
577
- if (occurrences === 0) {
578
- throw new Error("old_string was not found in file");
579
- }
580
- if (occurrences > 1) {
581
- throw new Error(`old_string occurs ${occurrences} times; provide a unique match`);
582
- }
583
- const updatedContent = current.content.replace(oldString, newString);
584
- const result = await writeFileAtomically(workingDirectory, filePath, updatedContent);
585
- if (onFileChange) {
586
- const relativePath = path
587
- .relative(result.workspaceRoot, result.targetPath)
588
- .replace(/\\/g, "/");
589
- await onFileChange({
590
- filePath: relativePath,
591
- operation: "UPDATE",
592
- beforeContent: current.content,
593
- afterContent: updatedContent,
594
- });
595
- }
596
- return {
597
- ok: true,
598
- tool: "edit_file",
599
- workspacePath: toDisplayPath(result.workspaceRoot),
600
- filePath: toDisplayPath(result.targetPath),
601
- replacements: 1,
602
- bytes: result.bytes,
603
- };
604
- },
605
- };
606
- }
607
- function deleteFileTool(workingDirectory, onFileChange) {
608
- return {
609
- kind: "builtin",
610
- toolName: "delete_file",
611
- exposedName: "delete_file",
612
- description: "Delete a file inside the current workspace. Returns an error if the file does not exist.",
613
- inputSchema: {
614
- type: "object",
615
- properties: {
616
- file_path: {
617
- type: "string",
618
- description: "Workspace-relative file path to delete.",
619
- },
620
- },
621
- required: ["file_path"],
622
- additionalProperties: false,
623
- },
624
- async execute(args) {
625
- const filePath = readStringArg(args, ["file_path", "filePath"], "file_path");
626
- const target = await resolveWorkspaceTarget(workingDirectory, filePath);
627
- const realTargetPath = ensureInsideWorkspace(target.workspaceRoot, await fs.realpath(target.targetPath).catch(() => target.targetPath));
628
- const stat = await fs.stat(realTargetPath).catch(() => null);
629
- if (!stat) {
630
- throw new Error(`File does not exist: ${realTargetPath}`);
631
- }
632
- if (!stat.isFile()) {
633
- throw new Error(`Path is not a file: ${realTargetPath}`);
634
- }
635
- const beforeContent = await fs
636
- .readFile(realTargetPath, "utf-8")
637
- .catch(() => null);
638
- await fs.rm(realTargetPath, { force: true });
639
- if (onFileChange) {
640
- const relativePath = path
641
- .relative(target.workspaceRoot, realTargetPath)
642
- .replace(/\\/g, "/");
643
- await onFileChange({
644
- filePath: relativePath,
645
- operation: "DELETE",
646
- beforeContent,
647
- afterContent: null,
648
- });
649
- }
650
- return {
651
- ok: true,
652
- tool: "delete_file",
653
- workspacePath: toDisplayPath(target.workspaceRoot),
654
- filePath: toDisplayPath(realTargetPath),
655
- deleted: true,
656
- };
657
- },
658
- };
659
- }
660
- function readFileTool(workingDirectory) {
661
- return {
662
- kind: "builtin",
663
- toolName: "read_file",
664
- exposedName: "read_file",
665
- description: "Read a UTF-8 text file inside the current workspace. " +
666
- "Returns content with line numbers in the format '<line>: <content>'. " +
667
- "Supports offset (1-indexed line number to start from) and limit (max lines to return, default 2000). " +
668
- "Output is capped at 2000 lines or 50 KB, whichever is reached first. " +
669
- "Individual lines longer than 2000 characters are truncated. " +
670
- "Avoid tiny repeated slices (e.g. 30-line chunks); read a larger window if more context is needed.",
671
- inputSchema: {
672
- type: "object",
673
- properties: {
674
- file_path: {
675
- type: "string",
676
- description: "Workspace-relative file path to read.",
677
- },
678
- offset: {
679
- type: "number",
680
- description: "Line number to start reading from (1-indexed). Defaults to 1.",
681
- },
682
- limit: {
683
- type: "number",
684
- description: "Maximum number of lines to return. Defaults to 2000.",
685
- },
686
- },
687
- required: ["file_path"],
688
- additionalProperties: false,
689
- },
690
- async execute(args) {
691
- const filePath = readStringArg(args, ["file_path", "filePath"], "file_path");
692
- const offset = readOptionalPositiveIntegerArg(args, ["offset"], 1);
693
- const limit = readOptionalPositiveIntegerArg(args, ["limit"], DEFAULT_READ_LIMIT);
694
- const result = await readFileWithPagination(workingDirectory, filePath, offset, limit);
695
- return {
696
- ok: true,
697
- tool: "read_file",
698
- workspacePath: toDisplayPath(result.workspaceRoot),
699
- filePath: toDisplayPath(result.targetPath),
700
- content: result.content,
701
- isBinary: result.isBinary,
702
- truncated: result.truncated,
703
- totalLines: result.totalLines,
704
- shownFromLine: result.shownFromLine,
705
- shownToLine: result.shownToLine,
706
- };
707
- },
708
- };
709
- }
710
- function bashTool(workingDirectory, agentId) {
711
- return {
712
- kind: "builtin",
713
- toolName: "Bash",
714
- exposedName: "Bash",
715
- description: "Execute a shell command in the current workspace. Use for local diagnostics, builds, tests, and OS commands. The command runs with a bounded timeout and returns stdout, stderr, and exit code.",
716
- inputSchema: {
717
- type: "object",
718
- properties: {
719
- command: { type: "string", description: "Shell command to execute." },
720
- cwd: {
721
- type: "string",
722
- description: "Optional workspace-relative working directory. Defaults to the workspace root.",
723
- },
724
- timeout_ms: {
725
- type: "number",
726
- description: "Optional timeout in milliseconds. Defaults to 600000 and is capped at 600000.",
727
- },
728
- inactivity_timeout_ms: {
729
- type: "number",
730
- description: "Optional no-output timeout in milliseconds. Defaults to 60000 and is capped at 600000.",
731
- },
732
- description: {
733
- type: "string",
734
- description: "Optional short reason for running the command.",
735
- },
736
- },
737
- required: ["command"],
738
- additionalProperties: false,
739
- },
740
- async execute(args, context) {
741
- const command = readStringArg(args, ["command"], "command").trim();
742
- if (!command) {
743
- throw new Error("command must not be empty");
744
- }
745
- const requestedTimeoutMs = readOptionalPositiveIntegerArg(args, ["timeout_ms", "timeoutMs"], DEFAULT_COMMAND_TIMEOUT_MS);
746
- const timeoutMs = Math.min(requestedTimeoutMs, MAX_COMMAND_TIMEOUT_MS);
747
- const requestedInactivityTimeoutMs = readOptionalPositiveIntegerArg(args, ["inactivity_timeout_ms", "inactivityTimeoutMs"], DEFAULT_COMMAND_INACTIVITY_TIMEOUT_MS);
748
- const inactivityTimeoutMs = Math.min(requestedInactivityTimeoutMs, MAX_COMMAND_INACTIVITY_TIMEOUT_MS);
749
- const cwdArg = readOptionalStringArg(args, ["cwd"]);
750
- const resolved = await resolveWorkspaceDirectory(workingDirectory, cwdArg);
751
- const result = await runShellCommand({
752
- commandText: command,
753
- agentId,
754
- workspaceRoot: resolved.workspaceRoot,
755
- cwd: resolved.cwd,
756
- timeoutMs,
757
- inactivityTimeoutMs,
758
- onOutput: context?.onOutput,
759
- });
760
- return {
761
- ok: result.exitCode === 0 && !result.timedOut,
762
- tool: "Bash",
763
- command,
764
- cwd: toDisplayPath(resolved.cwd),
765
- exitCode: result.exitCode,
766
- signal: result.signal,
767
- timedOut: result.timedOut,
768
- inactivityTimedOut: result.inactivityTimedOut,
769
- timeoutMs,
770
- inactivityTimeoutMs,
771
- durationMs: result.durationMs,
772
- outputSpilled: result.outputSpilled,
773
- outputFilePath: result.outputFilePath,
774
- outputLineCount: result.outputLineCount,
775
- commandFilePath: result.commandFilePath,
776
- commandLineCount: result.commandLineCount,
777
- stdout: result.stdout,
778
- stderr: result.stderr,
779
- };
780
- },
781
- };
782
- }
783
- function grepTool(workingDirectory) {
784
- return {
785
- kind: "builtin",
786
- toolName: "grep",
787
- exposedName: "grep",
788
- description: "Search file contents using regular expressions within the workspace. " +
789
- "Returns matched lines with file paths and line numbers. " +
790
- "Supports include/exclude glob patterns, case-insensitive matching, and three output modes " +
791
- "(content, files_with_matches, count). Searches recursively through directories, " +
792
- "skipping binary files, hidden directories, and common build/dependency directories (node_modules, .git, dist, etc.).",
793
- inputSchema: {
794
- type: "object",
795
- properties: {
796
- pattern: {
797
- type: "string",
798
- description: "Regular expression pattern to search for in file contents.",
799
- },
800
- path: {
801
- type: "string",
802
- description: "Workspace-relative file or directory path to search in. Defaults to the workspace root.",
803
- },
804
- include: {
805
- type: "string",
806
- description: "Glob pattern to filter files by name (e.g. '*.ts', '*.{js,ts}'). Only matching files are searched.",
807
- },
808
- exclude: {
809
- type: "string",
810
- description: "Glob pattern to exclude files by name (e.g. '*.test.ts'). Matching files are skipped.",
811
- },
812
- case_insensitive: {
813
- type: "boolean",
814
- description: "Case-insensitive matching. Default false.",
815
- },
816
- output_mode: {
817
- type: "string",
818
- enum: ["content", "files_with_matches", "count"],
819
- description: "Output format: 'content' returns matched lines with line numbers (default), " +
820
- "'files_with_matches' returns only file paths with matches, " +
821
- "'count' returns match counts per file.",
822
- },
823
- max_results: {
824
- type: "number",
825
- description: "Maximum number of matched lines to return (content mode). Default 1000.",
826
- },
827
- },
828
- required: ["pattern"],
829
- additionalProperties: false,
830
- },
831
- /**
832
- * grep 工具执行主流程:
833
- * 1. 解析参数(pattern, path, include/exclude, output_mode 等)
834
- * 2. 编译正则(含 case_insensitive 标志)
835
- * 3. 解析搜索路径并校验 workspace 边界
836
- * 4. 收集待搜索文件列表(单文件或递归遍历目录)
837
- * 5. 逐文件搜索(流式读取 + 正则匹配)
838
- * 6. 根据 output_mode 构建响应
839
- */
840
- async execute(args) {
841
- const pattern = readStringArg(args, ["pattern"], "pattern");
842
- const searchPath = readOptionalStringArg(args, ["path"]) || ".";
843
- const includeGlob = readOptionalStringArg(args, ["include"]);
844
- const excludeGlob = readOptionalStringArg(args, ["exclude"]);
845
- const caseInsensitive = args.case_insensitive === true;
846
- const outputMode = (() => {
847
- const mode = args.output_mode;
848
- if (mode === "files_with_matches" || mode === "count")
849
- return mode;
850
- return "content";
851
- })();
852
- const maxResults = readOptionalPositiveIntegerArg(args, ["max_results"], DEFAULT_GREP_MAX_RESULTS);
853
- // ── 编译正则 ──
854
- const flags = caseInsensitive ? "i" : "";
855
- let regex;
856
- try {
857
- regex = new RegExp(pattern, flags);
858
- }
859
- catch (error) {
860
- throw new Error(`Invalid regex pattern: ${error instanceof Error ? error.message : String(error)}`);
861
- }
862
- const includeRegex = includeGlob ? globToRegex(includeGlob) : null;
863
- const excludeRegex = excludeGlob ? globToRegex(excludeGlob) : null;
864
- // ── 解析搜索路径(复用 workspace 安全校验) ──
865
- const target = await resolveWorkspaceTarget(workingDirectory, searchPath);
866
- const realTargetPath = ensureInsideWorkspace(target.workspaceRoot, await fs.realpath(target.targetPath));
867
- const targetStat = await fs.stat(realTargetPath);
868
- // ── 收集文件列表 ──
869
- let files;
870
- if (targetStat.isFile()) {
871
- files = [realTargetPath];
872
- }
873
- else if (targetStat.isDirectory()) {
874
- files = await walkDirectory(realTargetPath, includeRegex, excludeRegex, MAX_GREP_FILES);
875
- }
876
- else {
877
- throw new Error(`Path is neither a file nor a directory: ${realTargetPath}`);
878
- }
879
- // ── 逐文件搜索 ──
880
- const allMatches = [];
881
- const fileCounts = [];
882
- const matchedFiles = [];
883
- let totalMatches = 0;
884
- let outputBytes = 0;
885
- let truncated = false;
886
- for (const filePath of files) {
887
- // content 模式:全局 maxResults 上限
888
- if (outputMode === "content" && allMatches.length >= maxResults) {
889
- truncated = true;
890
- break;
891
- }
892
- const searchOptions = {
893
- regex,
894
- maxResults: outputMode === "content"
895
- ? maxResults - allMatches.length
896
- : Number.MAX_SAFE_INTEGER,
897
- collectContent: outputMode === "content",
898
- stopOnFirstMatch: outputMode === "files_with_matches",
899
- };
900
- const result = await searchInFile(filePath, target.workspaceRoot, searchOptions);
901
- if (result.count > 0) {
902
- const relativePath = path
903
- .relative(target.workspaceRoot, filePath)
904
- .replace(/\\/g, "/");
905
- matchedFiles.push(relativePath);
906
- totalMatches += result.count;
907
- if (outputMode === "content") {
908
- for (const match of result.matches) {
909
- const matchBytes = Buffer.byteLength(match.content, "utf-8") + 64;
910
- if (outputBytes + matchBytes > MAX_GREP_OUTPUT_BYTES) {
911
- truncated = true;
912
- break;
913
- }
914
- outputBytes += matchBytes;
915
- allMatches.push(match);
916
- }
917
- if (truncated)
918
- break;
919
- // max_results 截断:收集完本文件匹配后检查是否已达上限
920
- if (allMatches.length >= maxResults) {
921
- truncated = true;
922
- break;
923
- }
924
- }
925
- else if (outputMode === "count") {
926
- fileCounts.push({ file: relativePath, count: result.count });
927
- }
928
- }
929
- }
930
- // ── 构建响应 ──
931
- const response = {
932
- ok: true,
933
- tool: "grep",
934
- pattern,
935
- searchPath: toDisplayPath(target.targetPath),
936
- outputMode,
937
- filesSearched: files.length,
938
- filesMatched: matchedFiles.length,
939
- totalMatches,
940
- truncated,
941
- };
942
- if (outputMode === "content") {
943
- response.matches = allMatches;
944
- }
945
- else if (outputMode === "files_with_matches") {
946
- response.matches = matchedFiles;
947
- }
948
- else {
949
- response.matches = fileCounts;
950
- }
951
- return response;
952
- },
953
- };
954
- }
955
- export function createBuiltInFileTools(workingDirectory, agentId, onFileChange) {
956
- const resolvedAgentId = agentId || "unknown";
957
- return [
958
- readFileTool(workingDirectory),
959
- writeFileTool(workingDirectory, onFileChange),
960
- editFileTool(workingDirectory, onFileChange),
961
- deleteFileTool(workingDirectory, onFileChange),
962
- grepTool(workingDirectory),
963
- bashTool(workingDirectory, resolvedAgentId),
964
- symbolsTool(workingDirectory),
965
- ];
966
- }
1
+ import{randomUUID as Y}from"node:crypto";import{promises as u,createReadStream as C}from"node:fs";import f from"node:path";import D from"node:readline";import{runShellCommand as K}from"./builtins/shellCommandRunner.js";import{symbolsTool as V}from"./built-in-symbols-tool.js";const H=2e3,v=2e3,Z=50*1024,U=4096,J=.3,Q=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".tiff",".tif",".zip",".gz",".tar",".rar",".7z",".bz2",".xz",".lz",".exe",".dll",".so",".dylib",".bin",".o",".a",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".mp3",".mp4",".avi",".mov",".wav",".flv",".mkv",".ogg",".woff",".woff2",".ttf",".otf",".eot",".class",".jar",".war",".ear",".pyc",".pyo",".node",".sqlite",".db",".mdb",".wasm"]),tt=1e3,et=1024*1024,nt=256*1024,ot=1e3,it=new Set([".git","node_modules","dist","build",".next",".nuxt",".cache",".turbo",".output","coverage",".nyc_output"]);function y(o){return o.replace(/\\/g,"/")}async function q(o){try{return await u.access(o),!0}catch{return!1}}function rt(o,n){if(!n)return 0;let t=0,e=o.indexOf(n);for(;e>=0;)t+=1,e=o.indexOf(n,e+n.length);return t}function _(o,n,t){for(const e of n){const i=o[e];if(typeof i=="string")return i}throw new Error(`${t} is required`)}function O(o,n){for(const t of n){const e=o[t];if(typeof e=="string"&&e.trim())return e}}function A(o,n,t){for(const e of n){const i=o[e],r=typeof i=="number"?i:typeof i=="string"?Number(i):NaN;if(Number.isFinite(r)&&r>0)return Math.floor(r)}return t}async function W(o){const n=f.extname(o).toLowerCase();if(Q.has(n))return!0;const t=await u.open(o,"r");try{const e=Buffer.alloc(U),{bytesRead:i}=await t.read(e,0,U,0);if(i===0)return!1;const r=e.subarray(0,i);if(r.includes(0))return!0;let c=0;for(let s=0;s<i;s++){const a=r[s];(a<9||a>13&&a<32)&&c++}return c/i>J}finally{await t.close()}}function E(o,n){const t=f.resolve(n),e=f.relative(o,t);if(e.startsWith("..")||f.isAbsolute(e))throw new Error(`Target path is outside workspace: ${t}`);return t}async function at(o,n){const t=f.resolve(String(o||"").trim()),e=await u.realpath(t);if(!(await u.stat(e)).isDirectory())throw new Error(`Workspace path is not a directory: ${t}`);if(!n?.trim())return{workspaceRoot:e,cwd:e};const r=n.trim(),c=f.isAbsolute(r)?f.resolve(r):f.resolve(t,r),s=f.relative(t,c);if(s.startsWith("..")||f.isAbsolute(s))throw new Error(`Command cwd is outside workspace: ${c}`);const a=E(e,await u.realpath(c));if(!(await u.stat(a)).isDirectory())throw new Error(`Command cwd is not a directory: ${a}`);return{workspaceRoot:e,cwd:a}}async function st(o,n){const t=await u.realpath(f.dirname(n));E(o,t);try{if((await u.lstat(n)).isSymbolicLink())throw new Error(`Refusing to write through symbolic link: ${n}`)}catch(e){if((typeof e=="object"&&e!==null?Reflect.get(e,"code"):void 0)!=="ENOENT")throw e}}async function R(o,n){const t=f.resolve(String(o||"").trim()),e=await u.realpath(t);if(!(await u.stat(e)).isDirectory())throw new Error(`Workspace path is not a directory: ${t}`);const r=n.trim();if(!r)throw new Error("file_path is required");const c=f.isAbsolute(r)?f.resolve(r):f.resolve(t,r),s=f.relative(t,c);if(s.startsWith("..")||f.isAbsolute(s))throw new Error(`Target path is outside workspace: ${c}`);return{workspaceRoot:e,requestedPath:c,targetPath:E(e,f.join(e,s))}}async function j(o,n,t){const e=await R(o,n),i=f.dirname(e.targetPath),r=!await q(i);await u.mkdir(i,{recursive:!0}),await st(e.workspaceRoot,e.targetPath);const c=f.join(i,`.${f.basename(e.targetPath)}.${process.pid}.${Y()}.tmp`);try{await u.writeFile(c,t,"utf-8"),await u.rename(c,e.targetPath)}catch(s){throw await u.rm(c,{force:!0}),s}return{workspaceRoot:e.workspaceRoot,targetPath:e.targetPath,bytes:Buffer.byteLength(t,"utf-8"),createdParentDirectory:r}}async function ct(o,n){const t=await R(o,n),e=E(t.workspaceRoot,await u.realpath(t.targetPath));if(!(await u.stat(e)).isFile())throw new Error(`Path is not a file: ${e}`);return{workspaceRoot:t.workspaceRoot,targetPath:e,content:await u.readFile(e,"utf-8")}}async function lt(o,n,t,e){const i=await R(o,n),r=E(i.workspaceRoot,await u.realpath(i.targetPath));if(!(await u.stat(r)).isFile())throw new Error(`Path is not a file: ${r}`);if(await W(r))return{workspaceRoot:i.workspaceRoot,targetPath:r,content:"[Binary file, content skipped]",isBinary:!0,truncated:!1,totalLines:0,shownFromLine:0,shownToLine:0};const s=C(r,{encoding:"utf-8"}),a=D.createInterface({input:s,crlfDelay:1/0});try{const d=[];let p=0,l=0,I=0,m=!1,w=!1;const S=t-1;for await(const L of a){if(l++,p<S){p++;continue}if(d.length>=e){m=!0,p++;continue}let x=L;x.length>v&&(x=x.slice(0,v)+`... (line truncated to ${v} chars)`);const k=`${p+1}: ${x}`,T=Buffer.byteLength(k,"utf-8")+1;if(I+T>Z){w=!0;break}d.push(k),I+=T,p++}if(l>0&&d.length===0&&!m&&!w&&S>=l)throw new Error(`offset ${t} exceeds total line count ${l} in file: ${r}`);const P=d.length>0?t:0,h=d.length>0?t+d.length-1:0;let b;w?b=`Output capped at 50 KB. Showing lines ${P}-${h}. Use offset=${h+1} to continue.`:m?b=`Showing lines ${P}-${h} of ${l}. Use offset=${h+1} to continue.`:b=`End of file - total ${l} lines`;const M=d.length>0?d.join(`
2
+ `)+`
3
+ `+b:b;return{workspaceRoot:i.workspaceRoot,targetPath:r,content:M,isBinary:!1,truncated:m||w,totalLines:w?-1:l,shownFromLine:P,shownToLine:h}}finally{a.close(),s.destroy()}}function G(o){let n="",t=0;for(;t<o.length;){const e=o[t];if(e==="*")n+="[^/]*";else if(e==="?")n+="[^/]";else if(e==="{"){const i=o.indexOf("}",t);if(i>=0){const r=o.slice(t+1,i);n+=`(${r.split(",").join("|")})`,t=i}else n+="\\{"}else if(e==="["){const i=o.indexOf("]",t);i>=0?(n+=o.slice(t,i+1),t=i):n+="\\["}else"+^$.()|\\".includes(e)?n+="\\"+e:n+=e;t++}return new RegExp(`^${n}$`)}async function ut(o,n,t,e){const i=[];async function r(c){if(i.length>=e)return;const s=await u.readdir(c,{withFileTypes:!0});for(const a of s){if(i.length>=e)return;if(a.name.startsWith(".")&&a.isDirectory())continue;const d=f.join(c,a.name);if(a.isDirectory()){if(it.has(a.name))continue;await r(d)}else if(a.isFile()){if(n&&!n.test(a.name)||t&&t.test(a.name))continue;i.push(d)}}}return await r(o),i}async function dt(o,n,t){if((await u.stat(o)).size>et)return{matches:[],count:0};if(await W(o))return{matches:[],count:0};const i=f.relative(n,o).replace(/\\/g,"/"),r=[];let c=0;const s=C(o,{encoding:"utf-8"}),a=D.createInterface({input:s,crlfDelay:1/0});try{let d=0;for await(const p of a)if(d++,t.regex.test(p)){if(c++,t.collectContent){let l=p;if(l.length>v&&(l=l.slice(0,v)+`... (line truncated to ${v} chars)`),r.push({file:i,line:d,content:l}),r.length>=t.maxResults)break}if(t.stopOnFirstMatch)break}}finally{a.close(),s.destroy()}return{matches:r,count:c}}const X=10*6e4,ft=X,pt=6e4,ht=10*6e4;function mt(o,n){return{kind:"builtin",toolName:"write_file",exposedName:"write_file",description:"Create or overwrite a UTF-8 text file inside the current workspace. Parent directories are created automatically.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to write."},content:{type:"string",description:"Complete UTF-8 file content."}},required:["file_path","content"],additionalProperties:!1},async execute(t){const e=_(t,["file_path","filePath"],"file_path"),i=_(t,["content"],"content"),r=await R(o,e),c=await q(r.targetPath),s=c?await u.readFile(r.targetPath,"utf-8").catch(()=>null):null,a=await j(o,e,i);if(n){const d=f.relative(a.workspaceRoot,a.targetPath).replace(/\\/g,"/");await n({filePath:d,operation:c?"UPDATE":"CREATE",beforeContent:s,afterContent:i})}return{ok:!0,tool:"write_file",workspacePath:y(a.workspaceRoot),filePath:y(a.targetPath),bytes:a.bytes,createdParentDirectory:a.createdParentDirectory}}}}function wt(o,n){return{kind:"builtin",toolName:"edit_file",exposedName:"edit_file",description:"Replace exactly one occurrence of old_string with new_string in a UTF-8 workspace text file.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to edit."},old_string:{type:"string",description:"Existing text to replace. Must occur exactly once."},new_string:{type:"string",description:"Replacement text."}},required:["file_path","old_string","new_string"],additionalProperties:!1},async execute(t){const e=_(t,["file_path","filePath"],"file_path"),i=_(t,["old_string","oldString"],"old_string"),r=_(t,["new_string","newString"],"new_string");if(!i)throw new Error("old_string must not be empty");const c=await ct(o,e),s=rt(c.content,i);if(s===0)throw new Error("old_string was not found in file");if(s>1)throw new Error(`old_string occurs ${s} times; provide a unique match`);const a=c.content.replace(i,r),d=await j(o,e,a);if(n){const p=f.relative(d.workspaceRoot,d.targetPath).replace(/\\/g,"/");await n({filePath:p,operation:"UPDATE",beforeContent:c.content,afterContent:a})}return{ok:!0,tool:"edit_file",workspacePath:y(d.workspaceRoot),filePath:y(d.targetPath),replacements:1,bytes:d.bytes}}}}function gt(o,n){return{kind:"builtin",toolName:"delete_file",exposedName:"delete_file",description:"Delete a file inside the current workspace. Returns an error if the file does not exist.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to delete."}},required:["file_path"],additionalProperties:!1},async execute(t){const e=_(t,["file_path","filePath"],"file_path"),i=await R(o,e),r=E(i.workspaceRoot,await u.realpath(i.targetPath).catch(()=>i.targetPath)),c=await u.stat(r).catch(()=>null);if(!c)throw new Error(`File does not exist: ${r}`);if(!c.isFile())throw new Error(`Path is not a file: ${r}`);const s=await u.readFile(r,"utf-8").catch(()=>null);if(await u.rm(r,{force:!0}),n){const a=f.relative(i.workspaceRoot,r).replace(/\\/g,"/");await n({filePath:a,operation:"DELETE",beforeContent:s,afterContent:null})}return{ok:!0,tool:"delete_file",workspacePath:y(i.workspaceRoot),filePath:y(r),deleted:!0}}}}function yt(o){return{kind:"builtin",toolName:"read_file",exposedName:"read_file",description:"Read a UTF-8 text file inside the current workspace. Returns content with line numbers in the format '<line>: <content>'. Supports offset (1-indexed line number to start from) and limit (max lines to return, default 2000). Output is capped at 2000 lines or 50 KB, whichever is reached first. Individual lines longer than 2000 characters are truncated. Avoid tiny repeated slices (e.g. 30-line chunks); read a larger window if more context is needed.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to read."},offset:{type:"number",description:"Line number to start reading from (1-indexed). Defaults to 1."},limit:{type:"number",description:"Maximum number of lines to return. Defaults to 2000."}},required:["file_path"],additionalProperties:!1},async execute(n){const t=_(n,["file_path","filePath"],"file_path"),e=A(n,["offset"],1),i=A(n,["limit"],H),r=await lt(o,t,e,i);return{ok:!0,tool:"read_file",workspacePath:y(r.workspaceRoot),filePath:y(r.targetPath),content:r.content,isBinary:r.isBinary,truncated:r.truncated,totalLines:r.totalLines,shownFromLine:r.shownFromLine,shownToLine:r.shownToLine}}}}function _t(o,n){return{kind:"builtin",toolName:"Bash",exposedName:"Bash",description:"Execute a shell command in the current workspace. Use for local diagnostics, builds, tests, and OS commands. The command runs with a bounded timeout and returns stdout, stderr, and exit code.",inputSchema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute."},cwd:{type:"string",description:"Optional workspace-relative working directory. Defaults to the workspace root."},timeout_ms:{type:"number",description:"Optional timeout in milliseconds. Defaults to 600000 and is capped at 600000."},inactivity_timeout_ms:{type:"number",description:"Optional no-output timeout in milliseconds. Defaults to 60000 and is capped at 600000."},description:{type:"string",description:"Optional short reason for running the command."}},required:["command"],additionalProperties:!1},async execute(t,e){const i=_(t,["command"],"command").trim();if(!i)throw new Error("command must not be empty");const r=A(t,["timeout_ms","timeoutMs"],ft),c=Math.min(r,X),s=A(t,["inactivity_timeout_ms","inactivityTimeoutMs"],pt),a=Math.min(s,ht),d=O(t,["cwd"]),p=await at(o,d),l=await K({commandText:i,agentId:n,workspaceRoot:p.workspaceRoot,cwd:p.cwd,timeoutMs:c,inactivityTimeoutMs:a,onOutput:e?.onOutput});return{ok:l.exitCode===0&&!l.timedOut,tool:"Bash",command:i,cwd:y(p.cwd),exitCode:l.exitCode,signal:l.signal,timedOut:l.timedOut,inactivityTimedOut:l.inactivityTimedOut,timeoutMs:c,inactivityTimeoutMs:a,durationMs:l.durationMs,outputSpilled:l.outputSpilled,outputFilePath:l.outputFilePath,outputLineCount:l.outputLineCount,commandFilePath:l.commandFilePath,commandLineCount:l.commandLineCount,stdout:l.stdout,stderr:l.stderr}}}}function Pt(o){return{kind:"builtin",toolName:"grep",exposedName:"grep",description:"Search file contents using regular expressions within the workspace. Returns matched lines with file paths and line numbers. Supports include/exclude glob patterns, case-insensitive matching, and three output modes (content, files_with_matches, count). Searches recursively through directories, skipping binary files, hidden directories, and common build/dependency directories (node_modules, .git, dist, etc.).",inputSchema:{type:"object",properties:{pattern:{type:"string",description:"Regular expression pattern to search for in file contents."},path:{type:"string",description:"Workspace-relative file or directory path to search in. Defaults to the workspace root."},include:{type:"string",description:"Glob pattern to filter files by name (e.g. '*.ts', '*.{js,ts}'). Only matching files are searched."},exclude:{type:"string",description:"Glob pattern to exclude files by name (e.g. '*.test.ts'). Matching files are skipped."},case_insensitive:{type:"boolean",description:"Case-insensitive matching. Default false."},output_mode:{type:"string",enum:["content","files_with_matches","count"],description:"Output format: 'content' returns matched lines with line numbers (default), 'files_with_matches' returns only file paths with matches, 'count' returns match counts per file."},max_results:{type:"number",description:"Maximum number of matched lines to return (content mode). Default 1000."}},required:["pattern"],additionalProperties:!1},async execute(n){const t=_(n,["pattern"],"pattern"),e=O(n,["path"])||".",i=O(n,["include"]),r=O(n,["exclude"]),c=n.case_insensitive===!0,s=(()=>{const g=n.output_mode;return g==="files_with_matches"||g==="count"?g:"content"})(),a=A(n,["max_results"],ot),d=c?"i":"";let p;try{p=new RegExp(t,d)}catch(g){throw new Error(`Invalid regex pattern: ${g instanceof Error?g.message:String(g)}`)}const l=i?G(i):null,I=r?G(r):null,m=await R(o,e),w=E(m.workspaceRoot,await u.realpath(m.targetPath)),S=await u.stat(w);let P;if(S.isFile())P=[w];else if(S.isDirectory())P=await ut(w,l,I,tt);else throw new Error(`Path is neither a file nor a directory: ${w}`);const h=[],b=[],M=[];let L=0,x=0,k=!1;for(const g of P){if(s==="content"&&h.length>=a){k=!0;break}const z={regex:p,maxResults:s==="content"?a-h.length:Number.MAX_SAFE_INTEGER,collectContent:s==="content",stopOnFirstMatch:s==="files_with_matches"},F=await dt(g,m.workspaceRoot,z);if(F.count>0){const N=f.relative(m.workspaceRoot,g).replace(/\\/g,"/");if(M.push(N),L+=F.count,s==="content"){for(const $ of F.matches){const B=Buffer.byteLength($.content,"utf-8")+64;if(x+B>nt){k=!0;break}x+=B,h.push($)}if(k)break;if(h.length>=a){k=!0;break}}else s==="count"&&b.push({file:N,count:F.count})}}const T={ok:!0,tool:"grep",pattern:t,searchPath:y(m.targetPath),outputMode:s,filesSearched:P.length,filesMatched:M.length,totalMatches:L,truncated:k};return s==="content"?T.matches=h:s==="files_with_matches"?T.matches=M:T.matches=b,T}}}function Rt(o,n,t){const e=n||"unknown";return[yt(o),mt(o,t),wt(o,t),gt(o,t),Pt(o),_t(o,e),V(o)]}export{Rt as createBuiltInFileTools,E as ensureInsideWorkspace,R as resolveWorkspaceTarget};
4
+