@mohanscodex/spectra-code 0.4.5

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 (319) hide show
  1. package/README.md +275 -0
  2. package/dist/package.json +62 -0
  3. package/dist/src/agents/definitions.d.ts +16 -0
  4. package/dist/src/agents/definitions.d.ts.map +1 -0
  5. package/dist/src/agents/definitions.js +148 -0
  6. package/dist/src/agents/definitions.js.map +1 -0
  7. package/dist/src/agents/registry.d.ts +11 -0
  8. package/dist/src/agents/registry.d.ts.map +1 -0
  9. package/dist/src/agents/registry.js +13 -0
  10. package/dist/src/agents/registry.js.map +1 -0
  11. package/dist/src/cli.d.ts +3 -0
  12. package/dist/src/cli.d.ts.map +1 -0
  13. package/dist/src/cli.js +436 -0
  14. package/dist/src/cli.js.map +1 -0
  15. package/dist/src/commands/agent.d.ts +3 -0
  16. package/dist/src/commands/agent.d.ts.map +1 -0
  17. package/dist/src/commands/agent.js +28 -0
  18. package/dist/src/commands/agent.js.map +1 -0
  19. package/dist/src/commands/db.d.ts +3 -0
  20. package/dist/src/commands/db.d.ts.map +1 -0
  21. package/dist/src/commands/db.js +47 -0
  22. package/dist/src/commands/db.js.map +1 -0
  23. package/dist/src/commands/doctor.d.ts +12 -0
  24. package/dist/src/commands/doctor.d.ts.map +1 -0
  25. package/dist/src/commands/doctor.js +59 -0
  26. package/dist/src/commands/doctor.js.map +1 -0
  27. package/dist/src/commands/mcp.d.ts +9 -0
  28. package/dist/src/commands/mcp.d.ts.map +1 -0
  29. package/dist/src/commands/mcp.js +208 -0
  30. package/dist/src/commands/mcp.js.map +1 -0
  31. package/dist/src/commands/plugin.d.ts +3 -0
  32. package/dist/src/commands/plugin.d.ts.map +1 -0
  33. package/dist/src/commands/plugin.js +36 -0
  34. package/dist/src/commands/plugin.js.map +1 -0
  35. package/dist/src/commands/session.d.ts +3 -0
  36. package/dist/src/commands/session.d.ts.map +1 -0
  37. package/dist/src/commands/session.js +49 -0
  38. package/dist/src/commands/session.js.map +1 -0
  39. package/dist/src/index.d.ts +19 -0
  40. package/dist/src/index.d.ts.map +1 -0
  41. package/dist/src/index.js +17 -0
  42. package/dist/src/index.js.map +1 -0
  43. package/dist/src/integrations/acp/index.d.ts +2 -0
  44. package/dist/src/integrations/acp/index.d.ts.map +1 -0
  45. package/dist/src/integrations/acp/index.js +2 -0
  46. package/dist/src/integrations/acp/index.js.map +1 -0
  47. package/dist/src/integrations/acp/server.d.ts +11 -0
  48. package/dist/src/integrations/acp/server.d.ts.map +1 -0
  49. package/dist/src/integrations/acp/server.js +220 -0
  50. package/dist/src/integrations/acp/server.js.map +1 -0
  51. package/dist/src/integrations/custom-tools/index.d.ts +3 -0
  52. package/dist/src/integrations/custom-tools/index.d.ts.map +1 -0
  53. package/dist/src/integrations/custom-tools/index.js +2 -0
  54. package/dist/src/integrations/custom-tools/index.js.map +1 -0
  55. package/dist/src/integrations/custom-tools/loader.d.ts +16 -0
  56. package/dist/src/integrations/custom-tools/loader.d.ts.map +1 -0
  57. package/dist/src/integrations/custom-tools/loader.js +95 -0
  58. package/dist/src/integrations/custom-tools/loader.js.map +1 -0
  59. package/dist/src/integrations/mcp/client.d.ts +32 -0
  60. package/dist/src/integrations/mcp/client.d.ts.map +1 -0
  61. package/dist/src/integrations/mcp/client.js +117 -0
  62. package/dist/src/integrations/mcp/client.js.map +1 -0
  63. package/dist/src/integrations/mcp/index.d.ts +3 -0
  64. package/dist/src/integrations/mcp/index.d.ts.map +1 -0
  65. package/dist/src/integrations/mcp/index.js +2 -0
  66. package/dist/src/integrations/mcp/index.js.map +1 -0
  67. package/dist/src/security/doom-loop.d.ts +22 -0
  68. package/dist/src/security/doom-loop.d.ts.map +1 -0
  69. package/dist/src/security/doom-loop.js +72 -0
  70. package/dist/src/security/doom-loop.js.map +1 -0
  71. package/dist/src/security/index.d.ts +46 -0
  72. package/dist/src/security/index.d.ts.map +1 -0
  73. package/dist/src/security/index.js +362 -0
  74. package/dist/src/security/index.js.map +1 -0
  75. package/dist/src/security/path-safety.d.ts +15 -0
  76. package/dist/src/security/path-safety.d.ts.map +1 -0
  77. package/dist/src/security/path-safety.js +57 -0
  78. package/dist/src/security/path-safety.js.map +1 -0
  79. package/dist/src/security/permissions.d.ts +7 -0
  80. package/dist/src/security/permissions.d.ts.map +1 -0
  81. package/dist/src/security/permissions.js +41 -0
  82. package/dist/src/security/permissions.js.map +1 -0
  83. package/dist/src/security/read-tracker.d.ts +20 -0
  84. package/dist/src/security/read-tracker.d.ts.map +1 -0
  85. package/dist/src/security/read-tracker.js +73 -0
  86. package/dist/src/security/read-tracker.js.map +1 -0
  87. package/dist/src/security/ssrf-guard.d.ts +19 -0
  88. package/dist/src/security/ssrf-guard.d.ts.map +1 -0
  89. package/dist/src/security/ssrf-guard.js +98 -0
  90. package/dist/src/security/ssrf-guard.js.map +1 -0
  91. package/dist/src/security/types.d.ts +70 -0
  92. package/dist/src/security/types.d.ts.map +1 -0
  93. package/dist/src/security/types.js +2 -0
  94. package/dist/src/security/types.js.map +1 -0
  95. package/dist/src/security/wildcard.d.ts +5 -0
  96. package/dist/src/security/wildcard.d.ts.map +1 -0
  97. package/dist/src/security/wildcard.js +50 -0
  98. package/dist/src/security/wildcard.js.map +1 -0
  99. package/dist/src/services/auth-store.d.ts +25 -0
  100. package/dist/src/services/auth-store.d.ts.map +1 -0
  101. package/dist/src/services/auth-store.js +40 -0
  102. package/dist/src/services/auth-store.js.map +1 -0
  103. package/dist/src/services/config.d.ts +66 -0
  104. package/dist/src/services/config.d.ts.map +1 -0
  105. package/dist/src/services/config.js +83 -0
  106. package/dist/src/services/config.js.map +1 -0
  107. package/dist/src/services/context.d.ts +7 -0
  108. package/dist/src/services/context.d.ts.map +1 -0
  109. package/dist/src/services/context.js +23 -0
  110. package/dist/src/services/context.js.map +1 -0
  111. package/dist/src/services/custom-providers.d.ts +5 -0
  112. package/dist/src/services/custom-providers.d.ts.map +1 -0
  113. package/dist/src/services/custom-providers.js +213 -0
  114. package/dist/src/services/custom-providers.js.map +1 -0
  115. package/dist/src/services/session-store.d.ts +76 -0
  116. package/dist/src/services/session-store.d.ts.map +1 -0
  117. package/dist/src/services/session-store.js +199 -0
  118. package/dist/src/services/session-store.js.map +1 -0
  119. package/dist/src/services/snapshot-manager.d.ts +46 -0
  120. package/dist/src/services/snapshot-manager.d.ts.map +1 -0
  121. package/dist/src/services/snapshot-manager.js +183 -0
  122. package/dist/src/services/snapshot-manager.js.map +1 -0
  123. package/dist/src/tools/edit.d.ts +3 -0
  124. package/dist/src/tools/edit.d.ts.map +1 -0
  125. package/dist/src/tools/edit.js +57 -0
  126. package/dist/src/tools/edit.js.map +1 -0
  127. package/dist/src/tools/glob.d.ts +3 -0
  128. package/dist/src/tools/glob.d.ts.map +1 -0
  129. package/dist/src/tools/glob.js +46 -0
  130. package/dist/src/tools/glob.js.map +1 -0
  131. package/dist/src/tools/grep.d.ts +3 -0
  132. package/dist/src/tools/grep.d.ts.map +1 -0
  133. package/dist/src/tools/grep.js +50 -0
  134. package/dist/src/tools/grep.js.map +1 -0
  135. package/dist/src/tools/index.d.ts +26 -0
  136. package/dist/src/tools/index.d.ts.map +1 -0
  137. package/dist/src/tools/index.js +202 -0
  138. package/dist/src/tools/index.js.map +1 -0
  139. package/dist/src/tools/mcp-tool.d.ts +5 -0
  140. package/dist/src/tools/mcp-tool.d.ts.map +1 -0
  141. package/dist/src/tools/mcp-tool.js +82 -0
  142. package/dist/src/tools/mcp-tool.js.map +1 -0
  143. package/dist/src/tools/read.d.ts +3 -0
  144. package/dist/src/tools/read.d.ts.map +1 -0
  145. package/dist/src/tools/read.js +48 -0
  146. package/dist/src/tools/read.js.map +1 -0
  147. package/dist/src/tools/shell.d.ts +3 -0
  148. package/dist/src/tools/shell.d.ts.map +1 -0
  149. package/dist/src/tools/shell.js +266 -0
  150. package/dist/src/tools/shell.js.map +1 -0
  151. package/dist/src/tools/task.d.ts +3 -0
  152. package/dist/src/tools/task.d.ts.map +1 -0
  153. package/dist/src/tools/task.js +75 -0
  154. package/dist/src/tools/task.js.map +1 -0
  155. package/dist/src/tools/types.d.ts +18 -0
  156. package/dist/src/tools/types.d.ts.map +1 -0
  157. package/dist/src/tools/types.js +2 -0
  158. package/dist/src/tools/types.js.map +1 -0
  159. package/dist/src/tools/utils.d.ts +4 -0
  160. package/dist/src/tools/utils.d.ts.map +1 -0
  161. package/dist/src/tools/utils.js +10 -0
  162. package/dist/src/tools/utils.js.map +1 -0
  163. package/dist/src/tools/web-fetch.d.ts +3 -0
  164. package/dist/src/tools/web-fetch.d.ts.map +1 -0
  165. package/dist/src/tools/web-fetch.js +81 -0
  166. package/dist/src/tools/web-fetch.js.map +1 -0
  167. package/dist/src/tools/write.d.ts +3 -0
  168. package/dist/src/tools/write.d.ts.map +1 -0
  169. package/dist/src/tools/write.js +28 -0
  170. package/dist/src/tools/write.js.map +1 -0
  171. package/dist/src/tui/app-constants.d.ts +3 -0
  172. package/dist/src/tui/app-constants.d.ts.map +1 -0
  173. package/dist/src/tui/app-constants.js +4 -0
  174. package/dist/src/tui/app-constants.js.map +1 -0
  175. package/dist/src/tui/app.d.ts +5 -0
  176. package/dist/src/tui/app.d.ts.map +1 -0
  177. package/dist/src/tui/app.js +322 -0
  178. package/dist/src/tui/app.js.map +1 -0
  179. package/dist/src/tui/commands.d.ts +61 -0
  180. package/dist/src/tui/commands.d.ts.map +1 -0
  181. package/dist/src/tui/commands.js +95 -0
  182. package/dist/src/tui/commands.js.map +1 -0
  183. package/dist/src/tui/components/chat-area.d.ts +9 -0
  184. package/dist/src/tui/components/chat-area.d.ts.map +1 -0
  185. package/dist/src/tui/components/chat-area.js +12 -0
  186. package/dist/src/tui/components/chat-area.js.map +1 -0
  187. package/dist/src/tui/components/command-palette.d.ts +18 -0
  188. package/dist/src/tui/components/command-palette.d.ts.map +1 -0
  189. package/dist/src/tui/components/command-palette.js +50 -0
  190. package/dist/src/tui/components/command-palette.js.map +1 -0
  191. package/dist/src/tui/components/message.d.ts +9 -0
  192. package/dist/src/tui/components/message.d.ts.map +1 -0
  193. package/dist/src/tui/components/message.js +116 -0
  194. package/dist/src/tui/components/message.js.map +1 -0
  195. package/dist/src/tui/components/slash-autocomplete.d.ts +14 -0
  196. package/dist/src/tui/components/slash-autocomplete.d.ts.map +1 -0
  197. package/dist/src/tui/components/slash-autocomplete.js +29 -0
  198. package/dist/src/tui/components/slash-autocomplete.js.map +1 -0
  199. package/dist/src/tui/components/toast.d.ts +8 -0
  200. package/dist/src/tui/components/toast.d.ts.map +1 -0
  201. package/dist/src/tui/components/toast.js +29 -0
  202. package/dist/src/tui/components/toast.js.map +1 -0
  203. package/dist/src/tui/hooks/use-agent.d.ts +20 -0
  204. package/dist/src/tui/hooks/use-agent.d.ts.map +1 -0
  205. package/dist/src/tui/hooks/use-agent.js +129 -0
  206. package/dist/src/tui/hooks/use-agent.js.map +1 -0
  207. package/dist/src/tui/hooks/use-app-keyboard.d.ts +53 -0
  208. package/dist/src/tui/hooks/use-app-keyboard.d.ts.map +1 -0
  209. package/dist/src/tui/hooks/use-app-keyboard.js +155 -0
  210. package/dist/src/tui/hooks/use-app-keyboard.js.map +1 -0
  211. package/dist/src/tui/hooks/use-chat-submit.d.ts +61 -0
  212. package/dist/src/tui/hooks/use-chat-submit.d.ts.map +1 -0
  213. package/dist/src/tui/hooks/use-chat-submit.js +269 -0
  214. package/dist/src/tui/hooks/use-chat-submit.js.map +1 -0
  215. package/dist/src/tui/hooks/use-permission-queue.d.ts +10 -0
  216. package/dist/src/tui/hooks/use-permission-queue.d.ts.map +1 -0
  217. package/dist/src/tui/hooks/use-permission-queue.js +26 -0
  218. package/dist/src/tui/hooks/use-permission-queue.js.map +1 -0
  219. package/dist/src/tui/hooks/use-revert.d.ts +26 -0
  220. package/dist/src/tui/hooks/use-revert.d.ts.map +1 -0
  221. package/dist/src/tui/hooks/use-revert.js +88 -0
  222. package/dist/src/tui/hooks/use-revert.js.map +1 -0
  223. package/dist/src/tui/index.d.ts +5 -0
  224. package/dist/src/tui/index.d.ts.map +1 -0
  225. package/dist/src/tui/index.js +38 -0
  226. package/dist/src/tui/index.js.map +1 -0
  227. package/dist/src/tui/prompt-bar.d.ts +29 -0
  228. package/dist/src/tui/prompt-bar.d.ts.map +1 -0
  229. package/dist/src/tui/prompt-bar.js +41 -0
  230. package/dist/src/tui/prompt-bar.js.map +1 -0
  231. package/dist/src/tui/slash-commands.d.ts +20 -0
  232. package/dist/src/tui/slash-commands.d.ts.map +1 -0
  233. package/dist/src/tui/slash-commands.js +30 -0
  234. package/dist/src/tui/slash-commands.js.map +1 -0
  235. package/dist/src/tui/theme.d.ts +29 -0
  236. package/dist/src/tui/theme.d.ts.map +1 -0
  237. package/dist/src/tui/theme.js +54 -0
  238. package/dist/src/tui/theme.js.map +1 -0
  239. package/dist/src/tui/tips.d.ts +2 -0
  240. package/dist/src/tui/tips.d.ts.map +1 -0
  241. package/dist/src/tui/tips.js +40 -0
  242. package/dist/src/tui/tips.js.map +1 -0
  243. package/dist/src/tui/types.d.ts +34 -0
  244. package/dist/src/tui/types.d.ts.map +1 -0
  245. package/dist/src/tui/types.js +2 -0
  246. package/dist/src/tui/types.js.map +1 -0
  247. package/dist/src/tui/ui/about-dialog.d.ts +8 -0
  248. package/dist/src/tui/ui/about-dialog.d.ts.map +1 -0
  249. package/dist/src/tui/ui/about-dialog.js +21 -0
  250. package/dist/src/tui/ui/about-dialog.js.map +1 -0
  251. package/dist/src/tui/ui/agent-switcher.d.ts +10 -0
  252. package/dist/src/tui/ui/agent-switcher.d.ts.map +1 -0
  253. package/dist/src/tui/ui/agent-switcher.js +77 -0
  254. package/dist/src/tui/ui/agent-switcher.js.map +1 -0
  255. package/dist/src/tui/ui/debug-dialog.d.ts +15 -0
  256. package/dist/src/tui/ui/debug-dialog.d.ts.map +1 -0
  257. package/dist/src/tui/ui/debug-dialog.js +74 -0
  258. package/dist/src/tui/ui/debug-dialog.js.map +1 -0
  259. package/dist/src/tui/ui/doctor-dialog.d.ts +9 -0
  260. package/dist/src/tui/ui/doctor-dialog.d.ts.map +1 -0
  261. package/dist/src/tui/ui/doctor-dialog.js +45 -0
  262. package/dist/src/tui/ui/doctor-dialog.js.map +1 -0
  263. package/dist/src/tui/ui/manage-providers-dialog.d.ts +10 -0
  264. package/dist/src/tui/ui/manage-providers-dialog.d.ts.map +1 -0
  265. package/dist/src/tui/ui/manage-providers-dialog.js +257 -0
  266. package/dist/src/tui/ui/manage-providers-dialog.js.map +1 -0
  267. package/dist/src/tui/ui/mcp-toggle-dialog.d.ts +8 -0
  268. package/dist/src/tui/ui/mcp-toggle-dialog.d.ts.map +1 -0
  269. package/dist/src/tui/ui/mcp-toggle-dialog.js +89 -0
  270. package/dist/src/tui/ui/mcp-toggle-dialog.js.map +1 -0
  271. package/dist/src/tui/ui/message-controls.d.ts +16 -0
  272. package/dist/src/tui/ui/message-controls.d.ts.map +1 -0
  273. package/dist/src/tui/ui/message-controls.js +102 -0
  274. package/dist/src/tui/ui/message-controls.js.map +1 -0
  275. package/dist/src/tui/ui/model-switcher.d.ts +10 -0
  276. package/dist/src/tui/ui/model-switcher.d.ts.map +1 -0
  277. package/dist/src/tui/ui/model-switcher.js +139 -0
  278. package/dist/src/tui/ui/model-switcher.js.map +1 -0
  279. package/dist/src/tui/ui/permission-dialog.d.ts +12 -0
  280. package/dist/src/tui/ui/permission-dialog.d.ts.map +1 -0
  281. package/dist/src/tui/ui/permission-dialog.js +37 -0
  282. package/dist/src/tui/ui/permission-dialog.js.map +1 -0
  283. package/dist/src/tui/ui/provider-dialog.d.ts +11 -0
  284. package/dist/src/tui/ui/provider-dialog.d.ts.map +1 -0
  285. package/dist/src/tui/ui/provider-dialog.js +232 -0
  286. package/dist/src/tui/ui/provider-dialog.js.map +1 -0
  287. package/dist/src/tui/ui/session-list.d.ts +23 -0
  288. package/dist/src/tui/ui/session-list.d.ts.map +1 -0
  289. package/dist/src/tui/ui/session-list.js +147 -0
  290. package/dist/src/tui/ui/session-list.js.map +1 -0
  291. package/dist/src/tui/ui/thinking-effort-dialog.d.ts +11 -0
  292. package/dist/src/tui/ui/thinking-effort-dialog.d.ts.map +1 -0
  293. package/dist/src/tui/ui/thinking-effort-dialog.js +79 -0
  294. package/dist/src/tui/ui/thinking-effort-dialog.js.map +1 -0
  295. package/dist/src/tui/utils/model-config.d.ts +9 -0
  296. package/dist/src/tui/utils/model-config.d.ts.map +1 -0
  297. package/dist/src/tui/utils/model-config.js +63 -0
  298. package/dist/src/tui/utils/model-config.js.map +1 -0
  299. package/dist/src/tui/utils/session-messages.d.ts +22 -0
  300. package/dist/src/tui/utils/session-messages.d.ts.map +1 -0
  301. package/dist/src/tui/utils/session-messages.js +62 -0
  302. package/dist/src/tui/utils/session-messages.js.map +1 -0
  303. package/dist/src/tui/utils.d.ts +6 -0
  304. package/dist/src/tui/utils.d.ts.map +1 -0
  305. package/dist/src/tui/utils.js +23 -0
  306. package/dist/src/tui/utils.js.map +1 -0
  307. package/dist/src/tui/variant-cycle.d.ts +10 -0
  308. package/dist/src/tui/variant-cycle.d.ts.map +1 -0
  309. package/dist/src/tui/variant-cycle.js +64 -0
  310. package/dist/src/tui/variant-cycle.js.map +1 -0
  311. package/dist/src/utils/paths.d.ts +10 -0
  312. package/dist/src/utils/paths.d.ts.map +1 -0
  313. package/dist/src/utils/paths.js +106 -0
  314. package/dist/src/utils/paths.js.map +1 -0
  315. package/dist/src/utils/platform.d.ts +10 -0
  316. package/dist/src/utils/platform.d.ts.map +1 -0
  317. package/dist/src/utils/platform.js +133 -0
  318. package/dist/src/utils/platform.js.map +1 -0
  319. package/package.json +62 -0
