sweet-search 0.0.1 → 2.3.0

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 (161) hide show
  1. package/LICENSE +190 -0
  2. package/NOTICE +23 -0
  3. package/core/cli.js +51 -0
  4. package/core/config.js +27 -0
  5. package/core/embedding/embedding-cache.js +467 -0
  6. package/core/embedding/embedding-local-model.js +845 -0
  7. package/core/embedding/embedding-remote.js +492 -0
  8. package/core/embedding/embedding-service.js +712 -0
  9. package/core/embedding/embedding-telemetry.js +219 -0
  10. package/core/embedding/index.js +40 -0
  11. package/core/graph/community-detector.js +294 -0
  12. package/core/graph/graph-expansion.js +839 -0
  13. package/core/graph/graph-extractor.js +2304 -0
  14. package/core/graph/graph-search.js +2148 -0
  15. package/core/graph/hcgs-generator.js +666 -0
  16. package/core/graph/index.js +16 -0
  17. package/core/graph/leiden-algorithm.js +547 -0
  18. package/core/graph/relationship-resolver.js +366 -0
  19. package/core/graph/repo-map.js +408 -0
  20. package/core/graph/summary-manager.js +549 -0
  21. package/core/indexing/artifact-builder.js +1054 -0
  22. package/core/indexing/ast-chunker.js +709 -0
  23. package/core/indexing/chunking/chunk-builder.js +170 -0
  24. package/core/indexing/chunking/markdown-chunker.js +503 -0
  25. package/core/indexing/chunking/plaintext-chunker.js +104 -0
  26. package/core/indexing/dedup/dedup-phase.js +159 -0
  27. package/core/indexing/dedup/exemplar-selector.js +65 -0
  28. package/core/indexing/document-chunker.js +56 -0
  29. package/core/indexing/incremental-parser.js +390 -0
  30. package/core/indexing/incremental-tracker.js +761 -0
  31. package/core/indexing/index-codebase-v21.js +472 -0
  32. package/core/indexing/index-maintainer.mjs +1674 -0
  33. package/core/indexing/index.js +90 -0
  34. package/core/indexing/indexer-ann.js +1077 -0
  35. package/core/indexing/indexer-build.js +742 -0
  36. package/core/indexing/indexer-phases.js +800 -0
  37. package/core/indexing/indexer-pool.js +764 -0
  38. package/core/indexing/indexer-sparse-gram.js +98 -0
  39. package/core/indexing/indexer-utils.js +536 -0
  40. package/core/indexing/indexer-worker.js +148 -0
  41. package/core/indexing/li-skip-policy.js +225 -0
  42. package/core/indexing/merkle-tracker.js +244 -0
  43. package/core/indexing/model-pool.js +166 -0
  44. package/core/infrastructure/code-graph-repository.js +120 -0
  45. package/core/infrastructure/codebase-repository.js +131 -0
  46. package/core/infrastructure/config/dedup.js +54 -0
  47. package/core/infrastructure/config/embedding.js +298 -0
  48. package/core/infrastructure/config/graph.js +80 -0
  49. package/core/infrastructure/config/index.js +82 -0
  50. package/core/infrastructure/config/indexing.js +8 -0
  51. package/core/infrastructure/config/platform.js +254 -0
  52. package/core/infrastructure/config/ranking.js +221 -0
  53. package/core/infrastructure/config/search.js +396 -0
  54. package/core/infrastructure/config/translation.js +89 -0
  55. package/core/infrastructure/config/vector-store.js +114 -0
  56. package/core/infrastructure/constants.js +86 -0
  57. package/core/infrastructure/coreml-cascade.js +909 -0
  58. package/core/infrastructure/coreml-cascade.json +46 -0
  59. package/core/infrastructure/coreml-provider.js +81 -0
  60. package/core/infrastructure/db-utils.js +69 -0
  61. package/core/infrastructure/dedup-hashing.js +83 -0
  62. package/core/infrastructure/hardware-capability.js +332 -0
  63. package/core/infrastructure/index.js +104 -0
  64. package/core/infrastructure/language-patterns/maps.js +121 -0
  65. package/core/infrastructure/language-patterns/registry-core.js +323 -0
  66. package/core/infrastructure/language-patterns/registry-data-query.js +155 -0
  67. package/core/infrastructure/language-patterns/registry-object-oriented.js +285 -0
  68. package/core/infrastructure/language-patterns/registry-tooling.js +240 -0
  69. package/core/infrastructure/language-patterns/registry-web-style.js +143 -0
  70. package/core/infrastructure/language-patterns/registry.js +19 -0
  71. package/core/infrastructure/language-patterns.js +141 -0
  72. package/core/infrastructure/llm-provider.js +733 -0
  73. package/core/infrastructure/manifest.json +46 -0
  74. package/core/infrastructure/maxsim.wasm +0 -0
  75. package/core/infrastructure/model-fetcher.js +423 -0
  76. package/core/infrastructure/model-registry.js +214 -0
  77. package/core/infrastructure/native-inference.js +587 -0
  78. package/core/infrastructure/native-resolver.js +187 -0
  79. package/core/infrastructure/native-sparse-gram.js +257 -0
  80. package/core/infrastructure/native-tokenizer.js +160 -0
  81. package/core/infrastructure/onnx-mutex.js +45 -0
  82. package/core/infrastructure/onnx-session-utils.js +261 -0
  83. package/core/infrastructure/ort-pipeline.js +111 -0
  84. package/core/infrastructure/project-detector.js +102 -0
  85. package/core/infrastructure/quantization.js +410 -0
  86. package/core/infrastructure/simd-distance.js +502 -0
  87. package/core/infrastructure/simd-distance.wasm +0 -0
  88. package/core/infrastructure/tree-sitter-provider.js +665 -0
  89. package/core/infrastructure/webgpu-maxsim.js +222 -0
  90. package/core/query/index.js +35 -0
  91. package/core/query/intent-detector.js +201 -0
  92. package/core/query/intent-router.js +156 -0
  93. package/core/query/query-router-catboost.js +222 -0
  94. package/core/query/query-router-ml.js +266 -0
  95. package/core/query/query-router.js +213 -0
  96. package/core/ranking/cascaded-scorer.js +379 -0
  97. package/core/ranking/flashrank.js +810 -0
  98. package/core/ranking/index.js +49 -0
  99. package/core/ranking/late-interaction-index.js +2383 -0
  100. package/core/ranking/late-interaction-model.js +812 -0
  101. package/core/ranking/local-reranker.js +374 -0
  102. package/core/ranking/mmr.js +379 -0
  103. package/core/ranking/quality-scorer.js +363 -0
  104. package/core/search/context-expander.js +1167 -0
  105. package/core/search/dedup/sibling-expander.js +327 -0
  106. package/core/search/index.js +16 -0
  107. package/core/search/search-boost.js +259 -0
  108. package/core/search/search-cli.js +544 -0
  109. package/core/search/search-format.js +282 -0
  110. package/core/search/search-fusion.js +327 -0
  111. package/core/search/search-hybrid.js +204 -0
  112. package/core/search/search-pattern-chunks.js +337 -0
  113. package/core/search/search-pattern-planner.js +439 -0
  114. package/core/search/search-pattern-prefilter.js +412 -0
  115. package/core/search/search-pattern-ripgrep.js +663 -0
  116. package/core/search/search-pattern.js +463 -0
  117. package/core/search/search-postprocess.js +452 -0
  118. package/core/search/search-semantic.js +706 -0
  119. package/core/search/search-server.js +554 -0
  120. package/core/search/session-daemon-prewarm.mjs +164 -0
  121. package/core/search/session-warmup.js +595 -0
  122. package/core/search/sweet-search.js +632 -0
  123. package/core/search/warmup-metrics.js +532 -0
  124. package/core/start-server.js +6 -0
  125. package/core/training/query-router/features/extractor.js +762 -0
  126. package/core/training/query-router/features/multilingual-patterns.js +431 -0
  127. package/core/training/query-router/features/text-segmenter.js +303 -0
  128. package/core/training/query-router/features/unicode-utils.js +383 -0
  129. package/core/training/query-router/output/v45_router_d4.js +11521 -0
  130. package/core/training/query-router/output/v46_router_d4.js +11498 -0
  131. package/core/vector-store/binary-heap.js +227 -0
  132. package/core/vector-store/binary-hnsw-index.js +1004 -0
  133. package/core/vector-store/float-vector-store.js +234 -0
  134. package/core/vector-store/hnsw-index.js +580 -0
  135. package/core/vector-store/index.js +39 -0
  136. package/core/vector-store/seismic-index.js +498 -0
  137. package/core/vocabulary/index.js +84 -0
  138. package/core/vocabulary/vocab-constants.js +20 -0
  139. package/core/vocabulary/vocab-miner-extractors.js +375 -0
  140. package/core/vocabulary/vocab-miner-nl.js +404 -0
  141. package/core/vocabulary/vocab-miner-utils.js +146 -0
  142. package/core/vocabulary/vocab-miner.js +574 -0
  143. package/core/vocabulary/vocab-prewarm-cli.js +110 -0
  144. package/core/vocabulary/vocab-ranker.js +492 -0
  145. package/core/vocabulary/vocab-warmer.js +523 -0
  146. package/core/vocabulary/vocab-warmup-orchestrator.js +425 -0
  147. package/core/vocabulary/vocabulary-utils.js +704 -0
  148. package/crates/wasm-router/pkg/package.json +13 -0
  149. package/crates/wasm-router/pkg/query_router_wasm.d.ts +36 -0
  150. package/crates/wasm-router/pkg/query_router_wasm.js +271 -0
  151. package/crates/wasm-router/pkg/query_router_wasm_bg.wasm +0 -0
  152. package/crates/wasm-router/pkg/query_router_wasm_bg.wasm.d.ts +19 -0
  153. package/mcp/config-gen.js +121 -0
  154. package/mcp/server.js +335 -0
  155. package/mcp/tool-handlers.js +476 -0
  156. package/package.json +131 -9
  157. package/scripts/benchmark-harness.js +794 -0
  158. package/scripts/init.js +1058 -0
  159. package/scripts/smoke-test.js +435 -0
  160. package/scripts/uninstall.js +478 -0
  161. package/scripts/verify-runtime.js +176 -0
