@aria-cli/tools 1.0.12 → 1.0.14

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 (233) hide show
  1. package/dist/index.js +378 -70
  2. package/dist/network-runtime/index.js +8 -12
  3. package/dist-cjs/index.js +400 -435
  4. package/dist-cjs/network-runtime/index.js +8 -172
  5. package/package.json +8 -6
  6. package/dist/.tsbuildinfo +0 -1
  7. package/dist/ask-user-interaction.js +0 -22
  8. package/dist/cache/web-cache.js +0 -66
  9. package/dist/definitions/arion.js +0 -104
  10. package/dist/definitions/browser/browser.js +0 -418
  11. package/dist/definitions/browser/index.js +0 -4
  12. package/dist/definitions/browser/pw-downloads.js +0 -114
  13. package/dist/definitions/browser/pw-interactions.js +0 -199
  14. package/dist/definitions/browser/pw-responses.js +0 -76
  15. package/dist/definitions/browser/pw-session.js +0 -310
  16. package/dist/definitions/browser/pw-shared.js +0 -66
  17. package/dist/definitions/browser/pw-snapshot.js +0 -301
  18. package/dist/definitions/browser/pw-state.js +0 -62
  19. package/dist/definitions/browser/types.js +0 -4
  20. package/dist/definitions/code-intelligence.js +0 -470
  21. package/dist/definitions/core.js +0 -109
  22. package/dist/definitions/delegation.js +0 -512
  23. package/dist/definitions/deploy.js +0 -65
  24. package/dist/definitions/filesystem.js +0 -196
  25. package/dist/definitions/frg.js +0 -63
  26. package/dist/definitions/index.js +0 -20
  27. package/dist/definitions/memory.js +0 -123
  28. package/dist/definitions/messaging.js +0 -625
  29. package/dist/definitions/meta.js +0 -349
  30. package/dist/definitions/network.js +0 -159
  31. package/dist/definitions/outlook.js +0 -277
  32. package/dist/definitions/patch/apply-patch.js +0 -184
  33. package/dist/definitions/patch/fuzzy-match.js +0 -166
  34. package/dist/definitions/patch/index.js +0 -1
  35. package/dist/definitions/patch/patch-parser.js +0 -207
  36. package/dist/definitions/patch/sandbox-paths.js +0 -105
  37. package/dist/definitions/process/index.js +0 -4
  38. package/dist/definitions/process/process-registry.js +0 -213
  39. package/dist/definitions/process/process.js +0 -386
  40. package/dist/definitions/process/pty-keys.js +0 -254
  41. package/dist/definitions/process/session-slug.js +0 -142
  42. package/dist/definitions/quip.js +0 -195
  43. package/dist/definitions/search.js +0 -60
  44. package/dist/definitions/session-history.js +0 -69
  45. package/dist/definitions/shell.js +0 -181
  46. package/dist/definitions/slack.js +0 -180
  47. package/dist/definitions/web.js +0 -109
  48. package/dist/executors/apply-patch.js +0 -901
  49. package/dist/executors/arion.js +0 -119
  50. package/dist/executors/code-intelligence.js +0 -882
  51. package/dist/executors/deploy.js +0 -848
  52. package/dist/executors/filesystem.js +0 -1122
  53. package/dist/executors/frg-freshness.js +0 -576
  54. package/dist/executors/frg.js +0 -298
  55. package/dist/executors/index.js +0 -46
  56. package/dist/executors/learning-meta.js +0 -1146
  57. package/dist/executors/lsp-client.js +0 -296
  58. package/dist/executors/memory.js +0 -750
  59. package/dist/executors/meta.js +0 -220
  60. package/dist/executors/process-registry.js +0 -465
  61. package/dist/executors/pty-session-store.js +0 -30
  62. package/dist/executors/pty.js +0 -271
  63. package/dist/executors/restart.js +0 -119
  64. package/dist/executors/search-freshness.js +0 -195
  65. package/dist/executors/search-types.js +0 -52
  66. package/dist/executors/search.js +0 -66
  67. package/dist/executors/self-diagnose.js +0 -398
  68. package/dist/executors/session-history.js +0 -283
  69. package/dist/executors/shell-safety.js +0 -473
  70. package/dist/executors/shell.js +0 -954
  71. package/dist/executors/utils.js +0 -33
  72. package/dist/executors/web.js +0 -542
  73. package/dist/extraction/content-extraction.js +0 -235
  74. package/dist/extraction/index.js +0 -4
  75. package/dist/headless-control-contract.js +0 -967
  76. package/dist/local-control-http-auth.js +0 -2
  77. package/dist/mcp/client.js +0 -181
  78. package/dist/mcp/connection.js +0 -480
  79. package/dist/mcp/index.js +0 -10
  80. package/dist/mcp/jsonrpc.js +0 -144
  81. package/dist/mcp/types.js +0 -7
  82. package/dist/network-control-adapter.js +0 -72
  83. package/dist/network-runtime/address-types.js +0 -165
  84. package/dist/network-runtime/db-owner-fencing.js +0 -69
  85. package/dist/network-runtime/delivery-receipts.js +0 -267
  86. package/dist/network-runtime/direct-endpoint-authority.js +0 -25
  87. package/dist/network-runtime/local-control-contract.js +0 -627
  88. package/dist/network-runtime/node-store-contract.js +0 -34
  89. package/dist/network-runtime/pair-route-contract.js +0 -77
  90. package/dist/network-runtime/peer-capabilities.js +0 -28
  91. package/dist/network-runtime/peer-principal-ref.js +0 -12
  92. package/dist/network-runtime/peer-state-machine.js +0 -121
  93. package/dist/network-runtime/protocol-schemas.js +0 -205
  94. package/dist/network-runtime/runtime-bootstrap-contract.js +0 -60
  95. package/dist/outlook/desktop-session.js +0 -279
  96. package/dist/policy.js +0 -149
  97. package/dist/providers/brave.js +0 -62
  98. package/dist/providers/duckduckgo.js +0 -176
  99. package/dist/providers/exa.js +0 -63
  100. package/dist/providers/firecrawl.js +0 -55
  101. package/dist/providers/index.js +0 -7
  102. package/dist/providers/jina.js +0 -49
  103. package/dist/providers/router.js +0 -96
  104. package/dist/providers/search-provider.js +0 -32
  105. package/dist/providers/tavily.js +0 -54
  106. package/dist/quip/desktop-session.js +0 -317
  107. package/dist/registry/index.js +0 -1
  108. package/dist/registry/registry.js +0 -756
  109. package/dist/runtime-socket-local-control-client.js +0 -330
  110. package/dist/security/dns-normalization.js +0 -19
  111. package/dist/security/dns-pinning.js +0 -123
  112. package/dist/security/external-content.js +0 -91
  113. package/dist/security/ssrf.js +0 -181
  114. package/dist/slack/desktop-session.js +0 -324
  115. package/dist/tool-factory.js +0 -47
  116. package/dist/types.js +0 -7
  117. package/dist/utils/retry.js +0 -132
  118. package/dist/utils/safe-parse-json.js +0 -160
  119. package/dist/utils/url.js +0 -19
  120. package/dist-cjs/.tsbuildinfo +0 -1
  121. package/dist-cjs/ask-user-interaction.js +0 -27
  122. package/dist-cjs/cache/web-cache.js +0 -70
  123. package/dist-cjs/definitions/arion.js +0 -107
  124. package/dist-cjs/definitions/browser/browser.js +0 -421
  125. package/dist-cjs/definitions/browser/index.js +0 -8
  126. package/dist-cjs/definitions/browser/pw-downloads.js +0 -117
  127. package/dist-cjs/definitions/browser/pw-interactions.js +0 -213
  128. package/dist-cjs/definitions/browser/pw-responses.js +0 -84
  129. package/dist-cjs/definitions/browser/pw-session.js +0 -326
  130. package/dist-cjs/definitions/browser/pw-shared.js +0 -72
  131. package/dist-cjs/definitions/browser/pw-snapshot.js +0 -307
  132. package/dist-cjs/definitions/browser/pw-state.js +0 -70
  133. package/dist-cjs/definitions/browser/types.js +0 -5
  134. package/dist-cjs/definitions/code-intelligence.js +0 -473
  135. package/dist-cjs/definitions/core.js +0 -133
  136. package/dist-cjs/definitions/delegation.js +0 -515
  137. package/dist-cjs/definitions/deploy.js +0 -68
  138. package/dist-cjs/definitions/filesystem.js +0 -199
  139. package/dist-cjs/definitions/frg.js +0 -66
  140. package/dist-cjs/definitions/index.js +0 -43
  141. package/dist-cjs/definitions/memory.js +0 -126
  142. package/dist-cjs/definitions/messaging.js +0 -631
  143. package/dist-cjs/definitions/meta.js +0 -352
  144. package/dist-cjs/definitions/network.js +0 -162
  145. package/dist-cjs/definitions/outlook.js +0 -280
  146. package/dist-cjs/definitions/patch/apply-patch.js +0 -191
  147. package/dist-cjs/definitions/patch/fuzzy-match.js +0 -172
  148. package/dist-cjs/definitions/patch/index.js +0 -5
  149. package/dist-cjs/definitions/patch/patch-parser.js +0 -215
  150. package/dist-cjs/definitions/patch/sandbox-paths.js +0 -113
  151. package/dist-cjs/definitions/process/index.js +0 -8
  152. package/dist-cjs/definitions/process/process-registry.js +0 -231
  153. package/dist-cjs/definitions/process/process.js +0 -389
  154. package/dist-cjs/definitions/process/pty-keys.js +0 -259
  155. package/dist-cjs/definitions/process/session-slug.js +0 -145
  156. package/dist-cjs/definitions/quip.js +0 -198
  157. package/dist-cjs/definitions/search.js +0 -63
  158. package/dist-cjs/definitions/session-history.js +0 -72
  159. package/dist-cjs/definitions/shell.js +0 -184
  160. package/dist-cjs/definitions/slack.js +0 -183
  161. package/dist-cjs/definitions/web.js +0 -112
  162. package/dist-cjs/executors/apply-patch.js +0 -938
  163. package/dist-cjs/executors/arion.js +0 -125
  164. package/dist-cjs/executors/code-intelligence.js +0 -925
  165. package/dist-cjs/executors/deploy.js +0 -869
  166. package/dist-cjs/executors/filesystem.js +0 -1167
  167. package/dist-cjs/executors/frg-freshness.js +0 -627
  168. package/dist-cjs/executors/frg.js +0 -334
  169. package/dist-cjs/executors/index.js +0 -143
  170. package/dist-cjs/executors/learning-meta.js +0 -1165
  171. package/dist-cjs/executors/lsp-client.js +0 -310
  172. package/dist-cjs/executors/memory.js +0 -796
  173. package/dist-cjs/executors/meta.js +0 -226
  174. package/dist-cjs/executors/process-registry.js +0 -469
  175. package/dist-cjs/executors/pty-session-store.js +0 -34
  176. package/dist-cjs/executors/pty.js +0 -312
  177. package/dist-cjs/executors/restart.js +0 -155
  178. package/dist-cjs/executors/search-freshness.js +0 -234
  179. package/dist-cjs/executors/search-types.js +0 -56
  180. package/dist-cjs/executors/search.js +0 -102
  181. package/dist-cjs/executors/self-diagnose.js +0 -434
  182. package/dist-cjs/executors/session-history.js +0 -320
  183. package/dist-cjs/executors/shell-safety.js +0 -478
  184. package/dist-cjs/executors/shell.js +0 -1001
  185. package/dist-cjs/executors/utils.js +0 -73
  186. package/dist-cjs/executors/web.js +0 -547
  187. package/dist-cjs/extraction/content-extraction.js +0 -243
  188. package/dist-cjs/extraction/index.js +0 -8
  189. package/dist-cjs/headless-control-contract.js +0 -972
  190. package/dist-cjs/local-control-http-auth.js +0 -5
  191. package/dist-cjs/mcp/client.js +0 -185
  192. package/dist-cjs/mcp/connection.js +0 -484
  193. package/dist-cjs/mcp/index.js +0 -30
  194. package/dist-cjs/mcp/jsonrpc.js +0 -148
  195. package/dist-cjs/mcp/types.js +0 -8
  196. package/dist-cjs/network-control-adapter.js +0 -77
  197. package/dist-cjs/network-runtime/address-types.js +0 -168
  198. package/dist-cjs/network-runtime/db-owner-fencing.js +0 -76
  199. package/dist-cjs/network-runtime/delivery-receipts.js +0 -276
  200. package/dist-cjs/network-runtime/direct-endpoint-authority.js +0 -29
  201. package/dist-cjs/network-runtime/local-control-contract.js +0 -633
  202. package/dist-cjs/network-runtime/node-store-contract.js +0 -38
  203. package/dist-cjs/network-runtime/pair-route-contract.js +0 -80
  204. package/dist-cjs/network-runtime/peer-capabilities.js +0 -37
  205. package/dist-cjs/network-runtime/peer-principal-ref.js +0 -15
  206. package/dist-cjs/network-runtime/peer-state-machine.js +0 -129
  207. package/dist-cjs/network-runtime/protocol-schemas.js +0 -212
  208. package/dist-cjs/network-runtime/runtime-bootstrap-contract.js +0 -63
  209. package/dist-cjs/outlook/desktop-session.js +0 -318
  210. package/dist-cjs/policy.js +0 -155
  211. package/dist-cjs/providers/brave.js +0 -66
  212. package/dist-cjs/providers/duckduckgo.js +0 -180
  213. package/dist-cjs/providers/exa.js +0 -67
  214. package/dist-cjs/providers/firecrawl.js +0 -59
  215. package/dist-cjs/providers/index.js +0 -17
  216. package/dist-cjs/providers/jina.js +0 -53
  217. package/dist-cjs/providers/router.js +0 -100
  218. package/dist-cjs/providers/search-provider.js +0 -36
  219. package/dist-cjs/providers/tavily.js +0 -58
  220. package/dist-cjs/quip/desktop-session.js +0 -353
  221. package/dist-cjs/registry/index.js +0 -6
  222. package/dist-cjs/registry/registry.js +0 -761
  223. package/dist-cjs/runtime-socket-local-control-client.js +0 -367
  224. package/dist-cjs/security/dns-normalization.js +0 -22
  225. package/dist-cjs/security/dns-pinning.js +0 -160
  226. package/dist-cjs/security/external-content.js +0 -95
  227. package/dist-cjs/security/ssrf.js +0 -221
  228. package/dist-cjs/slack/desktop-session.js +0 -366
  229. package/dist-cjs/tool-factory.js +0 -50
  230. package/dist-cjs/types.js +0 -8
  231. package/dist-cjs/utils/retry.js +0 -169
  232. package/dist-cjs/utils/safe-parse-json.js +0 -164
  233. package/dist-cjs/utils/url.js +0 -23
