@frontmcp/plugins 0.6.1 → 0.6.3

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 (121) hide show
  1. package/cache/index.js +412 -0
  2. package/codecall/index.js +2988 -0
  3. package/esm/cache/index.mjs +395 -0
  4. package/esm/codecall/index.mjs +2959 -0
  5. package/esm/index.mjs +2951 -0
  6. package/esm/package.json +82 -0
  7. package/index.js +2973 -0
  8. package/package.json +38 -10
  9. package/src/cache/README.md +0 -186
  10. package/src/cache/cache.plugin.js +0 -167
  11. package/src/cache/cache.plugin.js.map +0 -1
  12. package/src/cache/cache.symbol.js +0 -5
  13. package/src/cache/cache.symbol.js.map +0 -1
  14. package/src/cache/cache.types.js +0 -3
  15. package/src/cache/cache.types.js.map +0 -1
  16. package/src/cache/index.js +0 -8
  17. package/src/cache/index.js.map +0 -1
  18. package/src/cache/providers/cache-memory.provider.js +0 -110
  19. package/src/cache/providers/cache-memory.provider.js.map +0 -1
  20. package/src/cache/providers/cache-redis.provider.js +0 -69
  21. package/src/cache/providers/cache-redis.provider.js.map +0 -1
  22. package/src/cache/providers/cache-vercel-kv.provider.js +0 -85
  23. package/src/cache/providers/cache-vercel-kv.provider.js.map +0 -1
  24. package/src/codecall/README.md +0 -999
  25. package/src/codecall/codecall.plugin.js +0 -152
  26. package/src/codecall/codecall.plugin.js.map +0 -1
  27. package/src/codecall/codecall.symbol.js +0 -4
  28. package/src/codecall/codecall.symbol.js.map +0 -1
  29. package/src/codecall/codecall.types.js +0 -262
  30. package/src/codecall/codecall.types.js.map +0 -1
  31. package/src/codecall/errors/index.js +0 -6
  32. package/src/codecall/errors/index.js.map +0 -1
  33. package/src/codecall/errors/tool-call.errors.js +0 -119
  34. package/src/codecall/errors/tool-call.errors.js.map +0 -1
  35. package/src/codecall/index.js +0 -8
  36. package/src/codecall/index.js.map +0 -1
  37. package/src/codecall/providers/code-call.config.js +0 -120
  38. package/src/codecall/providers/code-call.config.js.map +0 -1
  39. package/src/codecall/security/index.js +0 -7
  40. package/src/codecall/security/index.js.map +0 -1
  41. package/src/codecall/security/self-reference-guard.js +0 -70
  42. package/src/codecall/security/self-reference-guard.js.map +0 -1
  43. package/src/codecall/security/tool-access-control.service.js +0 -170
  44. package/src/codecall/security/tool-access-control.service.js.map +0 -1
  45. package/src/codecall/services/audit-logger.service.js +0 -322
  46. package/src/codecall/services/audit-logger.service.js.map +0 -1
  47. package/src/codecall/services/enclave.service.js +0 -214
  48. package/src/codecall/services/enclave.service.js.map +0 -1
  49. package/src/codecall/services/error-enrichment.service.js +0 -387
  50. package/src/codecall/services/error-enrichment.service.js.map +0 -1
  51. package/src/codecall/services/index.js +0 -13
  52. package/src/codecall/services/index.js.map +0 -1
  53. package/src/codecall/services/output-sanitizer.js +0 -260
  54. package/src/codecall/services/output-sanitizer.js.map +0 -1
  55. package/src/codecall/services/synonym-expansion.service.js +0 -374
  56. package/src/codecall/services/synonym-expansion.service.js.map +0 -1
  57. package/src/codecall/services/tool-search.service.js +0 -587
  58. package/src/codecall/services/tool-search.service.js.map +0 -1
  59. package/src/codecall/tools/describe.schema.js +0 -67
  60. package/src/codecall/tools/describe.schema.js.map +0 -1
  61. package/src/codecall/tools/describe.tool.js +0 -207
  62. package/src/codecall/tools/describe.tool.js.map +0 -1
  63. package/src/codecall/tools/execute.schema.js +0 -116
  64. package/src/codecall/tools/execute.schema.js.map +0 -1
  65. package/src/codecall/tools/execute.tool.js +0 -238
  66. package/src/codecall/tools/execute.tool.js.map +0 -1
  67. package/src/codecall/tools/index.js +0 -13
  68. package/src/codecall/tools/index.js.map +0 -1
  69. package/src/codecall/tools/invoke.schema.js +0 -27
  70. package/src/codecall/tools/invoke.schema.js.map +0 -1
  71. package/src/codecall/tools/invoke.tool.js +0 -70
  72. package/src/codecall/tools/invoke.tool.js.map +0 -1
  73. package/src/codecall/tools/search.schema.js +0 -60
  74. package/src/codecall/tools/search.schema.js.map +0 -1
  75. package/src/codecall/tools/search.tool.js +0 -108
  76. package/src/codecall/tools/search.tool.js.map +0 -1
  77. package/src/codecall/utils/describe.utils.js +0 -531
  78. package/src/codecall/utils/describe.utils.js.map +0 -1
  79. package/src/codecall/utils/index.js +0 -7
  80. package/src/codecall/utils/index.js.map +0 -1
  81. package/src/codecall/utils/mcp-result.js +0 -36
  82. package/src/codecall/utils/mcp-result.js.map +0 -1
  83. package/src/index.js +0 -9
  84. package/src/index.js.map +0 -1
  85. /package/{src/cache → cache}/cache.plugin.d.ts +0 -0
  86. /package/{src/cache → cache}/cache.symbol.d.ts +0 -0
  87. /package/{src/cache → cache}/cache.types.d.ts +0 -0
  88. /package/{src/cache → cache}/index.d.ts +0 -0
  89. /package/{src/cache → cache}/providers/cache-memory.provider.d.ts +0 -0
  90. /package/{src/cache → cache}/providers/cache-redis.provider.d.ts +0 -0
  91. /package/{src/cache → cache}/providers/cache-vercel-kv.provider.d.ts +0 -0
  92. /package/{src/codecall → codecall}/codecall.plugin.d.ts +0 -0
  93. /package/{src/codecall → codecall}/codecall.symbol.d.ts +0 -0
  94. /package/{src/codecall → codecall}/codecall.types.d.ts +0 -0
  95. /package/{src/codecall → codecall}/errors/index.d.ts +0 -0
  96. /package/{src/codecall → codecall}/errors/tool-call.errors.d.ts +0 -0
  97. /package/{src/codecall → codecall}/index.d.ts +0 -0
  98. /package/{src/codecall → codecall}/providers/code-call.config.d.ts +0 -0
  99. /package/{src/codecall → codecall}/security/index.d.ts +0 -0
  100. /package/{src/codecall → codecall}/security/self-reference-guard.d.ts +0 -0
  101. /package/{src/codecall → codecall}/security/tool-access-control.service.d.ts +0 -0
  102. /package/{src/codecall → codecall}/services/audit-logger.service.d.ts +0 -0
  103. /package/{src/codecall → codecall}/services/enclave.service.d.ts +0 -0
  104. /package/{src/codecall → codecall}/services/error-enrichment.service.d.ts +0 -0
  105. /package/{src/codecall → codecall}/services/index.d.ts +0 -0
  106. /package/{src/codecall → codecall}/services/output-sanitizer.d.ts +0 -0
  107. /package/{src/codecall → codecall}/services/synonym-expansion.service.d.ts +0 -0
  108. /package/{src/codecall → codecall}/services/tool-search.service.d.ts +0 -0
  109. /package/{src/codecall → codecall}/tools/describe.schema.d.ts +0 -0
  110. /package/{src/codecall → codecall}/tools/describe.tool.d.ts +0 -0
  111. /package/{src/codecall → codecall}/tools/execute.schema.d.ts +0 -0
  112. /package/{src/codecall → codecall}/tools/execute.tool.d.ts +0 -0
  113. /package/{src/codecall → codecall}/tools/index.d.ts +0 -0
  114. /package/{src/codecall → codecall}/tools/invoke.schema.d.ts +0 -0
  115. /package/{src/codecall → codecall}/tools/invoke.tool.d.ts +0 -0
  116. /package/{src/codecall → codecall}/tools/search.schema.d.ts +0 -0
  117. /package/{src/codecall → codecall}/tools/search.tool.d.ts +0 -0
  118. /package/{src/codecall → codecall}/utils/describe.utils.d.ts +0 -0
  119. /package/{src/codecall → codecall}/utils/index.d.ts +0 -0
  120. /package/{src/codecall → codecall}/utils/mcp-result.d.ts +0 -0
  121. /package/{src/index.d.ts → index.d.ts} +0 -0