@@ -0,0 +1,36 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Route labels
6
+ */
7
+ export enum RouteMode {
8
+ Lexical = 0,
9
+ Semantic = 1,
10
+ Hybrid = 2,
11
+ }
12
+
13
+ export class RouteResult {
14
+ private constructor();
15
+ free(): void;
16
+ [Symbol.dispose](): void;
17
+ readonly mode_str: string;
18
+ mode: RouteMode;
19
+ confidence: number;
20
+ rejected: boolean;
21
+ }
22
+
23
+ /**
24
+ * Export features for debugging
25
+ */
26
+ export function extract_features_js(query: string): Float32Array;
27
+
28
+ /**
29
+ * Initialize panic hook for better error messages
30
+ */
31
+ export function init(): void;
32
+
33
+ /**
34
+ * Main entry point - route a query string
35
+ */
36
+ export function route_query(query: string): RouteResult;
@@ -0,0 +1,271 @@
1
+
2
+ let imports = {};
3
+ imports['__wbindgen_placeholder__'] = module.exports;
4
+
5
+ function getArrayF32FromWasm0(ptr, len) {
6
+ ptr = ptr >>> 0;
7
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
8
+ }
9
+
10
+ let cachedDataViewMemory0 = null;
11
+ function getDataViewMemory0() {
12
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
13
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
14
+ }
15
+ return cachedDataViewMemory0;
16
+ }
17
+
18
+ let cachedFloat32ArrayMemory0 = null;
19
+ function getFloat32ArrayMemory0() {
20
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
21
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
22
+ }
23
+ return cachedFloat32ArrayMemory0;
24
+ }
25
+
26
+ function getStringFromWasm0(ptr, len) {
27
+ ptr = ptr >>> 0;
28
+ return decodeText(ptr, len);
29
+ }
30
+
31
+ let cachedUint8ArrayMemory0 = null;
32
+ function getUint8ArrayMemory0() {
33
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
34
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
35
+ }
36
+ return cachedUint8ArrayMemory0;
37
+ }
38
+
39
+ function passStringToWasm0(arg, malloc, realloc) {
40
+ if (realloc === undefined) {
41
+ const buf = cachedTextEncoder.encode(arg);
42
+ const ptr = malloc(buf.length, 1) >>> 0;
43
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
44
+ WASM_VECTOR_LEN = buf.length;
45
+ return ptr;
46
+ }
47
+
48
+ let len = arg.length;
49
+ let ptr = malloc(len, 1) >>> 0;
50
+
51
+ const mem = getUint8ArrayMemory0();
52
+
53
+ let offset = 0;
54
+
55
+ for (; offset < len; offset++) {
56
+ const code = arg.charCodeAt(offset);
57
+ if (code > 0x7F) break;
58
+ mem[ptr + offset] = code;
59
+ }
60
+ if (offset !== len) {
61
+ if (offset !== 0) {
62
+ arg = arg.slice(offset);
63
+ }
64
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
65
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
66
+ const ret = cachedTextEncoder.encodeInto(arg, view);
67
+
68
+ offset += ret.written;
69
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
70
+ }
71
+
72
+ WASM_VECTOR_LEN = offset;
73
+ return ptr;
74
+ }
75
+
76
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
77
+ cachedTextDecoder.decode();
78
+ function decodeText(ptr, len) {
79
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
80
+ }
81
+
82
+ const cachedTextEncoder = new TextEncoder();
83
+
84
+ if (!('encodeInto' in cachedTextEncoder)) {
85
+ cachedTextEncoder.encodeInto = function (arg, view) {
86
+ const buf = cachedTextEncoder.encode(arg);
87
+ view.set(buf);
88
+ return {
89
+ read: arg.length,
90
+ written: buf.length
91
+ };
92
+ }
93
+ }
94
+
95
+ let WASM_VECTOR_LEN = 0;
96
+
97
+ const RouteResultFinalization = (typeof FinalizationRegistry === 'undefined')
98
+ ? { register: () => {}, unregister: () => {} }
99
+ : new FinalizationRegistry(ptr => wasm.__wbg_routeresult_free(ptr >>> 0, 1));
100
+
101
+ /**
102
+ * Route labels
103
+ * @enum {0 | 1 | 2}
104
+ */
105
+ const RouteMode = Object.freeze({
106
+ Lexical: 0, "0": "Lexical",
107
+ Semantic: 1, "1": "Semantic",
108
+ Hybrid: 2, "2": "Hybrid",
109
+ });
110
+ exports.RouteMode = RouteMode;
111
+
112
+ /**
113
+ * Routing result
114
+ */
115
+ class RouteResult {
116
+ static __wrap(ptr) {
117
+ ptr = ptr >>> 0;
118
+ const obj = Object.create(RouteResult.prototype);
119
+ obj.__wbg_ptr = ptr;
120
+ RouteResultFinalization.register(obj, obj.__wbg_ptr, obj);
121
+ return obj;
122
+ }
123
+ __destroy_into_raw() {
124
+ const ptr = this.__wbg_ptr;
125
+ this.__wbg_ptr = 0;
126
+ RouteResultFinalization.unregister(this);
127
+ return ptr;
128
+ }
129
+ free() {
130
+ const ptr = this.__destroy_into_raw();
131
+ wasm.__wbg_routeresult_free(ptr, 0);
132
+ }
133
+ /**
134
+ * @returns {string}
135
+ */
136
+ get mode_str() {
137
+ let deferred1_0;
138
+ let deferred1_1;
139
+ try {
140
+ const ret = wasm.routeresult_mode_str(this.__wbg_ptr);
141
+ deferred1_0 = ret[0];
142
+ deferred1_1 = ret[1];
143
+ return getStringFromWasm0(ret[0], ret[1]);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
146
+ }
147
+ }
148
+ /**
149
+ * @returns {RouteMode}
150
+ */
151
+ get mode() {
152
+ const ret = wasm.__wbg_get_routeresult_mode(this.__wbg_ptr);
153
+ return ret;
154
+ }
155
+ /**
156
+ * @param {RouteMode} arg0
157
+ */
158
+ set mode(arg0) {
159
+ wasm.__wbg_set_routeresult_mode(this.__wbg_ptr, arg0);
160
+ }
161
+ /**
162
+ * @returns {number}
163
+ */
164
+ get confidence() {
165
+ const ret = wasm.__wbg_get_routeresult_confidence(this.__wbg_ptr);
166
+ return ret;
167
+ }
168
+ /**
169
+ * @param {number} arg0
170
+ */
171
+ set confidence(arg0) {
172
+ wasm.__wbg_set_routeresult_confidence(this.__wbg_ptr, arg0);
173
+ }
174
+ /**
175
+ * @returns {boolean}
176
+ */
177
+ get rejected() {
178
+ const ret = wasm.__wbg_get_routeresult_rejected(this.__wbg_ptr);
179
+ return ret !== 0;
180
+ }
181
+ /**
182
+ * @param {boolean} arg0
183
+ */
184
+ set rejected(arg0) {
185
+ wasm.__wbg_set_routeresult_rejected(this.__wbg_ptr, arg0);
186
+ }
187
+ }
188
+ if (Symbol.dispose) RouteResult.prototype[Symbol.dispose] = RouteResult.prototype.free;
189
+ exports.RouteResult = RouteResult;
190
+
191
+ /**
192
+ * Export features for debugging
193
+ * @param {string} query
194
+ * @returns {Float32Array}
195
+ */
196
+ function extract_features_js(query) {
197
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
198
+ const len0 = WASM_VECTOR_LEN;
199
+ const ret = wasm.extract_features_js(ptr0, len0);
200
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
201
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
202
+ return v2;
203
+ }
204
+ exports.extract_features_js = extract_features_js;
205
+
206
+ /**
207
+ * Initialize panic hook for better error messages
208
+ */
209
+ function init() {
210
+ wasm.init();
211
+ }
212
+ exports.init = init;
213
+
214
+ /**
215
+ * Main entry point - route a query string
216
+ * @param {string} query
217
+ * @returns {RouteResult}
218
+ */
219
+ function route_query(query) {
220
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
221
+ const len0 = WASM_VECTOR_LEN;
222
+ const ret = wasm.route_query(ptr0, len0);
223
+ return RouteResult.__wrap(ret);
224
+ }
225
+ exports.route_query = route_query;
226
+
227
+ exports.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
228
+ throw new Error(getStringFromWasm0(arg0, arg1));
229
+ };
230
+
231
+ exports.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
232
+ let deferred0_0;
233
+ let deferred0_1;
234
+ try {
235
+ deferred0_0 = arg0;
236
+ deferred0_1 = arg1;
237
+ console.error(getStringFromWasm0(arg0, arg1));
238
+ } finally {
239
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
240
+ }
241
+ };
242
+
243
+ exports.__wbg_new_8a6f238a6ece86ea = function() {
244
+ const ret = new Error();
245
+ return ret;
246
+ };
247
+
248
+ exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
249
+ const ret = arg1.stack;
250
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
251
+ const len1 = WASM_VECTOR_LEN;
252
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
253
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
254
+ };
255
+
256
+ exports.__wbindgen_init_externref_table = function() {
257
+ const table = wasm.__wbindgen_externrefs;
258
+ const offset = table.grow(4);
259
+ table.set(0, undefined);
260
+ table.set(offset + 0, undefined);
261
+ table.set(offset + 1, null);
262
+ table.set(offset + 2, true);
263
+ table.set(offset + 3, false);
264
+ };
265
+
266
+ const wasmPath = `${__dirname}/query_router_wasm_bg.wasm`;
267
+ const wasmBytes = require('fs').readFileSync(wasmPath);
268
+ const wasmModule = new WebAssembly.Module(wasmBytes);
269
+ const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
270
+
271
+ wasm.__wbindgen_start();
@@ -0,0 +1,19 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_get_routeresult_confidence: (a: number) => number;
5
+ export const __wbg_get_routeresult_mode: (a: number) => number;
6
+ export const __wbg_get_routeresult_rejected: (a: number) => number;
7
+ export const __wbg_routeresult_free: (a: number, b: number) => void;
8
+ export const __wbg_set_routeresult_confidence: (a: number, b: number) => void;
9
+ export const __wbg_set_routeresult_mode: (a: number, b: number) => void;
10
+ export const __wbg_set_routeresult_rejected: (a: number, b: number) => void;
11
+ export const extract_features_js: (a: number, b: number) => [number, number];
12
+ export const route_query: (a: number, b: number) => number;
13
+ export const routeresult_mode_str: (a: number) => [number, number];
14
+ export const init: () => void;
15
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
16
+ export const __wbindgen_malloc: (a: number, b: number) => number;
17
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
18
+ export const __wbindgen_externrefs: WebAssembly.Table;
19
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const PROJECT_ROOT = path.resolve(__dirname, '..');
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Profiles
12
+ // ---------------------------------------------------------------------------
13
+
14
+ function devLocal(platform) {
15
+ if (platform === 'claude') {
16
+ return {
17
+ mcpServers: {
18
+ 'sweet-search': {
19
+ command: 'node',
20
+ args: ['./mcp/server.js'],
21
+ },
22
+ },
23
+ };
24
+ }
25
+
26
+ // codex
27
+ return [
28
+ '[mcp_servers.sweet-search]',
29
+ 'command = "node"',
30
+ 'args = ["./mcp/server.js"]',
31
+ ].join('\n');
32
+ }
33
+
34
+ function externalProject(platform, targetPath) {
35
+ const serverPath = path.resolve(PROJECT_ROOT, 'mcp', 'server.js');
36
+ const target = targetPath ? path.resolve(targetPath) : '/absolute/path/to/target-project';
37
+
38
+ if (platform === 'claude') {
39
+ return {
40
+ mcpServers: {
41
+ 'sweet-search': {
42
+ command: 'node',
43
+ args: [serverPath, '--project-root', target],
44
+ env: {
45
+ SWEET_SEARCH_PROJECT_ROOT: target,
46
+ },
47
+ },
48
+ },
49
+ };
50
+ }
51
+
52
+ // codex
53
+ return [
54
+ '[mcp_servers.sweet-search]',
55
+ `command = "node"`,
56
+ `args = ["${serverPath}"]`,
57
+ `cwd = "${target}"`,
58
+ `env = { "SWEET_SEARCH_PROJECT_ROOT" = "${target}" }`,
59
+ '# enabled = true',
60
+ '# startup_timeout_sec = 15',
61
+ '# tool_timeout_sec = 120',
62
+ '# enabled_tools = ["search", "health"]',
63
+ '# disabled_tools = []',
64
+ ].join('\n');
65
+ }
66
+
67
+ function published(platform) {
68
+ if (platform === 'claude') {
69
+ return {
70
+ mcpServers: {
71
+ 'sweet-search': {
72
+ command: 'npx',
73
+ args: ['-y', 'sweet-search-mcp'],
74
+ },
75
+ },
76
+ };
77
+ }
78
+
79
+ // codex
80
+ return [
81
+ '[mcp_servers.sweet-search]',
82
+ 'command = "npx"',
83
+ 'args = ["-y", "sweet-search-mcp"]',
84
+ '# env = { "SWEET_SEARCH_PROJECT_ROOT" = "/path/to/project" }',
85
+ '# enabled = true',
86
+ '# startup_timeout_sec = 15',
87
+ '# tool_timeout_sec = 120',
88
+ ].join('\n');
89
+ }
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // CLI
93
+ // ---------------------------------------------------------------------------
94
+
95
+ const args = process.argv.slice(2);
96
+ const platform = args[0] || 'claude';
97
+ const profileIdx = args.indexOf('--profile');
98
+ const profile = profileIdx !== -1 ? args[profileIdx + 1] : 'dev-local';
99
+ const targetIdx = args.indexOf('--target');
100
+ const targetPath = targetIdx !== -1 ? args[targetIdx + 1] : undefined;
101
+
102
+ if (!['claude', 'codex'].includes(platform)) {
103
+ console.error(`Usage: node mcp/config-gen.js [claude|codex] [--profile dev-local|external-project|published] [--target <path>]`);
104
+ process.exit(1);
105
+ }
106
+
107
+ const profiles = { 'dev-local': devLocal, 'external-project': externalProject, published };
108
+ const generator = profiles[profile];
109
+
110
+ if (!generator) {
111
+ console.error(`Unknown profile: ${profile}. Available: ${Object.keys(profiles).join(', ')}`);
112
+ process.exit(1);
113
+ }
114
+
115
+ const result = generator(platform, targetPath);
116
+
117
+ if (typeof result === 'string') {
118
+ console.log(result);
119
+ } else {
120
+ console.log(JSON.stringify(result, null, 2));
121
+ }