@@ -1,925 +0,0 @@
1
- "use strict";
2
- /**
3
- * @aria/tools - Code intelligence executors
4
- *
5
- * 7 native tools wrapping external CLI binaries:
6
- * rg (ripgrep), ug (ugrep), probe, sg (ast-grep),
7
- * cbm (codebase-memory-mcp), serena, fff
8
- */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || (function () {
26
- var ownKeys = function(o) {
27
- ownKeys = Object.getOwnPropertyNames || function (o) {
28
- var ar = [];
29
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
- return ar;
31
- };
32
- return ownKeys(o);
33
- };
34
- return function (mod) {
35
- if (mod && mod.__esModule) return mod;
36
- var result = {};
37
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
- __setModuleDefault(result, mod);
39
- return result;
40
- };
41
- })();
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.executeRg = executeRg;
44
- exports.executeUg = executeUg;
45
- exports.executeProbe = executeProbe;
46
- exports.executeSg = executeSg;
47
- exports.executeCbm = executeCbm;
48
- exports.executeLsp = executeLsp;
49
- exports.executeSerena = executeSerena;
50
- exports.executeFff = executeFff;
51
- const node_child_process_1 = require("node:child_process");
52
- const node_util_1 = require("node:util");
53
- const node_fs_1 = require("node:fs");
54
- const node_path_1 = require("node:path");
55
- const node_net_1 = require("node:net");
56
- const utils_js_1 = require("./utils.js");
57
- const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
58
- // ---------------------------------------------------------------------------
59
- // Shared helpers
60
- // ---------------------------------------------------------------------------
61
- const binaryCache = new Map();
62
- async function hasBinary(name) {
63
- if (binaryCache.has(name))
64
- return binaryCache.get(name);
65
- try {
66
- await execFileAsync("which", [name]);
67
- binaryCache.set(name, true);
68
- }
69
- catch {
70
- binaryCache.set(name, false);
71
- }
72
- return binaryCache.get(name);
73
- }
74
- async function shellExec(cmd, args, opts) {
75
- return execFileAsync(cmd, args, {
76
- cwd: opts.cwd,
77
- timeout: opts.timeout ?? 30_000,
78
- signal: opts.signal,
79
- maxBuffer: 10 * 1024 * 1024, // 10MB
80
- });
81
- }
82
- function pushIf(args, condition, ...flags) {
83
- if (condition)
84
- args.push(...flags);
85
- }
86
- function mergeExtraArgs(args, extra) {
87
- if (extra?.length)
88
- args.push(...extra);
89
- }
90
- function escapeRegex(str) {
91
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
92
- }
93
- function asExecError(err) {
94
- if (err && typeof err === "object")
95
- return err;
96
- return { message: String(err) };
97
- }
98
- // ---------------------------------------------------------------------------
99
- // 1. rg — ripgrep
100
- // ---------------------------------------------------------------------------
101
- async function executeRg(input, ctx) {
102
- if (ctx.abortSignal?.aborted)
103
- return (0, utils_js_1.fail)("Operation cancelled");
104
- if (!(await hasBinary("rg")))
105
- return (0, utils_js_1.fail)("ripgrep (rg) not installed. Install: brew install ripgrep");
106
- // When count mode is active, rg -c outputs plain text (file:count) even with --json.
107
- // We omit --json and parse the plain-text output instead.
108
- const rgCountMode = !!input.count;
109
- const args = rgCountMode
110
- ? ["--line-number", "--color", "never"]
111
- : ["--json", "--line-number", "--color", "never"];
112
- pushIf(args, input.ignore_case, "-i");
113
- pushIf(args, input.smart_case, "-S");
114
- pushIf(args, input.fixed_strings, "-F");
115
- pushIf(args, input.word_regexp, "-w");
116
- pushIf(args, input.invert, "-v");
117
- pushIf(args, input.files_only, "-l");
118
- pushIf(args, input.count, "-c");
119
- if (input.file_type)
120
- args.push("-t", input.file_type);
121
- if (input.glob)
122
- args.push("-g", input.glob);
123
- if (input.context != null)
124
- args.push("-C", String(input.context));
125
- if (input.max_count != null)
126
- args.push("-m", String(input.max_count));
127
- mergeExtraArgs(args, input.extra_args);
128
- args.push("--", input.pattern);
129
- args.push(input.path ?? ctx.workingDir);
130
- try {
131
- const { stdout } = await shellExec("rg", args, {
132
- cwd: ctx.workingDir,
133
- signal: ctx.abortSignal,
134
- });
135
- if (rgCountMode) {
136
- const counts = parseRipgrepCount(stdout);
137
- const total = counts.reduce((s, c) => s + c.count, 0);
138
- return (0, utils_js_1.success)(`Found ${total} matches across ${counts.length} files for "${input.pattern}"`, { counts, total });
139
- }
140
- const matches = parseRipgrepJson(stdout);
141
- return (0, utils_js_1.success)(`Found ${matches.length} matches for "${input.pattern}"`, { matches });
142
- }
143
- catch (err) {
144
- const e = asExecError(err);
145
- if (e.code === 1)
146
- return (0, utils_js_1.success)("No matches found", { matches: [] });
147
- return (0, utils_js_1.fail)(`rg failed: ${e.stderr || e.message}`);
148
- }
149
- }
150
- function parseRipgrepJson(stdout) {
151
- const matches = [];
152
- for (const line of stdout.split("\n")) {
153
- if (!line.trim())
154
- continue;
155
- try {
156
- const obj = JSON.parse(line);
157
- if (obj.type === "match") {
158
- matches.push({
159
- file: obj.data.path.text,
160
- line: obj.data.line_number,
161
- text: obj.data.lines.text.trimEnd(),
162
- submatches: obj.data.submatches?.map((s) => s.match?.text) ?? [],
163
- });
164
- }
165
- }
166
- catch {
167
- // Skip malformed lines
168
- }
169
- }
170
- return matches;
171
- }
172
- /** Parse rg/ug plain-text count output: `file:count` per line.
173
- * Filters out files with 0 matches (ug -c outputs 0-count lines, rg doesn't). */
174
- function parseRipgrepCount(stdout) {
175
- const counts = [];
176
- for (const line of stdout.split("\n")) {
177
- if (!line.trim())
178
- continue;
179
- const lastColon = line.lastIndexOf(":");
180
- if (lastColon === -1)
181
- continue;
182
- const file = line.slice(0, lastColon);
183
- const count = parseInt(line.slice(lastColon + 1), 10);
184
- if (!isNaN(count) && count > 0)
185
- counts.push({ file, count });
186
- }
187
- return counts;
188
- }
189
- // ---------------------------------------------------------------------------
190
- // 2. ug — ugrep
191
- // ---------------------------------------------------------------------------
192
- async function executeUg(input, ctx) {
193
- if (ctx.abortSignal?.aborted)
194
- return (0, utils_js_1.fail)("Operation cancelled");
195
- if (!(await hasBinary("ug")))
196
- return (0, utils_js_1.fail)("ugrep (ug) not installed. Install: brew install ugrep");
197
- // --ignore-files: respect .gitignore / .ignore (parity with rg default behaviour).
198
- // --ignore-binary: skip binary files (tar, images, etc.) — rg skips them by default.
199
- // Without these flags ug searches dist/, node_modules/, .tar archives, etc.
200
- const ugCountMode = !!input.count;
201
- const args = ugCountMode
202
- ? ["--line-number", "--color=never", "-r", "--ignore-files", "--ignore-binary"]
203
- : ["--json", "--line-number", "--color=never", "-r", "--ignore-files", "--ignore-binary"];
204
- pushIf(args, input.ignore_case, "-i");
205
- pushIf(args, input.smart_case, "-j");
206
- pushIf(args, input.fixed_strings, "-F");
207
- pushIf(args, input.word_regexp, "-w");
208
- pushIf(args, input.files_only, "-l");
209
- pushIf(args, input.count, "-c");
210
- pushIf(args, input.decompress, "-z");
211
- if (input.file_type)
212
- args.push("-t", input.file_type);
213
- if (input.glob)
214
- args.push("-g", input.glob);
215
- if (input.context != null)
216
- args.push("-C", String(input.context));
217
- if (input.max_count != null)
218
- args.push("-m", String(input.max_count));
219
- if (input.neg_pattern)
220
- args.push("-N", input.neg_pattern);
221
- // Fuzzy matching
222
- if (input.fuzzy === true) {
223
- args.push("-Z");
224
- }
225
- else if (typeof input.fuzzy === "number") {
226
- args.push(`-Z${input.fuzzy}`);
227
- }
228
- // Boolean query mode
229
- if (input.bool)
230
- args.push("-%%");
231
- mergeExtraArgs(args, input.extra_args);
232
- args.push("--", input.pattern);
233
- args.push(input.path ?? ctx.workingDir);
234
- try {
235
- const { stdout } = await shellExec("ug", args, {
236
- cwd: ctx.workingDir,
237
- signal: ctx.abortSignal,
238
- });
239
- if (ugCountMode) {
240
- const counts = parseRipgrepCount(stdout); // same file:count format
241
- const total = counts.reduce((s, c) => s + c.count, 0);
242
- return (0, utils_js_1.success)(`Found ${total} matches across ${counts.length} files for "${input.pattern}"`, { counts, total });
243
- }
244
- const matches = parseUgrepJson(stdout);
245
- return (0, utils_js_1.success)(`Found ${matches.length} matches for "${input.pattern}"`, { matches });
246
- }
247
- catch (err) {
248
- const e = asExecError(err);
249
- if (e.code === 1)
250
- return (0, utils_js_1.success)("No matches found", { matches: [] });
251
- return (0, utils_js_1.fail)(`ug failed: ${e.stderr || e.message}`);
252
- }
253
- }
254
- function parseUgrepJson(stdout) {
255
- // ugrep --json outputs: [{ file, matches: [{ line, match }] }]
256
- // This is a JSON array, NOT NDJSON like ripgrep
257
- const results = [];
258
- try {
259
- const parsed = JSON.parse(stdout);
260
- for (const fileGroup of parsed) {
261
- for (const m of fileGroup.matches) {
262
- results.push({
263
- file: fileGroup.file,
264
- line: m.line,
265
- text: m.match.trimEnd(),
266
- submatches: [],
267
- });
268
- }
269
- }
270
- }
271
- catch {
272
- // Fallback: try NDJSON parsing in case format varies
273
- for (const line of stdout.split("\n")) {
274
- if (!line.trim())
275
- continue;
276
- try {
277
- const obj = JSON.parse(line);
278
- if (obj.file && obj.matches) {
279
- for (const m of obj.matches) {
280
- results.push({
281
- file: obj.file,
282
- line: m.line,
283
- text: m.match?.trimEnd() ?? "",
284
- submatches: [],
285
- });
286
- }
287
- }
288
- }
289
- catch {
290
- // Skip
291
- }
292
- }
293
- }
294
- return results;
295
- }
296
- // ---------------------------------------------------------------------------
297
- // 3. probe
298
- // ---------------------------------------------------------------------------
299
- async function executeProbe(input, ctx) {
300
- if (ctx.abortSignal?.aborted)
301
- return (0, utils_js_1.fail)("Operation cancelled");
302
- if (!(await hasBinary("probe")))
303
- return (0, utils_js_1.fail)("probe not installed. Install: npm install -g @probelabs/probe");
304
- const cmd = input.command ?? "search";
305
- const args = [cmd];
306
- switch (cmd) {
307
- case "search": {
308
- if (!input.query)
309
- return (0, utils_js_1.fail)("query required for search");
310
- pushIf(args, input.exact, "--exact");
311
- pushIf(args, input.allow_tests, "--allow-tests");
312
- if (input.max_tokens != null)
313
- args.push("--max-tokens", String(input.max_tokens));
314
- if (input.max_results != null)
315
- args.push("--max-results", String(input.max_results));
316
- if (input.session)
317
- args.push("--session", input.session);
318
- if (input.language)
319
- args.push("--language", input.language);
320
- if (input.reranker)
321
- args.push("--reranker", input.reranker);
322
- args.push("--format", "json");
323
- mergeExtraArgs(args, input.extra_args);
324
- args.push("--", input.query);
325
- if (input.path)
326
- args.push(input.path);
327
- break;
328
- }
329
- case "extract": {
330
- if (!input.files?.length)
331
- return (0, utils_js_1.fail)("files required for extract");
332
- args.push("--format", "json");
333
- mergeExtraArgs(args, input.extra_args);
334
- args.push(...input.files);
335
- break;
336
- }
337
- case "symbols": {
338
- // Accept files via `files` array or fall back to `query` as a file path
339
- const symbolFiles = input.files?.length ? input.files : input.query ? [input.query] : [];
340
- if (!symbolFiles.length)
341
- return (0, utils_js_1.fail)("files required for symbols (pass via 'files' or 'query')");
342
- args.push("--format", "json");
343
- mergeExtraArgs(args, input.extra_args);
344
- args.push(...symbolFiles);
345
- break;
346
- }
347
- case "query": {
348
- if (!input.query)
349
- return (0, utils_js_1.fail)("query (AST pattern) required for query command");
350
- if (input.language)
351
- args.push("--language", input.language);
352
- if (input.max_results != null)
353
- args.push("--max-results", String(input.max_results));
354
- pushIf(args, input.allow_tests, "--allow-tests");
355
- args.push("--format", "json");
356
- mergeExtraArgs(args, input.extra_args);
357
- args.push("--", input.query);
358
- if (input.path)
359
- args.push(input.path);
360
- break;
361
- }
362
- }
363
- try {
364
- const { stdout } = await shellExec("probe", args, {
365
- cwd: ctx.workingDir,
366
- signal: ctx.abortSignal,
367
- timeout: 60_000,
368
- });
369
- try {
370
- const data = JSON.parse(stdout);
371
- return (0, utils_js_1.success)(`probe ${cmd} completed`, data);
372
- }
373
- catch {
374
- // If not valid JSON, return raw output
375
- return (0, utils_js_1.success)(`probe ${cmd} completed`, { raw: stdout });
376
- }
377
- }
378
- catch (err) {
379
- const e = asExecError(err);
380
- return (0, utils_js_1.fail)(`probe ${cmd} failed: ${e.stderr || e.message}`);
381
- }
382
- }
383
- // ---------------------------------------------------------------------------
384
- // 4. sg — ast-grep
385
- // ---------------------------------------------------------------------------
386
- async function executeSg(input, ctx) {
387
- if (ctx.abortSignal?.aborted)
388
- return (0, utils_js_1.fail)("Operation cancelled");
389
- if (!(await hasBinary("sg")))
390
- return (0, utils_js_1.fail)("ast-grep (sg) not installed. Install: cargo install ast-grep --locked");
391
- const cmd = input.command ?? "run";
392
- const isMutation = !!(input.rewrite || input.update_all);
393
- // Require confirmation for mutations
394
- if (isMutation && !input.update_all && ctx.confirm) {
395
- const approved = await ctx.confirm(`Rewrite code matching \`${input.pattern}\` to \`${input.rewrite}\` in ${input.language || "auto-detected"} files?`);
396
- if (!approved)
397
- return (0, utils_js_1.fail)("Rewrite cancelled by user");
398
- }
399
- const args = [cmd];
400
- if (cmd === "run") {
401
- if (!input.pattern)
402
- return (0, utils_js_1.fail)("pattern required for sg run");
403
- args.push("--pattern", input.pattern);
404
- if (input.language)
405
- args.push("--lang", input.language);
406
- if (input.rewrite)
407
- args.push("--rewrite", input.rewrite);
408
- if (input.strictness)
409
- args.push("--strictness", input.strictness);
410
- pushIf(args, input.update_all, "-U");
411
- }
412
- else if (cmd === "scan") {
413
- if (input.rule)
414
- args.push("--rule", input.rule);
415
- if (input.inline_rules)
416
- args.push("--inline-rules", input.inline_rules);
417
- }
418
- // Shared flags
419
- if (input.globs)
420
- args.push("--globs", input.globs);
421
- if (input.context != null)
422
- args.push("-C", String(input.context));
423
- // Always JSON for machine parsing, skip color
424
- if (!isMutation) {
425
- args.push("--json=compact");
426
- }
427
- args.push("--color", "never");
428
- mergeExtraArgs(args, input.extra_args);
429
- args.push(input.path ?? ctx.workingDir);
430
- try {
431
- const { stdout } = await shellExec("sg", args, {
432
- cwd: ctx.workingDir,
433
- signal: ctx.abortSignal,
434
- });
435
- if (isMutation) {
436
- return (0, utils_js_1.success)(`sg ${cmd}: rewrites applied`, { raw: stdout });
437
- }
438
- try {
439
- const data = JSON.parse(stdout);
440
- const count = Array.isArray(data) ? data.length : 0;
441
- return (0, utils_js_1.success)(`Found ${count} matches`, { matches: data });
442
- }
443
- catch {
444
- return (0, utils_js_1.success)(`sg ${cmd} completed`, { raw: stdout });
445
- }
446
- }
447
- catch (err) {
448
- // Exit code 1 = no matches for run
449
- const e = asExecError(err);
450
- if (e.code === 1 && cmd === "run")
451
- return (0, utils_js_1.success)("No matches found", { matches: [] });
452
- return (0, utils_js_1.fail)(`sg ${cmd} failed: ${e.stderr || e.message}`);
453
- }
454
- }
455
- // ---------------------------------------------------------------------------
456
- // 5. cbm — codebase-memory-mcp
457
- // ---------------------------------------------------------------------------
458
- // Internal helper to call cbm CLI
459
- async function cbmCall(tool, params, ctx, timeout) {
460
- // Remove undefined/null values from params
461
- const clean = {};
462
- for (const [k, v] of Object.entries(params)) {
463
- if (v !== undefined && v !== null)
464
- clean[k] = v;
465
- }
466
- const { stdout } = await shellExec("codebase-memory-mcp", ["cli", tool, JSON.stringify(clean)], {
467
- cwd: ctx.workingDir,
468
- signal: ctx.abortSignal,
469
- timeout: timeout ?? 30_000,
470
- });
471
- // cbm cli returns MCP content format: { content: [{ type: "text", text: "..." }] }
472
- // Filter log lines (level=info ...) and parse
473
- const jsonLines = stdout.split("\n").filter((l) => l.trim() && !l.startsWith("level="));
474
- const parsed = JSON.parse(jsonLines.join("\n"));
475
- if (Array.isArray(parsed.content)) {
476
- const textBlocks = parsed.content
477
- .filter((c) => c.type === "text")
478
- .map((c) => c.text);
479
- const combined = textBlocks.join("\n");
480
- try {
481
- return JSON.parse(combined);
482
- }
483
- catch {
484
- return { text: combined };
485
- }
486
- }
487
- return parsed;
488
- }
489
- async function executeCbm(input, ctx) {
490
- if (ctx.abortSignal?.aborted)
491
- return (0, utils_js_1.fail)("Operation cancelled");
492
- if (!(await hasBinary("codebase-memory-mcp")))
493
- return (0, utils_js_1.fail)("codebase-memory-mcp not installed. Install:\ncurl -fsSL https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/scripts/setup.sh | bash");
494
- // Auto-detect project name: cbm slugifies repo_path by replacing / with -
495
- // and stripping the leading separator: /Users/hole/aria → Users-hole-aria
496
- const p = input.project ?? (input.path ?? ctx.workingDir).replace(/^\//, "").replace(/\//g, "-");
497
- // Auto-index: if the action requires an indexed project and no project exists,
498
- // transparently run a fast index first so queries don't silently return empty.
499
- const queryActions = new Set([
500
- "search",
501
- "trace",
502
- "impact",
503
- "context",
504
- "snippet",
505
- "code_search",
506
- "architecture",
507
- "schema",
508
- "cypher",
509
- ]);
510
- if (queryActions.has(input.action)) {
511
- let needsIndex = false;
512
- try {
513
- const statusResult = (await cbmCall("index_status", { project: p }, ctx));
514
- // If status indicates no project or empty graph, auto-index
515
- if (statusResult?.status === "no_project" ||
516
- statusResult?.node_count === 0 ||
517
- statusResult?.error) {
518
- needsIndex = true;
519
- }
520
- }
521
- catch {
522
- // index_status failed — likely no project
523
- needsIndex = true;
524
- }
525
- if (needsIndex) {
526
- try {
527
- await cbmCall("index_repository", { repo_path: input.path ?? ctx.workingDir, mode: "full" }, ctx, 300_000);
528
- }
529
- catch {
530
- // If auto-index fails, continue — let the actual action produce the error
531
- }
532
- }
533
- }
534
- switch (input.action) {
535
- case "index":
536
- return (0, utils_js_1.success)("Indexed", await cbmCall("index_repository", { repo_path: input.path ?? ctx.workingDir, mode: input.mode ?? "full" }, ctx, 300_000));
537
- case "search":
538
- return (0, utils_js_1.success)("Search results", await cbmCall("search_graph", {
539
- project: p,
540
- name_pattern: input.name,
541
- label: input.label,
542
- file_pattern: input.file,
543
- limit: input.limit ?? 20,
544
- }, ctx));
545
- case "trace": {
546
- if (!input.name)
547
- return (0, utils_js_1.fail)("name required for trace");
548
- return (0, utils_js_1.success)(`Call chain: ${input.name}`, await cbmCall("trace_call_path", {
549
- project: p,
550
- function_name: input.name,
551
- direction: input.direction ?? "both",
552
- depth: input.depth ?? 3,
553
- edge_types: input.edge_types,
554
- }, ctx));
555
- }
556
- case "impact":
557
- return (0, utils_js_1.success)("Impact analysis", await cbmCall("detect_changes", {
558
- project: p,
559
- scope: input.scope,
560
- depth: input.depth ?? 2,
561
- base_branch: input.base_branch ?? "main",
562
- }, ctx));
563
- case "context": {
564
- if (!input.name)
565
- return (0, utils_js_1.fail)("name required for context");
566
- const [sym, callers, callees] = await Promise.all([
567
- cbmCall("search_graph", { project: p, name_pattern: `^${escapeRegex(input.name)}$`, limit: 1 }, ctx),
568
- cbmCall("trace_call_path", { project: p, function_name: input.name, direction: "inbound", depth: 2 }, ctx),
569
- cbmCall("trace_call_path", { project: p, function_name: input.name, direction: "outbound", depth: 2 }, ctx),
570
- ]);
571
- return (0, utils_js_1.success)(`360° context: ${input.name}`, {
572
- definition: sym.results?.[0],
573
- callers,
574
- callees,
575
- });
576
- }
577
- case "snippet": {
578
- if (!input.qualified_name)
579
- return (0, utils_js_1.fail)("qualified_name required for snippet");
580
- return (0, utils_js_1.success)("Code snippet", await cbmCall("get_code_snippet", {
581
- project: p,
582
- qualified_name: input.qualified_name,
583
- include_neighbors: input.include_neighbors,
584
- }, ctx));
585
- }
586
- case "code_search":
587
- return (0, utils_js_1.success)("Code search", await cbmCall("search_code", {
588
- project: p,
589
- pattern: input.code_pattern,
590
- mode: input.code_mode ?? "compact",
591
- regex: input.regex,
592
- limit: input.limit ?? 10,
593
- file_pattern: input.file,
594
- context: input.context,
595
- }, ctx));
596
- case "architecture":
597
- return (0, utils_js_1.success)("Architecture", await cbmCall("get_architecture", { project: p }, ctx));
598
- case "schema":
599
- return (0, utils_js_1.success)("Schema", await cbmCall("get_graph_schema", { project: p }, ctx));
600
- case "cypher": {
601
- if (!input.query)
602
- return (0, utils_js_1.fail)("query required for cypher");
603
- return (0, utils_js_1.success)("Cypher result", await cbmCall("query_graph", { project: p, query: input.query, max_rows: input.max_rows }, ctx));
604
- }
605
- case "list_projects":
606
- return (0, utils_js_1.success)("Projects", await cbmCall("list_projects", {}, ctx));
607
- case "delete_project": {
608
- if (!input.project)
609
- return (0, utils_js_1.fail)("project required for delete_project");
610
- if (ctx.confirm) {
611
- const ok = await ctx.confirm(`Delete project "${input.project}" from cbm index?`);
612
- if (!ok)
613
- return (0, utils_js_1.fail)("Cancelled");
614
- }
615
- return (0, utils_js_1.success)("Deleted", await cbmCall("delete_project", { project: p }, ctx));
616
- }
617
- case "status":
618
- return (0, utils_js_1.success)("Status", await cbmCall("index_status", { project: p }, ctx));
619
- default:
620
- return (0, utils_js_1.fail)(`Unknown cbm action: ${input.action}`);
621
- }
622
- }
623
- let _lspClient;
624
- async function getLspClient() {
625
- if (!_lspClient) {
626
- // Use variable to prevent TypeScript from following the import in CJS build
627
- const modulePath = "./lsp-client.js";
628
- _lspClient = (await Promise.resolve(`${modulePath}`).then(s => __importStar(require(s))));
629
- }
630
- return _lspClient;
631
- }
632
- async function executeLsp(input, ctx) {
633
- if (ctx.abortSignal?.aborted)
634
- return (0, utils_js_1.fail)("Operation cancelled");
635
- if (!input.file)
636
- return (0, utils_js_1.fail)("file required");
637
- const { getServerForFile, getOrCreateServer, LSP_SERVERS } = await getLspClient();
638
- const serverName = getServerForFile(input.file);
639
- if (!serverName) {
640
- const ext = input.file.slice(input.file.lastIndexOf("."));
641
- const supported = Object.entries(LSP_SERVERS)
642
- .map(([name, cfg]) => `${name}: ${Object.keys(cfg.extensionToLanguage).join(", ")}`)
643
- .join("\n ");
644
- return (0, utils_js_1.fail)(`No language server for extension "${ext}". Supported:\n ${supported}`);
645
- }
646
- // Rename requires confirmation
647
- if (input.action === "rename" && ctx.confirm) {
648
- const ok = await ctx.confirm(`Rename symbol at ${input.file}:${input.line}:${input.character} to "${input.new_name}"?`);
649
- if (!ok)
650
- return (0, utils_js_1.fail)("Cancelled by user");
651
- }
652
- const server = getOrCreateServer(serverName, ctx.workingDir);
653
- try {
654
- await server.start();
655
- switch (input.action) {
656
- case "definition": {
657
- if (input.line == null || input.character == null)
658
- return (0, utils_js_1.fail)("line and character required for definition");
659
- const result = await server.definition(input.file, input.line, input.character);
660
- return (0, utils_js_1.success)(`lsp definition`, result);
661
- }
662
- case "references": {
663
- if (input.line == null || input.character == null)
664
- return (0, utils_js_1.fail)("line and character required for references");
665
- const result = await server.references(input.file, input.line, input.character);
666
- return (0, utils_js_1.success)(`lsp references`, result);
667
- }
668
- case "hover": {
669
- if (input.line == null || input.character == null)
670
- return (0, utils_js_1.fail)("line and character required for hover");
671
- const result = await server.hover(input.file, input.line, input.character);
672
- return (0, utils_js_1.success)(`lsp hover`, result);
673
- }
674
- case "symbols": {
675
- const result = await server.documentSymbols(input.file);
676
- return (0, utils_js_1.success)(`lsp symbols`, result);
677
- }
678
- case "rename": {
679
- if (input.line == null || input.character == null || !input.new_name)
680
- return (0, utils_js_1.fail)("line, character, and new_name required for rename");
681
- const result = await server.rename(input.file, input.line, input.character, input.new_name);
682
- return (0, utils_js_1.success)(`lsp rename`, result);
683
- }
684
- default:
685
- return (0, utils_js_1.fail)(`Unknown lsp action: ${input.action}. Use: definition, references, hover, symbols, rename`);
686
- }
687
- }
688
- catch (err) {
689
- const e = asExecError(err);
690
- return (0, utils_js_1.fail)(`lsp ${input.action} failed: ${e.message}`);
691
- }
692
- }
693
- // ---------------------------------------------------------------------------
694
- // 7. serena — HTTP project server (kept alongside native LSP for full Serena API)
695
- // ---------------------------------------------------------------------------
696
- const SERENA_PORT = 9750;
697
- const SERENA_BASE = `http://127.0.0.1:${SERENA_PORT}`;
698
- const SERENA_PROJECT = "aria";
699
- const SERENA_TOOL_MAP = {
700
- find_symbol: "find_symbol",
701
- find_references: "find_referencing_symbols",
702
- overview: "get_symbols_overview",
703
- replace_body: "replace_symbol_body",
704
- insert_after: "insert_after_symbol",
705
- insert_before: "insert_before_symbol",
706
- rename: "rename_symbol",
707
- search: "search_for_pattern",
708
- };
709
- // ---------------------------------------------------------------------------
710
- // Serena auto-start: spawn the HTTP project server on demand
711
- // ---------------------------------------------------------------------------
712
- let serenaStarting = null;
713
- async function isSerenaAlive() {
714
- // Lightweight TCP probe — just check if something is listening on the port.
715
- // A full HTTP request is too heavy during startup (Serena takes seconds to load projects).
716
- return new Promise((resolve) => {
717
- const sock = (0, node_net_1.createConnection)({ host: "127.0.0.1", port: SERENA_PORT }, () => {
718
- sock.destroy();
719
- resolve(true);
720
- });
721
- sock.setTimeout(2_000);
722
- sock.on("error", () => resolve(false));
723
- sock.on("timeout", () => {
724
- sock.destroy();
725
- resolve(false);
726
- });
727
- });
728
- }
729
- function findSerenaProjectRoot() {
730
- // Walk up from cwd looking for .serena/project.yml
731
- let dir = (0, node_path_1.resolve)(process.cwd());
732
- while (dir !== (0, node_path_1.dirname)(dir)) {
733
- if ((0, node_fs_1.existsSync)((0, node_path_1.join)(dir, ".serena", "project.yml")))
734
- return dir;
735
- dir = (0, node_path_1.dirname)(dir);
736
- }
737
- // Fallback: walk up from this file's directory
738
- // (compiled JS lives in packages/tools/dist/executors/)
739
- // __dirname is available since the build target is CJS
740
- dir = typeof __dirname === "string" ? (0, node_path_1.resolve)(__dirname) : (0, node_path_1.resolve)(".");
741
- while (dir !== (0, node_path_1.dirname)(dir)) {
742
- if ((0, node_fs_1.existsSync)((0, node_path_1.join)(dir, ".serena", "project.yml")))
743
- return dir;
744
- dir = (0, node_path_1.dirname)(dir);
745
- }
746
- return process.cwd();
747
- }
748
- let cachedSerenaBin;
749
- function resolveSerenaBin() {
750
- if (cachedSerenaBin !== undefined)
751
- return cachedSerenaBin;
752
- // Find the serena binary from uv's cache directory.
753
- // We avoid `uvx --from git+... which serena` because it triggers a blocking
754
- // git fetch that hangs inside a detached spawn context.
755
- const cacheBase = (0, node_path_1.join)(process.env.HOME ?? "/tmp", ".cache", "uv", "archive-v0");
756
- try {
757
- const entries = (0, node_fs_1.readdirSync)(cacheBase)
758
- .map((d) => (0, node_path_1.join)(cacheBase, d, "bin", "serena"))
759
- .filter((p) => (0, node_fs_1.existsSync)(p))
760
- .sort((a, b) => (0, node_fs_1.statSync)(b).mtimeMs - (0, node_fs_1.statSync)(a).mtimeMs);
761
- cachedSerenaBin = entries.length > 0 ? entries[0] : null;
762
- }
763
- catch {
764
- cachedSerenaBin = null;
765
- }
766
- return cachedSerenaBin ?? null;
767
- }
768
- function spawnSerenaServer() {
769
- const projectRoot = findSerenaProjectRoot();
770
- const serenaBin = resolveSerenaBin();
771
- if (!serenaBin)
772
- return;
773
- // Spawn the cached Python binary directly with stdio:'ignore' + detached.
774
- // Using 'uvx --from git+...' does NOT work because uvx triggers a blocking
775
- // git fetch that hangs/dies with closed file descriptors.
776
- const child = (0, node_child_process_1.spawn)(serenaBin, ["start-project-server", "--port", String(SERENA_PORT)], {
777
- cwd: projectRoot,
778
- detached: true,
779
- stdio: "ignore",
780
- env: { ...process.env },
781
- });
782
- child.unref();
783
- }
784
- async function ensureSerenaServer() {
785
- if (await isSerenaAlive())
786
- return true;
787
- // Deduplicate concurrent start attempts
788
- if (serenaStarting)
789
- return serenaStarting;
790
- serenaStarting = (async () => {
791
- spawnSerenaServer();
792
- // Poll for readiness (serena can take a few seconds to initialize)
793
- const deadline = Date.now() + 30_000;
794
- const interval = 500;
795
- while (Date.now() < deadline) {
796
- await new Promise((r) => setTimeout(r, interval));
797
- if (await isSerenaAlive()) {
798
- serenaStarting = null;
799
- return true;
800
- }
801
- }
802
- serenaStarting = null;
803
- return false;
804
- })();
805
- return serenaStarting;
806
- }
807
- async function executeSerena(input, ctx) {
808
- if (ctx.abortSignal?.aborted)
809
- return (0, utils_js_1.fail)("Operation cancelled");
810
- const toolName = SERENA_TOOL_MAP[input.action];
811
- if (!toolName)
812
- return (0, utils_js_1.fail)(`Unknown serena action: ${input.action}`);
813
- const isMutation = ["replace_body", "insert_after", "insert_before", "rename"].includes(input.action);
814
- if (isMutation && ctx.confirm) {
815
- const desc = input.action === "rename"
816
- ? `Rename "${input.name_path}" to "${input.new_name}"?`
817
- : `${input.action} on "${input.name_path}"?`;
818
- const ok = await ctx.confirm(desc);
819
- if (!ok)
820
- return (0, utils_js_1.fail)("Cancelled by user");
821
- }
822
- // Auto-start the Serena project server if not running
823
- const alive = await ensureSerenaServer();
824
- if (!alive) {
825
- return (0, utils_js_1.fail)("Failed to auto-start Serena project server after 30s. " +
826
- "Check logs or start manually:\n" +
827
- `uvx --from "git+https://github.com/oraios/serena" serena start-project-server --port ${SERENA_PORT}`);
828
- }
829
- const params = { ...input.extra_args };
830
- if (input.name_path) {
831
- if (input.action === "find_symbol") {
832
- params.name_path_pattern = input.name_path;
833
- }
834
- else {
835
- params.name_path = input.name_path;
836
- }
837
- }
838
- if (input.relative_path)
839
- params.relative_path = input.relative_path;
840
- if (input.include_body != null)
841
- params.include_body = input.include_body;
842
- if (input.include_info != null)
843
- params.include_info = input.include_info;
844
- if (input.depth != null)
845
- params.depth = input.depth;
846
- if (input.body)
847
- params.body = input.body;
848
- if (input.new_name)
849
- params.new_name = input.new_name;
850
- if (input.pattern)
851
- params.substring_pattern = input.pattern;
852
- if (input.context_before != null)
853
- params.context_lines_before = input.context_before;
854
- if (input.context_after != null)
855
- params.context_lines_after = input.context_after;
856
- if (input.paths_include)
857
- params.paths_include_glob = input.paths_include;
858
- if (input.paths_exclude)
859
- params.paths_exclude_glob = input.paths_exclude;
860
- try {
861
- const body = JSON.stringify({
862
- project_name: SERENA_PROJECT,
863
- tool_name: toolName,
864
- tool_params_json: JSON.stringify(params),
865
- });
866
- const response = await fetch(`${SERENA_BASE}/query_project`, {
867
- method: "POST",
868
- headers: { "Content-Type": "application/json" },
869
- body,
870
- signal: ctx.abortSignal,
871
- });
872
- if (!response.ok) {
873
- const text = await response.text();
874
- return (0, utils_js_1.fail)(`serena ${input.action}: HTTP ${response.status} — ${text.slice(0, 200)}`);
875
- }
876
- const text = await response.text();
877
- try {
878
- return (0, utils_js_1.success)(`serena ${input.action} completed`, JSON.parse(text));
879
- }
880
- catch {
881
- return (0, utils_js_1.success)(`serena ${input.action} completed`, { raw: text });
882
- }
883
- }
884
- catch (err) {
885
- const e = asExecError(err);
886
- return (0, utils_js_1.fail)(`serena ${input.action} failed: ${e.message}`);
887
- }
888
- }
889
- // ---------------------------------------------------------------------------
890
- // 8. fff — native CLI (fff-cli binary, zero MCP)
891
- // ---------------------------------------------------------------------------
892
- async function executeFff(input, ctx) {
893
- if (ctx.abortSignal?.aborted)
894
- return (0, utils_js_1.fail)("Operation cancelled");
895
- if (!(await hasBinary("fff-cli")))
896
- return (0, utils_js_1.fail)("fff-cli not installed. Build: cd vendor/fff-cli && cargo build --release && cp target/release/fff-cli ~/.local/bin/");
897
- const args = [input.action];
898
- // Query or patterns. Native fff-cli supports positional query terms; constraints are
899
- // appended as additional terms for grep/find_files and patterns for multi_grep.
900
- if (input.action === "multi_grep" && input.patterns?.length) {
901
- args.push(...input.patterns);
902
- if (input.constraints)
903
- args.push(input.constraints);
904
- }
905
- else {
906
- if (input.query)
907
- args.push(input.query);
908
- if (input.constraints)
909
- args.push(input.constraints);
910
- }
911
- // Path
912
- args.push("--path", input.path ?? ctx.workingDir);
913
- try {
914
- const { stdout } = await shellExec("fff-cli", args, {
915
- cwd: ctx.workingDir,
916
- signal: ctx.abortSignal,
917
- timeout: 30_000,
918
- });
919
- return (0, utils_js_1.success)(`fff ${input.action} completed`, JSON.parse(stdout));
920
- }
921
- catch (err) {
922
- const e = asExecError(err);
923
- return (0, utils_js_1.fail)(`fff ${input.action} failed: ${e.stderr || e.message}`);
924
- }
925
- }