@@ -1,260 +0,0 @@
1
- "use strict";
2
- // file: libs/plugins/src/codecall/services/output-sanitizer.ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DEFAULT_SANITIZER_CONFIG = void 0;
5
- exports.sanitizeOutput = sanitizeOutput;
6
- exports.needsSanitization = needsSanitization;
7
- exports.sanitizeLogMessage = sanitizeLogMessage;
8
- /**
9
- * Default sanitization configuration.
10
- */
11
- exports.DEFAULT_SANITIZER_CONFIG = Object.freeze({
12
- maxDepth: 10,
13
- maxStringLength: 10000,
14
- maxObjectKeys: 100,
15
- maxArrayLength: 1000,
16
- maxTotalSize: 1024 * 1024, // 1MB
17
- removeStackTraces: true,
18
- removeFilePaths: true,
19
- });
20
- /**
21
- * Sanitize output from CodeCall script execution.
22
- *
23
- * @param output - Raw output from script
24
- * @param config - Sanitization configuration
25
- * @returns Sanitized output with metadata
26
- */
27
- function sanitizeOutput(output, config = {}) {
28
- const cfg = { ...exports.DEFAULT_SANITIZER_CONFIG, ...config };
29
- const warnings = [];
30
- const seen = new WeakSet();
31
- const result = sanitizeValue(output, cfg, warnings, seen, 0);
32
- // Check total size
33
- try {
34
- const serialized = JSON.stringify(result);
35
- if (serialized && serialized.length > cfg.maxTotalSize) {
36
- warnings.push(`Output truncated: exceeded max size of ${cfg.maxTotalSize} bytes`);
37
- return {
38
- value: { _truncated: true, _reason: 'Output exceeded maximum size' },
39
- wasModified: true,
40
- warnings,
41
- };
42
- }
43
- }
44
- catch {
45
- // If we can't serialize, return a safe placeholder
46
- warnings.push('Output could not be serialized');
47
- return {
48
- value: { _error: 'Output could not be serialized' },
49
- wasModified: true,
50
- warnings,
51
- };
52
- }
53
- return {
54
- value: result,
55
- wasModified: warnings.length > 0,
56
- warnings,
57
- };
58
- }
59
- /**
60
- * Recursively sanitize a value.
61
- */
62
- function sanitizeValue(value, config, warnings, seen, depth) {
63
- // Check depth
64
- if (depth > config.maxDepth) {
65
- warnings.push(`Max depth of ${config.maxDepth} exceeded`);
66
- return '[max depth exceeded]';
67
- }
68
- // Handle null/undefined
69
- if (value === null || value === undefined) {
70
- return value;
71
- }
72
- // Handle primitives
73
- if (typeof value === 'string') {
74
- return sanitizeString(value, config, warnings);
75
- }
76
- if (typeof value === 'number' || typeof value === 'boolean') {
77
- return value;
78
- }
79
- if (typeof value === 'bigint') {
80
- return value.toString();
81
- }
82
- if (typeof value === 'symbol') {
83
- return value.toString();
84
- }
85
- if (typeof value === 'function') {
86
- warnings.push('Function removed from output');
87
- return '[function]';
88
- }
89
- // Handle objects
90
- if (typeof value === 'object') {
91
- // Check for circular references
92
- if (seen.has(value)) {
93
- warnings.push('Circular reference detected');
94
- return '[circular]';
95
- }
96
- seen.add(value);
97
- // Handle arrays
98
- if (Array.isArray(value)) {
99
- return sanitizeArray(value, config, warnings, seen, depth);
100
- }
101
- // Handle Error objects
102
- if (value instanceof Error) {
103
- return sanitizeError(value, config, warnings);
104
- }
105
- // Handle Date objects
106
- if (value instanceof Date) {
107
- return value.toISOString();
108
- }
109
- // Handle RegExp objects
110
- if (value instanceof RegExp) {
111
- return value.toString();
112
- }
113
- // Handle Map
114
- if (value instanceof Map) {
115
- const obj = {};
116
- let count = 0;
117
- for (const [k, v] of value) {
118
- if (count >= config.maxObjectKeys) {
119
- warnings.push(`Map truncated: exceeded ${config.maxObjectKeys} keys`);
120
- break;
121
- }
122
- obj[String(k)] = sanitizeValue(v, config, warnings, seen, depth + 1);
123
- count++;
124
- }
125
- return obj;
126
- }
127
- // Handle Set
128
- if (value instanceof Set) {
129
- const arr = [];
130
- let count = 0;
131
- for (const item of value) {
132
- if (count >= config.maxArrayLength) {
133
- warnings.push(`Set truncated: exceeded ${config.maxArrayLength} items`);
134
- break;
135
- }
136
- arr.push(sanitizeValue(item, config, warnings, seen, depth + 1));
137
- count++;
138
- }
139
- return arr;
140
- }
141
- // Handle plain objects
142
- return sanitizeObject(value, config, warnings, seen, depth);
143
- }
144
- // Unknown type - return safe string representation
145
- return String(value);
146
- }
147
- /**
148
- * Sanitize a string value.
149
- */
150
- function sanitizeString(value, config, warnings) {
151
- let result = value;
152
- // Remove file paths if configured
153
- if (config.removeFilePaths) {
154
- const pathRegex = /(?:\/[\w.-]+)+|(?:[A-Za-z]:\\[\w\\.-]+)+/g;
155
- if (pathRegex.test(result)) {
156
- result = result.replace(pathRegex, '[path]');
157
- warnings.push('File paths removed from string');
158
- }
159
- }
160
- // Truncate if too long
161
- if (result.length > config.maxStringLength) {
162
- result = result.substring(0, config.maxStringLength) + '...[truncated]';
163
- warnings.push(`String truncated: exceeded ${config.maxStringLength} characters`);
164
- }
165
- return result;
166
- }
167
- /**
168
- * Sanitize an array.
169
- */
170
- function sanitizeArray(value, config, warnings, seen, depth) {
171
- const result = [];
172
- const limit = Math.min(value.length, config.maxArrayLength);
173
- for (let i = 0; i < limit; i++) {
174
- result.push(sanitizeValue(value[i], config, warnings, seen, depth + 1));
175
- }
176
- if (value.length > config.maxArrayLength) {
177
- warnings.push(`Array truncated: ${value.length} items reduced to ${config.maxArrayLength}`);
178
- }
179
- return result;
180
- }
181
- /**
182
- * Sanitize a plain object.
183
- */
184
- function sanitizeObject(value, config, warnings, seen, depth) {
185
- const result = {};
186
- const keys = Object.keys(value);
187
- const limit = Math.min(keys.length, config.maxObjectKeys);
188
- for (let i = 0; i < limit; i++) {
189
- const key = keys[i];
190
- // Skip prototype pollution vectors
191
- if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
192
- warnings.push(`Dangerous key "${key}" removed`);
193
- continue;
194
- }
195
- result[key] = sanitizeValue(value[key], config, warnings, seen, depth + 1);
196
- }
197
- if (keys.length > config.maxObjectKeys) {
198
- warnings.push(`Object truncated: ${keys.length} keys reduced to ${config.maxObjectKeys}`);
199
- }
200
- return result;
201
- }
202
- /**
203
- * Sanitize an Error object.
204
- */
205
- function sanitizeError(error, config, warnings) {
206
- const result = {
207
- name: error.name,
208
- message: sanitizeString(error.message, config, warnings),
209
- };
210
- // Include stack only if configured
211
- if (!config.removeStackTraces && error.stack) {
212
- result['stack'] = sanitizeString(error.stack, config, warnings);
213
- }
214
- else if (error.stack) {
215
- warnings.push('Stack trace removed');
216
- }
217
- // Include error code if present
218
- if ('code' in error) {
219
- result['code'] = error.code;
220
- }
221
- return result;
222
- }
223
- /**
224
- * Quick check if a value needs sanitization.
225
- * Used for optimization - skip sanitization for simple values.
226
- */
227
- function needsSanitization(value) {
228
- if (value === null || value === undefined) {
229
- return false;
230
- }
231
- if (typeof value === 'number' || typeof value === 'boolean') {
232
- return false;
233
- }
234
- if (typeof value === 'string') {
235
- // Quick heuristic: check if string might contain paths
236
- return value.length > 100 || value.includes('/') || value.includes('\\');
237
- }
238
- // Objects and arrays always need checking
239
- return true;
240
- }
241
- /**
242
- * Sanitize a log message (less aggressive than output sanitization).
243
- */
244
- function sanitizeLogMessage(message, maxLength = 500) {
245
- if (!message)
246
- return '';
247
- let result = message;
248
- // Remove file paths
249
- result = result.replace(/(?:\/[\w.-]+)+|(?:[A-Za-z]:\\[\w\\.-]+)+/g, '[path]');
250
- // Remove line numbers
251
- result = result.replace(/:\d+:\d+/g, '');
252
- // Remove stack trace lines
253
- result = result.replace(/\n\s*at .*/g, '');
254
- // Truncate
255
- if (result.length > maxLength) {
256
- result = result.substring(0, maxLength) + '...';
257
- }
258
- return result.trim();
259
- }
260
- //# sourceMappingURL=output-sanitizer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-sanitizer.js","sourceRoot":"","sources":["../../../../src/codecall/services/output-sanitizer.ts"],"names":[],"mappings":";AAAA,+DAA+D;;;AAgG/D,wCAoCC;AA6ND,8CAgBC;AAKD,gDAoBC;AA1UD;;GAEG;AACU,QAAA,wBAAwB,GAA0B,MAAM,CAAC,MAAM,CAAC;IAC3E,QAAQ,EAAE,EAAE;IACZ,eAAe,EAAE,KAAK;IACtB,aAAa,EAAE,GAAG;IAClB,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM;IACjC,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;CACtB,CAAC,CAAC;AAcH;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,MAAe,EACf,SAAyC,EAAE;IAE3C,MAAM,GAAG,GAAG,EAAE,GAAG,gCAAwB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,OAAO,EAAU,CAAC;IAEnC,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE7D,mBAAmB;IACnB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC;YACvD,QAAQ,CAAC,IAAI,CAAC,0C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AExB,IAAI,MAAM,GAAG,OAAO,CAAC;IAErB,oBAAoB;IACpB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,2CAA2C,EAAE,QAAQ,CAAC,CAAC;IAE/E,sBAAsB;IACtB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEzC,2BAA2B;IAC3B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAE3C,WAAW;IACX,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QAC9B,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/services/output-sanitizer.ts\n\n/**\n * Output Sanitizer for CodeCall\n *\n * Sanitizes script outputs to prevent information leakage through:\n * - Error messages with stack traces or file paths\n * - Large outputs that could contain sensitive data\n * - Recursive structures that could cause DoS\n *\n * Security considerations:\n * - All sanitization is defensive (fail-safe)\n * - Outputs are truncated, not rejected\n * - Circular references are handled\n * - Prototype pollution is prevented\n */\n\n/**\n * Configuration for output sanitization.\n */\nexport interface OutputSanitizerConfig {\n /**\n * Maximum depth for nested objects/arrays.\n * @default 10\n */\n maxDepth: number;\n\n /**\n * Maximum length for string values.\n * @default 10000\n */\n maxStringLength: number;\n\n /**\n * Maximum number of keys in an object.\n * @default 100\n */\n maxObjectKeys: number;\n\n /**\n * Maximum number of items in an array.\n * @default 1000\n */\n maxArrayLength: number;\n\n /**\n * Maximum total size of serialized output in bytes.\n * @default 1MB\n */\n maxTotalSize: number;\n\n /**\n * Remove error stack traces.\n * @default true\n */\n removeStackTraces: boolean;\n\n /**\n * Remove file paths from strings.\n * @default true\n */\n removeFilePaths: boolean;\n}\n\n/**\n * Default sanitization configuration.\n */\nexport const DEFAULT_SANITIZER_CONFIG: OutputSanitizerConfig = Object.freeze({\n maxDepth: 10,\n maxStringLength: 10000,\n maxObjectKeys: 100,\n maxArrayLength: 1000,\n maxTotalSize: 1024 * 1024, // 1MB\n removeStackTraces: true,\n removeFilePaths: true,\n});\n\n/**\n * Result of sanitization.\n */\nexport interface SanitizationResult<T> {\n /** Sanitized value */\n value: T;\n /** Whether any sanitization was applied */\n wasModified: boolean;\n /** Warnings about what was sanitized */\n warnings: string[];\n}\n\n/**\n * Sanitize output from CodeCall script execution.\n *\n * @param output - Raw output from script\n * @param config - Sanitization configuration\n * @returns Sanitized output with metadata\n */\nexport function sanitizeOutput<T = unknown>(\n output: unknown,\n config: Partial<OutputSanitizerConfig> = {},\n): SanitizationResult<T> {\n const cfg = { ...DEFAULT_SANITIZER_CONFIG, ...config };\n const warnings: string[] = [];\n const seen = new WeakSet<object>();\n\n const result = sanitizeValue(output, cfg, warnings, seen, 0);\n\n // Check total size\n try {\n const serialized = JSON.stringify(result);\n if (serialized && serialized.length > cfg.maxTotalSize) {\n warnings.push(`Output truncated: exceeded max size of ${cfg.maxTotalSize} bytes`);\n return {\n value: { _truncated: true, _reason: 'Output exceeded maximum size' } as T,\n wasModified: true,\n warnings,\n };\n }\n } catch {\n // If we can't serialize, return a safe placeholder\n warnings.push('Output could not be serialized');\n return {\n value: { _error: 'Output could not be serialized' } as T,\n wasModified: true,\n warnings,\n };\n }\n\n return {\n value: result as T,\n wasModified: warnings.length > 0,\n warnings,\n };\n}\n\n/**\n * Recursively sanitize a value.\n */\nfunction sanitizeValue(\n value: unknown,\n config: OutputSanitizerConfig,\n warnings: string[],\n seen: WeakSet<object>,\n depth: number,\n): unknown {\n // Check depth\n if (depth > config.maxDepth) {\n warnings.push(`Max depth of ${config.maxDepth} exceeded`);\n return '[max depth exceeded]';\n }\n\n // Handle null/undefined\n if (value === null || value === undefined) {\n return value;\n }\n\n // Handle primitives\n if (typeof value === 'string') {\n return sanitizeString(value, config, warnings);\n }\n\n if (typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n\n if (typeof value === 'bigint') {\n return value.toString();\n }\n\n if (typeof value === 'symbol') {\n return value.toString();\n }\n\n if (typeof value === 'function') {\n warnings.push('Function removed from output');\n return '[function]';\n }\n\n // Handle objects\n if (typeof value === 'object') {\n // Check for circular references\n if (seen.has(value)) {\n warnings.push('Circular reference detected');\n return '[circular]';\n }\n seen.add(value);\n\n // Handle arrays\n if (Array.isArray(value)) {\n return sanitizeArray(value, config, warnings, seen, depth);\n }\n\n // Handle Error objects\n if (value instanceof Error) {\n return sanitizeError(value, config, warnings);\n }\n\n // Handle Date objects\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n // Handle RegExp objects\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n // Handle Map\n if (value instanceof Map) {\n const obj: Record<string, unknown> = {};\n let count = 0;\n for (const [k, v] of value) {\n if (count >= config.maxObjectKeys) {\n warnings.push(`Map truncated: exceeded ${config.maxObjectKeys} keys`);\n break;\n }\n obj[String(k)] = sanitizeValue(v, config, warnings, seen, depth + 1);\n count++;\n }\n return obj;\n }\n\n // Handle Set\n if (value instanceof Set) {\n const arr: unknown[] = [];\n let count = 0;\n for (const item of value) {\n if (count >= config.maxArrayLength) {\n warnings.push(`Set truncated: exceeded ${config.maxArrayLength} items`);\n break;\n }\n arr.push(sanitizeValue(item, config, warnings, seen, depth + 1));\n count++;\n }\n return arr;\n }\n\n // Handle plain objects\n return sanitizeObject(value as Record<string, unknown>, config, warnings, seen, depth);\n }\n\n // Unknown type - return safe string representation\n return String(value);\n}\n\n/**\n * Sanitize a string value.\n */\nfunction sanitizeString(value: string, config: OutputSanitizerConfig, warnings: string[]): string {\n let result = value;\n\n // Remove file paths if configured\n if (config.removeFilePaths) {\n const pathRegex = /(?:\\/[\\w.-]+)+|(?:[A-Za-z]:\\\\[\\w\\\\.-]+)+/g;\n if (pathRegex.test(result)) {\n result = result.replace(pathRegex, '[path]');\n warnings.push('File paths removed from string');\n }\n }\n\n // Truncate if too long\n if (result.length > config.maxStringLength) {\n result = result.substring(0, config.maxStringLength) + '...[truncated]';\n warnings.push(`String truncated: exceeded ${config.maxStringLength} characters`);\n }\n\n return result;\n}\n\n/**\n * Sanitize an array.\n */\nfunction sanitizeArray(\n value: unknown[],\n config: OutputSanitizerConfig,\n warnings: string[],\n seen: WeakSet<object>,\n depth: number,\n): unknown[] {\n const result: unknown[] = [];\n const limit = Math.min(value.length, config.maxArrayLength);\n\n for (let i = 0; i < limit; i++) {\n result.push(sanitizeValue(value[i], config, warnings, seen, depth + 1));\n }\n\n if (value.length > config.maxArrayLength) {\n warnings.push(`Array truncated: ${value.length} items reduced to ${config.maxArrayLength}`);\n }\n\n return result;\n}\n\n/**\n * Sanitize a plain object.\n */\nfunction sanitizeObject(\n value: Record<string, unknown>,\n config: OutputSanitizerConfig,\n warnings: string[],\n seen: WeakSet<object>,\n depth: number,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n const keys = Object.keys(value);\n const limit = Math.min(keys.length, config.maxObjectKeys);\n\n for (let i = 0; i < limit; i++) {\n const key = keys[i];\n\n // Skip prototype pollution vectors\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n warnings.push(`Dangerous key \"${key}\" removed`);\n continue;\n }\n\n result[key] = sanitizeValue(value[key], config, warnings, seen, depth + 1);\n }\n\n if (keys.length > config.maxObjectKeys) {\n warnings.push(`Object truncated: ${keys.length} keys reduced to ${config.maxObjectKeys}`);\n }\n\n return result;\n}\n\n/**\n * Sanitize an Error object.\n */\nfunction sanitizeError(error: Error, config: OutputSanitizerConfig, warnings: string[]): Record<string, unknown> {\n const result: Record<string, unknown> = {\n name: error.name,\n message: sanitizeString(error.message, config, warnings),\n };\n\n // Include stack only if configured\n if (!config.removeStackTraces && error.stack) {\n result['stack'] = sanitizeString(error.stack, config, warnings);\n } else if (error.stack) {\n warnings.push('Stack trace removed');\n }\n\n // Include error code if present\n if ('code' in error) {\n result['code'] = (error as any).code;\n }\n\n return result;\n}\n\n/**\n * Quick check if a value needs sanitization.\n * Used for optimization - skip sanitization for simple values.\n */\nexport function needsSanitization(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n\n if (typeof value === 'number' || typeof value === 'boolean') {\n return false;\n }\n\n if (typeof value === 'string') {\n // Quick heuristic: check if string might contain paths\n return value.length > 100 || value.includes('/') || value.includes('\\\\');\n }\n\n // Objects and arrays always need checking\n return true;\n}\n\n/**\n * Sanitize a log message (less aggressive than output sanitization).\n */\nexport function sanitizeLogMessage(message: string, maxLength = 500): string {\n if (!message) return '';\n\n let result = message;\n\n // Remove file paths\n result = result.replace(/(?:\\/[\\w.-]+)+|(?:[A-Za-z]:\\\\[\\w\\\\.-]+)+/g, '[path]');\n\n // Remove line numbers\n result = result.replace(/:\\d+:\\d+/g, '');\n\n // Remove stack trace lines\n result = result.replace(/\\n\\s*at .*/g, '');\n\n // Truncate\n if (result.length > maxLength) {\n result = result.substring(0, maxLength) + '...';\n }\n\n return result.trim();\n}\n"]}
@@ -1,374 +0,0 @@
1
- "use strict";
2
- // file: libs/plugins/src/codecall/services/synonym-expansion.service.ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.SynonymExpansionService = void 0;
5
- /**
6
- * Universal Synonym groups for MCP Tool searching.
7
- *
8
- * DESIGN PRINCIPLE:
9
- * These groups bridge the gap between "User Intent" (Natural Language)
10
- * and "System Function" (API/Tool Names).
11
- *
12
- * STRUCTURE:
13
- * 1. Core Data Operations (CRUD+)
14
- * 2. State & Lifecycle
15
- * 3. Transfer & IO
16
- * 4. DevOps & Technical
17
- * 5. Commerce & Business Logic
18
- * 6. Communication & Social
19
- * 7. Universal Entities (Nouns)
20
- */
21
- const DEFAULT_SYNONYM_GROUPS = [
22
- // ===========================================================================
23
- // 1. CORE DATA OPERATIONS (CRUD+)
24
- // ===========================================================================
25
- // Creation / Instantiation
26
- [
27
- 'create',
28
- 'add',
29
- 'new',
30
- 'insert',
31
- 'make',
32
- 'append',
33
- 'register',
34
- 'generate',
35
- 'produce',
36
- 'build',
37
- 'construct',
38
- 'provision',
39
- 'instantiate',
40
- 'define',
41
- 'compose',
42
- 'draft',
43
- ],
44
- // Destructive Removal
45
- [
46
- 'delete',
47
- 'remove',
48
- 'destroy',
49
- 'drop',
50
- 'erase',
51
- 'clear',
52
- 'purge',
53
- 'discard',
54
- 'eliminate',
55
- 'nuke',
56
- 'unbind',
57
- 'unregister',
58
- ],
59
- // Retrieval / Access
60
- ['get', 'fetch', 'retrieve', 'read', 'obtain', 'load', 'pull', 'access', 'grab', 'snag', 'receive'],
61
- // Modification
62
- [
63
- 'update',
64
- 'edit',
65
- 'modify',
66
- 'change',
67
- 'patch',
68
- 'alter',
69
- 'revise',
70
- 'refresh',
71
- 'correct',
72
- 'amend',
73
- 'adjust',
74
- 'tweak',
75
- 'rectify',
76
- 'refine',
77
- ],
78
- // Viewing / Listing
79
- [
80
- 'list',
81
- 'show',
82
- 'display',
83
- 'enumerate',
84
- 'browse',
85
- 'view',
86
- 'peek',
87
- 'index',
88
- 'catalog',
89
- 'survey',
90
- 'inspect',
91
- 'ls',
92
- 'dir',
93
- ],
94
- // Searching / Discovery
95
- [
96
- 'find',
97
- 'search',
98
- 'lookup',
99
- 'query',
100
- 'locate',
101
- 'filter',
102
- 'scan',
103
- 'explore',
104
- 'investigate',
105
- 'detect',
106
- 'scout',
107
- 'seek',
108
- ],
109
- // Soft Delete / Archival
110
- ['archive', 'shelve', 'retire', 'hide', 'suppress', 'mute'],
111
- ['unarchive', 'restore', 'recover', 'undelete', 'unhide'],
112
- // ===========================================================================
113
- // 2. STATE & LIFECYCLE
114
- // ===========================================================================
115
- // Activation
116
- [
117
- 'enable',
118
- 'activate',
119
- 'start',
120
- 'turn on',
121
- 'switch on',
122
- 'boot',
123
- 'init',
124
- 'initialize',
125
- 'setup',
126
- 'spin up',
127
- 'resume',
128
- 'unpause',
129
- ],
130
- // Deactivation
131
- [
132
- 'disable',
133
- 'deactivate',
134
- 'stop',
135
- 'turn off',
136
- 'switch off',
137
- 'shutdown',
138
- 'halt',
139
- 'kill',
140
- 'terminate',
141
- 'suspend',
142
- 'pause',
143
- 'cease',
144
- ],
145
- // Execution
146
- ['run', 'execute', 'invoke', 'trigger', 'launch', 'call', 'perform', 'operate', 'handle', 'process', 'fire'],
147
- // Reset cycles
148
- ['restart', 'reboot', 'reset', 'reload', 'bounce', 'recycle', 'refresh'],
149
- // Validation & Check
150
- ['validate', 'verify', 'check', 'confirm', 'assert', 'test', 'audit', 'assess', 'healthcheck', 'ping'],
151
- // Analysis & Math
152
- [
153
- 'analyze',
154
- 'interpret',
155
- 'diagnose',
156
- 'evaluate',
157
- 'review',
158
- 'summarize',
159
- 'count',
160
- 'calculate',
161
- 'compute',
162
- 'measure',
163
- 'aggregate',
164
- 'summarise',
165
- ],
166
- // ===========================================================================
167
- // 3. TRANSFER, IO & MANIPULATION
168
- // ===========================================================================
169
- // Duplication
170
- ['copy', 'duplicate', 'clone', 'replicate', 'mirror', 'fork', 'repro'],
171
- // Movement
172
- ['move', 'transfer', 'migrate', 'relocate', 'rename', 'shift', 'mv', 'slide'],
173
- // Persistence
174
- ['save', 'store', 'write', 'persist', 'commit', 'stash', 'record', 'log'],
175
- // Synchronization
176
- ['sync', 'synchronize', 'resync', 'reconcile', 'align', 'pair'],
177
- // Import/Export
178
- ['import', 'ingest', 'upload', 'push', 'feed'],
179
- ['export', 'download', 'dump', 'backup', 'extract'],
180
- // Connection
181
- ['connect', 'link', 'bind', 'attach', 'join', 'bridge', 'associate', 'mount', 'map'],
182
- ['disconnect', 'unlink', 'unbind', 'detach', 'leave', 'dissociate', 'unmount', 'unmap'],
183
- // ===========================================================================
184
- // 4. DEVOPS, SECURITY & TECHNICAL
185
- // ===========================================================================
186
- // Auth
187
- ['login', 'log in', 'sign in', 'authenticate', 'auth'],
188
- ['logout', 'log out', 'sign out', 'disconnect'],
189
- // Permissions
190
- ['approve', 'authorize', 'grant', 'permit', 'allow', 'sanction', 'whitelist'],
191
- ['deny', 'reject', 'revoke', 'forbid', 'block', 'ban', 'blacklist'],
192
- // Encryption
193
- ['encrypt', 'secure', 'lock', 'seal', 'protect', 'scramble', 'hash'],
194
- ['decrypt', 'unlock', 'unseal', 'reveal', 'decode'],
195
- // Deployment
196
- ['deploy', 'release', 'ship', 'publish', 'roll out', 'promote', 'distribute', 'install'],
197
- // Development
198
- ['debug', 'troubleshoot', 'fix', 'repair', 'resolve', 'trace'],
199
- ['compile', 'transpile', 'build', 'assemble', 'package', 'bundle', 'minify'],
200
- // ===========================================================================
201
- // 5. COMMERCE & BUSINESS LOGIC
202
- // ===========================================================================
203
- // Financial Transactions
204
- ['buy', 'purchase', 'order', 'pay', 'checkout', 'spend'],
205
- ['sell', 'refund', 'reimburse', 'charge', 'invoice', 'bill'],
206
- ['subscribe', 'upgrade', 'upsell'],
207
- ['unsubscribe', 'cancel', 'downgrade'],
208
- // Scheduling
209
- ['schedule', 'book', 'appoint', 'reserve', 'plan', 'calendar'],
210
- ['reschedule', 'postpone', 'delay', 'defer'],
211
- // ===========================================================================
212
- // 6. COMMUNICATION & SOCIAL
213
- // ===========================================================================
214
- // Outbound
215
- [
216
- 'send',
217
- 'dispatch',
218
- 'deliver',
219
- 'transmit',
220
- 'post',
221
- 'broadcast',
222
- 'notify',
223
- 'alert',
224
- 'email',
225
- 'text',
226
- 'message',
227
- 'chat',
228
- ],
229
- // Social Interactions
230
- ['reply', 'respond', 'answer', 'retort'],
231
- ['share', 'forward', 'retweet', 'repost'],
232
- ['like', 'favorite', 'star', 'upvote', 'heart'],
233
- ['dislike', 'downvote'],
234
- ['follow', 'watch', 'track'],
235
- ['unfollow', 'ignore', 'mute'],
236
- // ===========================================================================
237
- // 7. COMMON ENTITIES (NOUNS)
238
- // ===========================================================================
239
- // Users & Roles
240
- [
241
- 'user',
242
- 'account',
243
- 'member',
244
- 'profile',
245
- 'identity',
246
- 'customer',
247
- 'principal',
248
- 'admin',
249
- 'operator',
250
- 'client',
251
- 'employee',
252
- 'staff',
253
- ],
254
- ['role', 'group', 'team', 'squad', 'unit', 'department'],
255
- // Data Artifacts
256
- ['file', 'document', 'attachment', 'blob', 'asset', 'object', 'resource', 'content', 'media'],
257
- ['image', 'picture', 'photo', 'screenshot'],
258
- ['video', 'clip', 'recording', 'footage'],
259
- // System Artifacts
260
- ['message', 'notification', 'alert', 'event', 'signal', 'webhook', 'ping'],
261
- ['log', 'trace', 'metric', 'telemetry', 'audit trail', 'history'],
262
- ['settings', 'config', 'configuration', 'preferences', 'options', 'params', 'env', 'environment', 'variables'],
263
- ['permission', 'privilege', 'access right', 'policy', 'rule', 'scope'],
264
- // Business Artifacts
265
- ['organization', 'company', 'tenant', 'workspace', 'org', 'project', 'repo', 'repository'],
266
- ['product', 'item', 'sku', 'inventory', 'stock'],
267
- ['task', 'ticket', 'issue', 'bug', 'story', 'epic', 'todo', 'job', 'workitem'],
268
- // Identification
269
- ['id', 'identifier', 'key', 'uuid', 'guid', 'token', 'hash', 'fingerprint'],
270
- ];
271
- /**
272
- * Lightweight synonym expansion service for improving TF-IDF search relevance.
273
- * Zero dependencies, synchronous, and easily extensible.
274
- *
275
- * This service provides query-time synonym expansion to help TF-IDF-based
276
- * search understand that semantically similar terms (like "add" and "create")
277
- * should match the same tools.
278
- */
279
- class SynonymExpansionService {
280
- synonymMap;
281
- maxExpansions;
282
- constructor(config = {}) {
283
- this.maxExpansions = config.maxExpansionsPerTerm ?? 5;
284
- // Build synonym map from groups
285
- const groups = config.replaceDefaults
286
- ? config.additionalSynonyms || []
287
- : [...DEFAULT_SYNONYM_GROUPS, ...(config.additionalSynonyms || [])];
288
- this.synonymMap = this.buildSynonymMap(groups);
289
- }
290
- /**
291
- * Build a bidirectional synonym map from groups.
292
- * Each term maps to all other terms in its group(s).
293
- */
294
- buildSynonymMap(groups) {
295
- const map = new Map();
296
- for (const group of groups) {
297
- const normalizedGroup = group.map((term) => term.toLowerCase());
298
- for (const term of normalizedGroup) {
299
- if (!map.has(term)) {
300
- map.set(term, new Set());
301
- }
302
- const synonyms = map.get(term);
303
- // Add all other terms in the group as synonyms
304
- for (const synonym of normalizedGroup) {
305
- if (synonym !== term) {
306
- synonyms.add(synonym);
307
- }
308
- }
309
- }
310
- }
311
- return map;
312
- }
313
- /**
314
- * Get synonyms for a single term.
315
- * Returns empty array if no synonyms found.
316
- *
317
- * @example
318
- * getSynonyms('add') // ['create', 'new', 'insert', 'make']
319
- */
320
- getSynonyms(term) {
321
- const normalized = term.toLowerCase();
322
- const synonyms = this.synonymMap.get(normalized);
323
- if (!synonyms) {
324
- return [];
325
- }
326
- // Return limited synonyms to prevent query explosion
327
- return Array.from(synonyms).slice(0, this.maxExpansions);
328
- }
329
- /**
330
- * Expand a query string by adding synonyms for each term.
331
- * Returns the expanded query string with original terms and their synonyms.
332
- *
333
- * @example
334
- * expandQuery('add user') // 'add create new insert make user account member profile'
335
- */
336
- expandQuery(query) {
337
- const terms = query
338
- .toLowerCase()
339
- .split(/\s+/)
340
- .filter((term) => term.length > 1);
341
- const expandedTerms = [];
342
- for (const term of terms) {
343
- // Always include the original term first
344
- expandedTerms.push(term);
345
- // Add synonyms
346
- const synonyms = this.getSynonyms(term);
347
- expandedTerms.push(...synonyms);
348
- }
349
- return expandedTerms.join(' ');
350
- }
351
- /**
352
- * Check if synonym expansion is available for any term in the query.
353
- */
354
- hasExpansions(query) {
355
- const terms = query.toLowerCase().split(/\s+/);
356
- return terms.some((term) => this.synonymMap.has(term));
357
- }
358
- /**
359
- * Get statistics about the synonym dictionary.
360
- */
361
- getStats() {
362
- const termCount = this.synonymMap.size;
363
- let totalSynonyms = 0;
364
- for (const synonyms of this.synonymMap.values()) {
365
- totalSynonyms += synonyms.size;
366
- }
367
- return {
368
- termCount,
369
- avgSynonymsPerTerm: termCount > 0 ? totalSynonyms / termCount : 0,
370
- };
371
- }
372
- }
373
- exports.SynonymExpansionService = SynonymExpansionService;
374
- //# sourceMappingURL=synonym-expansion.service.js.map