@@ -0,0 +1,183 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "fs";
2
+ import { dirname, join, relative, resolve } from "path";
3
+ import { getGlobalDataDir } from "../utils/paths.js";
4
+ const FILE_MODE = 0o600;
5
+ const DIR_MODE = 0o700;
6
+ export class SnapshotManager {
7
+ workdir;
8
+ snapshotDir;
9
+ disabled;
10
+ maxFileSize;
11
+ active = null;
12
+ constructor(options) {
13
+ this.workdir = options?.workdir || process.cwd();
14
+ this.snapshotDir =
15
+ options?.snapshotDir || join(getGlobalDataDir(), "snapshots");
16
+ this.disabled = options?.disabled || false;
17
+ this.maxFileSize = options?.maxFileSize || 5 * 1024 * 1024; // 5MB
18
+ }
19
+ /** Open a new checkpoint. Returns checkpoint ID. */
20
+ begin(label) {
21
+ if (this.disabled)
22
+ return null;
23
+ if (this.active)
24
+ this.commit(); // close prior
25
+ const id = Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
26
+ this.active = {
27
+ id,
28
+ label: String(label || "checkpoint").slice(0, 80),
29
+ startedAt: Date.now(),
30
+ files: new Map(),
31
+ };
32
+ return id;
33
+ }
34
+ /** Snapshot a file's pre-edit content. Idempotent — first snapshot wins. */
35
+ note(filePath, before) {
36
+ if (this.disabled || !this.active)
37
+ return;
38
+ const abs = resolve(this.workdir, filePath);
39
+ // Containment — only snapshot files inside workspace root
40
+ const rel = relative(this.workdir, abs);
41
+ if (rel.startsWith("..") || rel.startsWith("."))
42
+ return;
43
+ if (this.active.files.has(abs))
44
+ return; // first-snapshot-wins
45
+ let content = before;
46
+ let existed = false;
47
+ if (content === undefined || content === null) {
48
+ try {
49
+ const stat = statSync(abs);
50
+ if (stat.size > this.maxFileSize) {
51
+ this.active.files.set(abs, { tooLarge: true, existed: true });
52
+ return;
53
+ }
54
+ content = readFileSync(abs, "utf-8");
55
+ existed = true;
56
+ }
57
+ catch (e) {
58
+ if (e.code === "ENOENT") {
59
+ this.active.files.set(abs, { before: null, existed: false });
60
+ return;
61
+ }
62
+ this.active.files.set(abs, { skipped: true, existed: true });
63
+ return;
64
+ }
65
+ }
66
+ else {
67
+ existed = true;
68
+ }
69
+ this.active.files.set(abs, { before: content, existed });
70
+ }
71
+ /**
72
+ * Roll back every file recorded since the last begin().
73
+ * Files snapshotted as nonexistent are deleted.
74
+ * Files with stored content are restored.
75
+ */
76
+ rollback(reason = "verification failed") {
77
+ if (this.disabled || !this.active) {
78
+ return {
79
+ checkpointId: "",
80
+ label: "",
81
+ restored: 0,
82
+ deleted: 0,
83
+ errors: [],
84
+ skipped: [],
85
+ reason,
86
+ };
87
+ }
88
+ const cp = this.active;
89
+ const restored = [];
90
+ const deleted = [];
91
+ const errors = [];
92
+ const skipped = [];
93
+ for (const [abs, snap] of cp.files.entries()) {
94
+ try {
95
+ if (snap.tooLarge) {
96
+ skipped.push({ path: abs, reason: "file too large to snapshot" });
97
+ continue;
98
+ }
99
+ if (snap.skipped) {
100
+ skipped.push({ path: abs, reason: "snapshot read failed" });
101
+ continue;
102
+ }
103
+ if (!snap.existed) {
104
+ // Was new — delete it
105
+ if (existsSync(abs)) {
106
+ unlinkSync(abs);
107
+ deleted.push(abs);
108
+ }
109
+ }
110
+ else if (snap.before !== undefined && snap.before !== null) {
111
+ // Restore content
112
+ const dir = dirname(abs);
113
+ if (!existsSync(dir))
114
+ mkdirSync(dir, { recursive: true });
115
+ writeFileSync(abs, snap.before);
116
+ restored.push(abs);
117
+ }
118
+ }
119
+ catch (e) {
120
+ errors.push({ path: abs, error: e.message || String(e) });
121
+ }
122
+ }
123
+ this._persist(cp, { reason, restored, deleted, errors, skipped, rolledBack: true });
124
+ this.active = null;
125
+ return {
126
+ checkpointId: cp.id,
127
+ label: cp.label,
128
+ restored: restored.length,
129
+ deleted: deleted.length,
130
+ errors,
131
+ skipped,
132
+ reason,
133
+ };
134
+ }
135
+ /** Discard the active checkpoint without restoring anything. */
136
+ commit() {
137
+ if (this.disabled || !this.active)
138
+ return null;
139
+ const cp = this.active;
140
+ this._persist(cp, { rolledBack: false, committed: true });
141
+ this.active = null;
142
+ return cp.id;
143
+ }
144
+ isActive() {
145
+ return !!this.active;
146
+ }
147
+ size() {
148
+ return this.active ? this.active.files.size : 0;
149
+ }
150
+ reset() {
151
+ this.active = null;
152
+ }
153
+ // ─── Internal ──────────────────────────────────────────────────────────
154
+ _persist(cp, outcome) {
155
+ if (this.disabled)
156
+ return;
157
+ try {
158
+ if (!existsSync(this.snapshotDir)) {
159
+ mkdirSync(this.snapshotDir, { recursive: true, mode: DIR_MODE });
160
+ }
161
+ const id = String(cp.id || "").replace(/[^A-Za-z0-9_-]/g, "");
162
+ if (!id)
163
+ return;
164
+ const filePath = join(this.snapshotDir, `${id}.json`);
165
+ const summary = {
166
+ id: cp.id,
167
+ label: cp.label,
168
+ startedAt: new Date(cp.startedAt).toISOString(),
169
+ endedAt: new Date().toISOString(),
170
+ fileCount: cp.files.size,
171
+ files: [...cp.files.keys()].slice(0, 50),
172
+ outcome,
173
+ };
174
+ const tmp = filePath + `.tmp.${process.pid}`;
175
+ writeFileSync(tmp, JSON.stringify(summary, null, 2), { mode: FILE_MODE });
176
+ renameSync(tmp, filePath);
177
+ }
178
+ catch {
179
+ // never fail the agent loop on persistence errors
180
+ }
181
+ }
182
+ }
183
+ //# sourceMappingURL=snapshot-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-manager.js","sourceRoot":"","sources":["../../../src/services/snapshot-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,SAAS,GAAG,KAAK,CAAC;AACxB,MAAM,QAAQ,GAAG,KAAK,CAAC;AA0BvB,MAAM,OAAO,eAAe;IAClB,OAAO,CAAS;IAChB,WAAW,CAAS;IACpB,QAAQ,CAAU;IAClB,WAAW,CAAS;IACpB,MAAM,GAAsB,IAAI,CAAC;IAEzC,YAAY,OAA8F;QACxG,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE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,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACjC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI;gBACxB,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;gBACxC,OAAO;aACR,CAAC;YACF,MAAM,GAAG,GAAG,QAAQ,GAAG,QAAQ,OAAO,CAAC,GAAG,EAAE,CAAC;YAC7C,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YAC1E,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACP,kDAAkD;QACpD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import type { SpectraTool } from "./types.js";
2
+ export declare const editTool: SpectraTool;
3
+ //# sourceMappingURL=edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/tools/edit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,QAAQ,EAAE,WAuCtB,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ import { errorResult, textResult } from "./utils.js";
3
+ import { readFileSync, writeFileSync, existsSync } from "fs";
4
+ import { resolve, relative } from "path";
5
+ export const editTool = {
6
+ name: "edit",
7
+ capabilities: { reads: false, writes: true },
8
+ description: `Edit a file by finding and replacing text.
9
+ The tool finds the exact old string in the file and replaces it with the new string.
10
+ For best results:
11
+ - Include enough surrounding context in the old string for a unique match
12
+ - Use exact text including whitespace
13
+ - If the old string appears multiple times, include more context to disambiguate
14
+ Prefer the write tool for large or new files.`,
15
+ displayName: (args) => relative(process.cwd(), resolve(args.path)),
16
+ parameters: z.object({
17
+ path: z.string().describe("Absolute or relative path to the file to edit"),
18
+ oldString: z.string().describe("The exact text to find and replace"),
19
+ newString: z.string().describe("The replacement text"),
20
+ }),
21
+ execute: async ({ path, oldString, newString }) => {
22
+ const resolved = resolve(process.cwd(), path);
23
+ if (!existsSync(resolved)) {
24
+ return errorResult(`File not found: ${resolved}`);
25
+ }
26
+ const content = readFileSync(resolved, "utf-8");
27
+ if (!content.includes(oldString)) {
28
+ return errorResult(`Could not find the specified text in ${relative(process.cwd(), resolved)}.
29
+ The text may have different whitespace or formatting. Try reading the file first.`);
30
+ }
31
+ const newContent = content.replace(oldString, newString);
32
+ if (newContent === content) {
33
+ return errorResult("No changes made - the replacement didn't modify the file.");
34
+ }
35
+ writeFileSync(resolved, newContent, "utf-8");
36
+ return textResult(`Applied edit to ${relative(process.cwd(), resolved)}
37
+
38
+ Changes made (showing context):
39
+ ${showDiff(content, newString, oldString)}`);
40
+ },
41
+ };
42
+ function showDiff(original, newStr, oldStr) {
43
+ const idx = original.indexOf(oldStr);
44
+ if (idx < 0)
45
+ return "";
46
+ const before = original.slice(Math.max(0, idx - 40), idx);
47
+ const after = original.slice(idx + oldStr.length, idx + oldStr.length + 40);
48
+ return [
49
+ "...",
50
+ before ? `${before}` : "",
51
+ `- ${oldStr.slice(0, 80)}`,
52
+ `+ ${newStr.slice(0, 80)}`,
53
+ after ? `${after}` : "",
54
+ "...",
55
+ ].filter(Boolean).join("\n");
56
+ }
57
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;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C;AAC/B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SpectraTool } from "./types.js";
2
+ export declare const globTool: SpectraTool;
3
+ //# sourceMappingURL=glob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/tools/glob.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,QAAQ,EAAE,WAyCtB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { errorResult, textResult } from "./utils.js";
3
+ import { execSync } from "child_process";
4
+ import { resolve } from "path";
5
+ export const globTool = {
6
+ name: "glob",
7
+ capabilities: { reads: true, writes: false },
8
+ description: `Find files matching a glob pattern.
9
+ Supports common glob patterns like **/*.ts, src/**/*.css, etc.
10
+ Searches from the specified directory or current working directory.
11
+ Results are limited to prevent overwhelming output.`,
12
+ displayName: (args) => args.pattern,
13
+ parameters: z.object({
14
+ pattern: z.string().describe("Glob pattern to match files (e.g. '**/*.ts', 'src/**/*.css')"),
15
+ path: z.string().optional().describe("Directory to search in (defaults to cwd)"),
16
+ maxResults: z.number().optional().describe("Maximum number of results to return"),
17
+ }),
18
+ execute: async ({ pattern, path, maxResults }) => {
19
+ const searchDir = path ? resolve(process.cwd(), path) : process.cwd();
20
+ const limit = maxResults || 100;
21
+ try {
22
+ const hasFd = execSync("which fdfind 2>/dev/null || which fd 2>/dev/null || where fd 2>nul", { encoding: "utf-8", timeout: 1000 }).trim().length > 0;
23
+ let cmd;
24
+ if (hasFd) {
25
+ cmd = `fd "${pattern}" "${searchDir}" --no-ignore -H 2>/dev/null | head -${limit}`;
26
+ }
27
+ else {
28
+ cmd = process.platform === "win32"
29
+ ? `powershell -Command "Get-ChildItem -Path '${searchDir}' -Recurse -Filter '${pattern}' -ErrorAction SilentlyContinue | Select-Object -First ${limit} | %% { $_.FullName }"`
30
+ : `find "${searchDir}" -name "${pattern}" 2>/dev/null | head -${limit}`;
31
+ }
32
+ const stdout = execSync(cmd, { encoding: "utf-8", timeout: 15000, maxBuffer: 1024 * 1024 });
33
+ const results = stdout.trim();
34
+ if (!results)
35
+ return textResult("No files matched the pattern.");
36
+ const lines = results.split("\n");
37
+ const truncated = lines.length >= limit;
38
+ return textResult(lines.join("\n") + (truncated ? `\n... (${lines.length} results, truncated at ${limit})` : ""));
39
+ }
40
+ catch (err) {
41
+ const error = err;
42
+ return errorResult(`Glob search failed: ${error.message || "unknown error"}`);
43
+ }
44
+ },
45
+ };
46
+ //# sourceMappingURL=glob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/tools/glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,CAAC,MAAM,QAAQ,GAAgB;IACnC,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IAC5C,WAAW,EAAE;;;oDAGqC;IAClD,WAAW,EAAE,CAAC,IAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO;IACxD,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8DAA8D,CAAC;QAC5F,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;QAChF,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;KAClF,CAAC;IACF,OAAO,EA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KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,MAAM,0BAA0B,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpH,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,GAA2B,CAAC;YAC1C,OAAO,WAAW,CAAC,uBAAuB,KAAK,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SpectraTool } from "./types.js";
2
+ export declare const grepTool: SpectraTool;
3
+ //# sourceMappingURL=grep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../src/tools/grep.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,QAAQ,EAAE,WA4CtB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { errorResult, textResult } from "./utils.js";
3
+ import { execSync } from "child_process";
4
+ import { resolve } from "path";
5
+ export const grepTool = {
6
+ name: "grep",
7
+ capabilities: { reads: true, writes: false },
8
+ description: `Search file contents using regular expressions.
9
+ Uses ripgrep (rg) if available, otherwise falls back to grep.
10
+ Returns matching file paths, line numbers, and the matched lines.
11
+ Results are truncated to prevent large outputs.`,
12
+ displayName: (args) => `"${args.pattern}"`,
13
+ parameters: z.object({
14
+ pattern: z.string().describe("The regex pattern to search for"),
15
+ include: z.string().optional().describe("File pattern to include (e.g. '*.ts', '*.{ts,js}')"),
16
+ path: z.string().optional().describe("Directory to search in (defaults to cwd)"),
17
+ maxResults: z.number().optional().describe("Maximum number of results to return"),
18
+ }),
19
+ execute: async ({ pattern, include, path, maxResults }) => {
20
+ const searchDir = path ? resolve(process.cwd(), path) : process.cwd();
21
+ const limit = maxResults || 50;
22
+ try {
23
+ let cmd;
24
+ const useRipgrep = execSync("which rg 2>/dev/null || where rg 2>nul", { encoding: "utf-8", timeout: 1000 }).trim().length > 0;
25
+ if (useRipgrep) {
26
+ const includeFlag = include ? `-g "${include}"` : "";
27
+ cmd = `rg -n --no-heading "${pattern}" "${searchDir}" ${includeFlag} | head -${limit}`;
28
+ }
29
+ else {
30
+ const includeFlag = include ? `--include="${include}"` : "";
31
+ cmd = `grep -rn "${pattern}" "${searchDir}" ${includeFlag} 2>/dev/null | head -${limit}`;
32
+ }
33
+ const stdout = execSync(cmd, { encoding: "utf-8", timeout: 15000, maxBuffer: 1024 * 1024 });
34
+ const results = stdout.trim();
35
+ if (!results)
36
+ return textResult("No matches found.");
37
+ const lineCount = results.split("\n").length;
38
+ const truncated = lineCount >= limit;
39
+ return textResult(results + (truncated ? `\n... (truncated at ${limit} results)` : ""));
40
+ }
41
+ catch (err) {
42
+ const error = err;
43
+ if (error.message?.includes("command failed") || error.stderr) {
44
+ return errorResult("No ripgrep or grep found on system, or search failed. Try using glob instead.");
45
+ }
46
+ return errorResult(`Search failed: ${error.message || "unknown error"}`);
47
+ }
48
+ },
49
+ };
50
+ //# sourceMappingURL=grep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/tools/grep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,CAAC,MAAM,QAAQ,GAAgB;IACnC,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IAC5C,WAAW,EAAE;;;gDAGiC;IAC9C,WAAW,EAA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GAAG,OAAO,CAAC,CAAC,CAAC,cAAc,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5D,GAAG,GAAG,aAAa,OAAO,MAAM,SAAS,KAAK,WAAW,wBAAwB,KAAK,EAAE,CAAC;YAC3F,CAAC;YAED,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;YAC5F,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,OAAO;gBAAE,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;YAErD,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;YAC7C,MAAM,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC;YACrC,OAAO,UAAU,CAAC,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,uBAAuB,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1F,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,GAA4C,CAAC;YAC3D,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC9D,OAAO,WAAW,CAAC,+EAA+E,CAAC,CAAC;YACtG,CAAC;YACD,OAAO,WAAW,CAAC,kBAAkB,KAAK,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { SpectraTool } from "./types.js";
2
+ import type { AgentTool, ToolResult } from "@mohanscodex/spectra-agent";
3
+ import type { SecurityManager } from "../security/index.js";
4
+ export { type SpectraTool } from "./types.js";
5
+ export declare const builtinTools: SpectraTool[];
6
+ export declare function spectraToolToAgentTool(specTool: SpectraTool, security?: SecurityManager): AgentTool;
7
+ export declare function createAllTools(): SpectraTool[];
8
+ export declare function createAllToolsWithMcp(): Promise<{
9
+ builtin: AgentTool[];
10
+ mcp: AgentTool[];
11
+ all: AgentTool[];
12
+ }>;
13
+ export declare function getToolStats(): {
14
+ builtin: number;
15
+ mcp: number;
16
+ total: number;
17
+ };
18
+ export declare function createAllToolsWithExtensions(): Promise<{
19
+ builtin: AgentTool[];
20
+ mcp: AgentTool[];
21
+ custom: AgentTool[];
22
+ all: AgentTool[];
23
+ }>;
24
+ export declare function createAllToolsWithSecurity(security: SecurityManager): AgentTool[];
25
+ export declare function getToolDisplayName(tool: SpectraTool, args: unknown, result?: ToolResult): string;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAMxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,YAAY,EAAE,WAAW,EASrC,CAAC;AA0HF,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,WAAW,EACrB,QAAQ,CAAC,EAAE,eAAe,GACzB,SAAS,CAeX;AAED,wBAAgB,cAAc,IAAI,WAAW,EAAE,CAE9C;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,GAAG,EAAE,SAAS,EAAE,CAAC;IACjB,GAAG,EAAE,SAAS,EAAE,CAAC;CAClB,CAAC,CAgBD;AAED,wBAAgB,YAAY,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAQ9E;AAED,wBAAsB,4BAA4B,IAAI,OAAO,CAAC;IAC5D,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,GAAG,EAAE,SAAS,EAAE,CAAC;IACjB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,GAAG,EAAE,SAAS,EAAE,CAAC;CAClB,CAAC,CAmBD;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,EAAE,CAEjF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,CAIhG"}
@@ -0,0 +1,202 @@
1
+ import { shellTool } from "./shell.js";
2
+ import { readTool } from "./read.js";
3
+ import { writeTool } from "./write.js";
4
+ import { editTool } from "./edit.js";
5
+ import { grepTool } from "./grep.js";
6
+ import { globTool } from "./glob.js";
7
+ import { webFetchTool } from "./web-fetch.js";
8
+ import { taskTool } from "./task.js";
9
+ import { defineTool } from "@mohanscodex/spectra-agent";
10
+ import { listConnectedServers } from "../integrations/mcp/index.js";
11
+ import { createMcpAgentTools } from "./mcp-tool.js";
12
+ import { loadCustomTools } from "../integrations/custom-tools/index.js";
13
+ import { PermissionDeniedError } from "../security/index.js";
14
+ export const builtinTools = [
15
+ shellTool,
16
+ readTool,
17
+ writeTool,
18
+ editTool,
19
+ grepTool,
20
+ globTool,
21
+ webFetchTool,
22
+ taskTool,
23
+ ];
24
+ const FILE_TOOL_NAMES = new Set(["read", "write", "edit", "grep", "glob", "bash", "shell"]);
25
+ function wrapExecute(tool, security) {
26
+ const tracker = security.getReadTracker();
27
+ const doomLoop = security.getDoomLoop();
28
+ return async (args, ctx) => {
29
+ const loopResult = doomLoop.recordToolCall(tool.name, args);
30
+ if (!loopResult.ok) {
31
+ return { content: [{ type: "text", text: loopResult.message }], isError: true };
32
+ }
33
+ const patterns = security.extractToolPatterns(tool.name, args);
34
+ if (FILE_TOOL_NAMES.has(tool.name)) {
35
+ for (const extPath of patterns.externalPaths) {
36
+ try {
37
+ await security.checkPermission("external_directory", [extPath], tool.name, extPath);
38
+ }
39
+ catch (err) {
40
+ if (err instanceof PermissionDeniedError) {
41
+ return { content: [{ type: "text", text: `External file access denied: ${err.message}` }], isError: true };
42
+ }
43
+ throw err;
44
+ }
45
+ }
46
+ }
47
+ else {
48
+ try {
49
+ await security.checkPermission(tool.name, patterns.toolPatterns, tool.name, patterns.toolPatterns[0]);
50
+ }
51
+ catch (err) {
52
+ if (err instanceof PermissionDeniedError) {
53
+ return { content: [{ type: "text", text: `Permission denied: ${err.message}` }], isError: true };
54
+ }
55
+ throw err;
56
+ }
57
+ }
58
+ for (const pathPattern of patterns.pathPatterns) {
59
+ try {
60
+ security.checkPath(pathPattern);
61
+ }
62
+ catch (err) {
63
+ if (err instanceof PermissionDeniedError) {
64
+ return { content: [{ type: "text", text: `Path safety blocked: ${pathPattern}` }], isError: true };
65
+ }
66
+ throw err;
67
+ }
68
+ }
69
+ const caps = tool.capabilities ?? { reads: false, writes: false };
70
+ for (const pathPattern of patterns.pathPatterns) {
71
+ if (caps.writes) {
72
+ const guard = tracker.checkWrite(pathPattern, process.cwd(), tool.name);
73
+ if (!guard.ok) {
74
+ return { content: [{ type: "text", text: guard.reason }], isError: true };
75
+ }
76
+ }
77
+ }
78
+ if (tool.name === "web_fetch" || tool.name === "webfetch") {
79
+ const url = args.url;
80
+ if (url) {
81
+ const ssrfResult = security.getSsrfGuard().check(url);
82
+ if (!ssrfResult.ok) {
83
+ return { content: [{ type: "text", text: `SSRF guard: ${ssrfResult.reason}` }], isError: true };
84
+ }
85
+ }
86
+ }
87
+ const result = await tool.execute(args, ctx);
88
+ const toolOk = result.isError !== true;
89
+ const loopCheck = doomLoop.recordToolResult(tool.name, toolOk);
90
+ if (!loopCheck.ok) {
91
+ const firstContent = result.content?.[0];
92
+ const existingContent = firstContent?.type === "text" ? firstContent.text : "";
93
+ return {
94
+ content: [{ type: "text", text: `${existingContent}\n\n<system-reminder>${loopCheck.message}</system-reminder>` }],
95
+ isError: result.isError,
96
+ details: result.details,
97
+ };
98
+ }
99
+ if (tool.name === "edit" || tool.name === "patch") {
100
+ if (toolOk) {
101
+ for (const pathPattern of patterns.pathPatterns) {
102
+ doomLoop.recordPatchSuccess(pathPattern);
103
+ }
104
+ }
105
+ else {
106
+ for (const pathPattern of patterns.pathPatterns) {
107
+ const spiralResult = doomLoop.recordPatchFailure(pathPattern);
108
+ if (!spiralResult.ok) {
109
+ const firstContent = result.content?.[0];
110
+ const text = firstContent?.type === "text" ? firstContent.text : "";
111
+ if (text) {
112
+ return {
113
+ content: [{ type: "text", text: `${text}\n\n<system-reminder>${spiralResult.message}</system-reminder>` }],
114
+ isError: result.isError,
115
+ details: result.details,
116
+ };
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ for (const pathPattern of patterns.pathPatterns) {
123
+ if (caps.reads) {
124
+ tracker.recordRead(pathPattern, process.cwd());
125
+ }
126
+ if (caps.writes && toolOk) {
127
+ tracker.recordWrite(pathPattern, process.cwd());
128
+ }
129
+ }
130
+ return result;
131
+ };
132
+ }
133
+ export function spectraToolToAgentTool(specTool, security) {
134
+ const execute = security
135
+ ? wrapExecute(specTool, security)
136
+ : specTool.execute;
137
+ return defineTool({
138
+ name: specTool.name,
139
+ label: typeof specTool.displayName === "string" ? specTool.displayName : undefined,
140
+ description: specTool.description,
141
+ parameters: specTool.parameters,
142
+ promptGuidelines: specTool.promptGuidelines,
143
+ execute: async (args, ctx) => {
144
+ return execute(args, ctx);
145
+ },
146
+ });
147
+ }
148
+ export function createAllTools() {
149
+ return [...builtinTools];
150
+ }
151
+ export async function createAllToolsWithMcp() {
152
+ const builtin = builtinTools.map((t) => spectraToolToAgentTool(t));
153
+ const connected = listConnectedServers();
154
+ const mcp = [];
155
+ for (const server of connected) {
156
+ if (server.tools.length > 0) {
157
+ mcp.push(...createMcpAgentTools(server.name, server.tools));
158
+ }
159
+ }
160
+ return {
161
+ builtin,
162
+ mcp,
163
+ all: [...builtin, ...mcp],
164
+ };
165
+ }
166
+ export function getToolStats() {
167
+ const connected = listConnectedServers();
168
+ const mcpCount = connected.reduce((sum, s) => sum + s.tools.length, 0);
169
+ return {
170
+ builtin: builtinTools.length,
171
+ mcp: mcpCount,
172
+ total: builtinTools.length + mcpCount,
173
+ };
174
+ }
175
+ export async function createAllToolsWithExtensions() {
176
+ const builtin = builtinTools.map((t) => spectraToolToAgentTool(t));
177
+ const connected = listConnectedServers();
178
+ const mcp = [];
179
+ for (const server of connected) {
180
+ if (server.tools.length > 0) {
181
+ mcp.push(...createMcpAgentTools(server.name, server.tools));
182
+ }
183
+ }
184
+ const custom = await loadCustomTools(process.cwd());
185
+ return {
186
+ builtin,
187
+ mcp,
188
+ custom,
189
+ all: [...builtin, ...mcp, ...custom],
190
+ };
191
+ }
192
+ export function createAllToolsWithSecurity(security) {
193
+ return builtinTools.map((t) => spectraToolToAgentTool(t, security));
194
+ }
195
+ export function getToolDisplayName(tool, args, result) {
196
+ if (!tool.displayName)
197
+ return tool.name;
198
+ if (typeof tool.displayName === "string")
199
+ return tool.displayName;
200
+ return tool.displayName(args, result);
201
+ }
202
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAA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