driftdetect-mcp 0.6.1 → 0.7.1

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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin/server.js +0 -0
  3. package/dist/enterprise-server.d.ts +1 -0
  4. package/dist/enterprise-server.d.ts.map +1 -1
  5. package/dist/enterprise-server.js +8 -1
  6. package/dist/enterprise-server.js.map +1 -1
  7. package/dist/tools/analysis/constants.d.ts +99 -0
  8. package/dist/tools/analysis/constants.d.ts.map +1 -0
  9. package/dist/tools/analysis/constants.js +421 -0
  10. package/dist/tools/analysis/constants.js.map +1 -0
  11. package/dist/tools/analysis/index.d.ts +1 -0
  12. package/dist/tools/analysis/index.d.ts.map +1 -1
  13. package/dist/tools/analysis/index.js +70 -0
  14. package/dist/tools/analysis/index.js.map +1 -1
  15. package/dist/tools/exploration/env.d.ts +53 -0
  16. package/dist/tools/exploration/env.d.ts.map +1 -0
  17. package/dist/tools/exploration/env.js +283 -0
  18. package/dist/tools/exploration/env.js.map +1 -0
  19. package/dist/tools/exploration/index.d.ts +2 -0
  20. package/dist/tools/exploration/index.d.ts.map +1 -1
  21. package/dist/tools/exploration/index.js +32 -0
  22. package/dist/tools/exploration/index.js.map +1 -1
  23. package/dist/tools/index.d.ts +6 -1
  24. package/dist/tools/index.d.ts.map +1 -1
  25. package/dist/tools/index.js +6 -1
  26. package/dist/tools/index.js.map +1 -1
  27. package/dist/tools/registry.d.ts +7 -5
  28. package/dist/tools/registry.d.ts.map +1 -1
  29. package/dist/tools/registry.js +10 -4
  30. package/dist/tools/registry.js.map +1 -1
  31. package/dist/tools/surgical/callers.d.ts +85 -0
  32. package/dist/tools/surgical/callers.d.ts.map +1 -0
  33. package/dist/tools/surgical/callers.js +239 -0
  34. package/dist/tools/surgical/callers.js.map +1 -0
  35. package/dist/tools/surgical/dependencies.d.ts +96 -0
  36. package/dist/tools/surgical/dependencies.d.ts.map +1 -0
  37. package/dist/tools/surgical/dependencies.js +433 -0
  38. package/dist/tools/surgical/dependencies.js.map +1 -0
  39. package/dist/tools/surgical/errors.d.ts +88 -0
  40. package/dist/tools/surgical/errors.d.ts.map +1 -0
  41. package/dist/tools/surgical/errors.js +275 -0
  42. package/dist/tools/surgical/errors.js.map +1 -0
  43. package/dist/tools/surgical/hooks.d.ts +69 -0
  44. package/dist/tools/surgical/hooks.d.ts.map +1 -0
  45. package/dist/tools/surgical/hooks.js +247 -0
  46. package/dist/tools/surgical/hooks.js.map +1 -0
  47. package/dist/tools/surgical/imports.d.ts +61 -0
  48. package/dist/tools/surgical/imports.d.ts.map +1 -0
  49. package/dist/tools/surgical/imports.js +211 -0
  50. package/dist/tools/surgical/imports.js.map +1 -0
  51. package/dist/tools/surgical/index.d.ts +42 -0
  52. package/dist/tools/surgical/index.d.ts.map +1 -0
  53. package/dist/tools/surgical/index.js +66 -0
  54. package/dist/tools/surgical/index.js.map +1 -0
  55. package/dist/tools/surgical/middleware.d.ts +69 -0
  56. package/dist/tools/surgical/middleware.d.ts.map +1 -0
  57. package/dist/tools/surgical/middleware.js +237 -0
  58. package/dist/tools/surgical/middleware.js.map +1 -0
  59. package/dist/tools/surgical/prevalidate.d.ts +76 -0
  60. package/dist/tools/surgical/prevalidate.d.ts.map +1 -0
  61. package/dist/tools/surgical/prevalidate.js +303 -0
  62. package/dist/tools/surgical/prevalidate.js.map +1 -0
  63. package/dist/tools/surgical/recent.d.ts +66 -0
  64. package/dist/tools/surgical/recent.d.ts.map +1 -0
  65. package/dist/tools/surgical/recent.js +238 -0
  66. package/dist/tools/surgical/recent.js.map +1 -0
  67. package/dist/tools/surgical/signature.d.ts +73 -0
  68. package/dist/tools/surgical/signature.d.ts.map +1 -0
  69. package/dist/tools/surgical/signature.js +190 -0
  70. package/dist/tools/surgical/signature.js.map +1 -0
  71. package/dist/tools/surgical/similar.d.ts +77 -0
  72. package/dist/tools/surgical/similar.d.ts.map +1 -0
  73. package/dist/tools/surgical/similar.js +285 -0
  74. package/dist/tools/surgical/similar.js.map +1 -0
  75. package/dist/tools/surgical/test-template.d.ts +70 -0
  76. package/dist/tools/surgical/test-template.d.ts.map +1 -0
  77. package/dist/tools/surgical/test-template.js +298 -0
  78. package/dist/tools/surgical/test-template.js.map +1 -0
  79. package/dist/tools/surgical/type.d.ts +69 -0
  80. package/dist/tools/surgical/type.d.ts.map +1 -0
  81. package/dist/tools/surgical/type.js +289 -0
  82. package/dist/tools/surgical/type.js.map +1 -0
  83. package/package.json +11 -11
@@ -0,0 +1,61 @@
1
+ /**
2
+ * drift_imports - Resolve Correct Imports
3
+ *
4
+ * Layer: Surgical
5
+ * Token Budget: 300 target, 600 max
6
+ * Cache TTL: 5 minutes
7
+ * Invalidation Keys: callgraph, file:{targetFile}
8
+ *
9
+ * Resolves correct import statements based on codebase conventions.
10
+ * Solves: Every codebase has different import conventions. AI guesses wrong.
11
+ */
12
+ import type { CallGraphStore } from 'driftdetect-core';
13
+ export interface ImportsArgs {
14
+ /** Symbols that need to be imported */
15
+ symbols: string[];
16
+ /** File where imports will be added */
17
+ targetFile: string;
18
+ }
19
+ export interface ImportConventions {
20
+ style: 'barrel' | 'deep' | 'mixed';
21
+ pathStyle: 'relative' | 'alias' | 'absolute';
22
+ alias?: string;
23
+ preferNamed: boolean;
24
+ preferType: boolean;
25
+ }
26
+ export interface ImportsData {
27
+ imports: string[];
28
+ unresolved: string[];
29
+ conventions: ImportConventions;
30
+ }
31
+ export declare function handleImports(store: CallGraphStore, args: ImportsArgs): Promise<{
32
+ content: Array<{
33
+ type: string;
34
+ text: string;
35
+ }>;
36
+ }>;
37
+ /**
38
+ * Tool definition for MCP registration
39
+ */
40
+ export declare const importsToolDefinition: {
41
+ name: string;
42
+ description: string;
43
+ inputSchema: {
44
+ type: "object";
45
+ properties: {
46
+ symbols: {
47
+ type: string;
48
+ items: {
49
+ type: string;
50
+ };
51
+ description: string;
52
+ };
53
+ targetFile: {
54
+ type: string;
55
+ description: string;
56
+ };
57
+ };
58
+ required: string[];
59
+ };
60
+ };
61
+ //# sourceMappingURL=imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../src/tools/surgical/imports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,kBAAkB,CAAC;AAQrE,MAAM,WAAW,WAAW;IAC1B,uCAAuC;IACvC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IACnC,SAAS,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,iBAAiB,CAAC;CAChC;AAMD,wBAAsB,aAAa,CACjC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA6G7D;AA0GD;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;CAkBjC,CAAC"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * drift_imports - Resolve Correct Imports
3
+ *
4
+ * Layer: Surgical
5
+ * Token Budget: 300 target, 600 max
6
+ * Cache TTL: 5 minutes
7
+ * Invalidation Keys: callgraph, file:{targetFile}
8
+ *
9
+ * Resolves correct import statements based on codebase conventions.
10
+ * Solves: Every codebase has different import conventions. AI guesses wrong.
11
+ */
12
+ import { createResponseBuilder, Errors, metrics } from '../../infrastructure/index.js';
13
+ import * as path from 'node:path';
14
+ // ============================================================================
15
+ // Handler
16
+ // ============================================================================
17
+ export async function handleImports(store, args) {
18
+ const startTime = Date.now();
19
+ const builder = createResponseBuilder();
20
+ // Validate input
21
+ if (!args.symbols || args.symbols.length === 0) {
22
+ throw Errors.missingParameter('symbols');
23
+ }
24
+ if (!args.targetFile) {
25
+ throw Errors.missingParameter('targetFile');
26
+ }
27
+ const symbols = args.symbols.map(s => s.trim()).filter(s => s.length > 0);
28
+ const targetFile = args.targetFile;
29
+ // Load call graph
30
+ await store.initialize();
31
+ const graph = store.getGraph();
32
+ if (!graph) {
33
+ throw Errors.custom('CALLGRAPH_NOT_BUILT', 'Call graph has not been built. Run "drift callgraph build" first.', ['drift_status']);
34
+ }
35
+ // Analyze existing import conventions in the codebase
36
+ const conventions = analyzeImportConventions(graph);
37
+ // Find where each symbol is exported
38
+ const symbolSources = new Map();
39
+ for (const [, func] of graph.functions) {
40
+ if (func.isExported) {
41
+ // Check if this function matches any requested symbol
42
+ for (const symbol of symbols) {
43
+ if (func.name === symbol || func.qualifiedName.endsWith(`.${symbol}`)) {
44
+ symbolSources.set(symbol, {
45
+ file: func.file,
46
+ isDefault: false, // Functions are typically named exports
47
+ isType: false,
48
+ });
49
+ }
50
+ }
51
+ }
52
+ }
53
+ // Build import statements
54
+ const imports = [];
55
+ const unresolved = [];
56
+ // Group symbols by source file
57
+ const bySource = new Map();
58
+ for (const symbol of symbols) {
59
+ const source = symbolSources.get(symbol);
60
+ if (source) {
61
+ const existing = bySource.get(source.file) ?? [];
62
+ existing.push(symbol);
63
+ bySource.set(source.file, existing);
64
+ }
65
+ else {
66
+ unresolved.push(symbol);
67
+ }
68
+ }
69
+ // Generate import statements
70
+ for (const [sourceFile, syms] of bySource) {
71
+ const importPath = resolveImportPath(sourceFile, targetFile, conventions);
72
+ const importStatement = buildImportStatement(syms, importPath, conventions);
73
+ imports.push(importStatement);
74
+ }
75
+ const data = {
76
+ imports,
77
+ unresolved,
78
+ conventions,
79
+ };
80
+ // Build summary
81
+ let summary;
82
+ if (imports.length === 0 && unresolved.length > 0) {
83
+ summary = `Could not resolve imports for: ${unresolved.join(', ')}`;
84
+ }
85
+ else if (unresolved.length > 0) {
86
+ summary = `Generated ${imports.length} import${imports.length !== 1 ? 's' : ''}, ${unresolved.length} unresolved`;
87
+ }
88
+ else {
89
+ summary = `Generated ${imports.length} import${imports.length !== 1 ? 's' : ''} for ${symbols.length} symbol${symbols.length !== 1 ? 's' : ''}`;
90
+ }
91
+ // Build hints
92
+ const hints = {
93
+ nextActions: imports.length > 0
94
+ ? ['Copy imports to your file', 'Use drift_prevalidate to check your code']
95
+ : ['Use drift_signature to find the correct symbol name', 'Check if the symbol exists in the codebase'],
96
+ relatedTools: ['drift_signature', 'drift_prevalidate', 'drift_similar'],
97
+ };
98
+ if (unresolved.length > 0) {
99
+ hints.warnings = [`Could not find exports for: ${unresolved.join(', ')}`];
100
+ }
101
+ // Record metrics
102
+ metrics.recordRequest('drift_imports', Date.now() - startTime, true, false);
103
+ return builder
104
+ .withSummary(summary)
105
+ .withData(data)
106
+ .withHints(hints)
107
+ .buildContent();
108
+ }
109
+ // ============================================================================
110
+ // Helpers
111
+ // ============================================================================
112
+ /**
113
+ * Analyze import conventions from the codebase
114
+ */
115
+ function analyzeImportConventions(graph) {
116
+ // Default conventions (TypeScript-style)
117
+ const conventions = {
118
+ style: 'mixed',
119
+ pathStyle: 'relative',
120
+ preferNamed: true,
121
+ preferType: true,
122
+ };
123
+ // Look for path alias patterns in file paths
124
+ for (const [, func] of graph.functions) {
125
+ // Check for common alias patterns
126
+ if (func.file.includes('@/') || func.file.includes('~/')) {
127
+ conventions.pathStyle = 'alias';
128
+ conventions.alias = func.file.includes('@/') ? '@/' : '~/';
129
+ break;
130
+ }
131
+ }
132
+ // Check for barrel file patterns (index.ts exports)
133
+ let barrelCount = 0;
134
+ let deepCount = 0;
135
+ for (const [, func] of graph.functions) {
136
+ if (func.file.endsWith('index.ts') || func.file.endsWith('index.js')) {
137
+ barrelCount++;
138
+ }
139
+ else {
140
+ deepCount++;
141
+ }
142
+ }
143
+ if (barrelCount > deepCount * 0.3) {
144
+ conventions.style = 'barrel';
145
+ }
146
+ else if (barrelCount < deepCount * 0.1) {
147
+ conventions.style = 'deep';
148
+ }
149
+ return conventions;
150
+ }
151
+ /**
152
+ * Resolve the import path from target to source
153
+ */
154
+ function resolveImportPath(sourceFile, targetFile, conventions) {
155
+ // If using alias, try to use it
156
+ if (conventions.pathStyle === 'alias' && conventions.alias) {
157
+ // Assume src/ is the alias root
158
+ if (sourceFile.includes('/src/')) {
159
+ const srcIndex = sourceFile.indexOf('/src/');
160
+ return conventions.alias + sourceFile.slice(srcIndex + 5).replace(/\.(ts|js|tsx|jsx)$/, '');
161
+ }
162
+ }
163
+ // Calculate relative path
164
+ const targetDir = path.dirname(targetFile);
165
+ let relativePath = path.relative(targetDir, sourceFile);
166
+ // Ensure it starts with ./ or ../
167
+ if (!relativePath.startsWith('.')) {
168
+ relativePath = './' + relativePath;
169
+ }
170
+ // Remove extension
171
+ relativePath = relativePath.replace(/\.(ts|js|tsx|jsx)$/, '');
172
+ // If barrel style and path ends with /index, remove it
173
+ if (conventions.style === 'barrel' && relativePath.endsWith('/index')) {
174
+ relativePath = relativePath.slice(0, -6);
175
+ }
176
+ return relativePath;
177
+ }
178
+ /**
179
+ * Build an import statement
180
+ */
181
+ function buildImportStatement(symbols, importPath, conventions) {
182
+ // For now, always use named imports
183
+ const symbolList = symbols.join(', ');
184
+ // Use type import if conventions prefer it and all symbols look like types
185
+ const allTypes = symbols.every(s => /^[A-Z]/.test(s) && !s.includes('create') && !s.includes('use'));
186
+ const typePrefix = conventions.preferType && allTypes ? 'type ' : '';
187
+ return `import ${typePrefix}{ ${symbolList} } from '${importPath}';`;
188
+ }
189
+ /**
190
+ * Tool definition for MCP registration
191
+ */
192
+ export const importsToolDefinition = {
193
+ name: 'drift_imports',
194
+ description: 'Resolve correct import statements based on codebase conventions. Returns ready-to-use import statements and detected conventions (barrel vs deep, alias vs relative).',
195
+ inputSchema: {
196
+ type: 'object',
197
+ properties: {
198
+ symbols: {
199
+ type: 'array',
200
+ items: { type: 'string' },
201
+ description: 'Symbols that need to be imported',
202
+ },
203
+ targetFile: {
204
+ type: 'string',
205
+ description: 'File where imports will be added (relative path)',
206
+ },
207
+ },
208
+ required: ['symbols', 'targetFile'],
209
+ },
210
+ };
211
+ //# sourceMappingURL=imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.js","sourceRoot":"","sources":["../../../src/tools/surgical/imports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AA2BlC,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAqB,EACrB,IAAiB;IAEjB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,qBAAqB,EAAe,CAAC;IAErD,iBAAiB;IACjB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/C,MAAM,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACrB,MAAM,MAAM,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM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,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACrG,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,IAAI,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAErE,OAAO,UAAU,UAAU,KAAK,UAAU,YAAY,UAAU,IAAI,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,uKAAuK;IACpL,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACzB,WAAW,EAAE,kCAAkC;aAChD;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,kDAAkD;aAChE;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC;KACpC;CACF,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Surgical Tools
3
+ *
4
+ * Ultra-focused, minimal-token tools for AI coding assistants.
5
+ * These tools provide surgical access to codebase intelligence,
6
+ * returning exactly what's needed for code generation.
7
+ *
8
+ * Layer: Surgical (between Orchestration and Detail)
9
+ * Token Budget: 200-500 target, 1000 max
10
+ *
11
+ * Tools:
12
+ * - drift_signature: Get function signatures without reading files
13
+ * - drift_callers: Lightweight "who calls this" lookup
14
+ * - drift_imports: Resolve correct import statements
15
+ * - drift_prevalidate: Validate code before writing
16
+ * - drift_similar: Find semantically similar code
17
+ * - drift_type: Expand type definitions
18
+ * - drift_recent: Show recent changes in area
19
+ * - drift_test_template: Generate test scaffolding
20
+ * - drift_dependencies: Package dependencies lookup (multi-language)
21
+ * - drift_middleware: Middleware pattern lookup
22
+ * - drift_hooks: React/Vue hooks lookup
23
+ * - drift_errors: Error types and handling gaps
24
+ */
25
+ import type { Tool } from '@modelcontextprotocol/sdk/types.js';
26
+ export * from './signature.js';
27
+ export * from './callers.js';
28
+ export * from './imports.js';
29
+ export * from './prevalidate.js';
30
+ export * from './similar.js';
31
+ export * from './type.js';
32
+ export * from './recent.js';
33
+ export * from './test-template.js';
34
+ export * from './dependencies.js';
35
+ export * from './middleware.js';
36
+ export * from './hooks.js';
37
+ export * from './errors.js';
38
+ /**
39
+ * All surgical tools
40
+ */
41
+ export declare const SURGICAL_TOOLS: Tool[];
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/surgical/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE/D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAe5B;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,IAAI,EAahC,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Surgical Tools
3
+ *
4
+ * Ultra-focused, minimal-token tools for AI coding assistants.
5
+ * These tools provide surgical access to codebase intelligence,
6
+ * returning exactly what's needed for code generation.
7
+ *
8
+ * Layer: Surgical (between Orchestration and Detail)
9
+ * Token Budget: 200-500 target, 1000 max
10
+ *
11
+ * Tools:
12
+ * - drift_signature: Get function signatures without reading files
13
+ * - drift_callers: Lightweight "who calls this" lookup
14
+ * - drift_imports: Resolve correct import statements
15
+ * - drift_prevalidate: Validate code before writing
16
+ * - drift_similar: Find semantically similar code
17
+ * - drift_type: Expand type definitions
18
+ * - drift_recent: Show recent changes in area
19
+ * - drift_test_template: Generate test scaffolding
20
+ * - drift_dependencies: Package dependencies lookup (multi-language)
21
+ * - drift_middleware: Middleware pattern lookup
22
+ * - drift_hooks: React/Vue hooks lookup
23
+ * - drift_errors: Error types and handling gaps
24
+ */
25
+ export * from './signature.js';
26
+ export * from './callers.js';
27
+ export * from './imports.js';
28
+ export * from './prevalidate.js';
29
+ export * from './similar.js';
30
+ export * from './type.js';
31
+ export * from './recent.js';
32
+ export * from './test-template.js';
33
+ export * from './dependencies.js';
34
+ export * from './middleware.js';
35
+ export * from './hooks.js';
36
+ export * from './errors.js';
37
+ import { signatureToolDefinition } from './signature.js';
38
+ import { callersToolDefinition } from './callers.js';
39
+ import { importsToolDefinition } from './imports.js';
40
+ import { prevalidateToolDefinition } from './prevalidate.js';
41
+ import { similarToolDefinition } from './similar.js';
42
+ import { typeToolDefinition } from './type.js';
43
+ import { recentToolDefinition } from './recent.js';
44
+ import { testTemplateToolDefinition } from './test-template.js';
45
+ import { dependenciesToolDefinition } from './dependencies.js';
46
+ import { middlewareToolDefinition } from './middleware.js';
47
+ import { hooksToolDefinition } from './hooks.js';
48
+ import { errorsToolDefinition } from './errors.js';
49
+ /**
50
+ * All surgical tools
51
+ */
52
+ export const SURGICAL_TOOLS = [
53
+ signatureToolDefinition,
54
+ callersToolDefinition,
55
+ importsToolDefinition,
56
+ prevalidateToolDefinition,
57
+ similarToolDefinition,
58
+ typeToolDefinition,
59
+ recentToolDefinition,
60
+ testTemplateToolDefinition,
61
+ dependenciesToolDefinition,
62
+ middlewareToolDefinition,
63
+ hooksToolDefinition,
64
+ errorsToolDefinition,
65
+ ];
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/t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CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * drift_middleware - Middleware Pattern Lookup
3
+ *
4
+ * Layer: Surgical
5
+ * Token Budget: 300 target, 800 max
6
+ *
7
+ * Returns middleware patterns in the codebase.
8
+ * Solves: AI needs to know existing middleware when adding auth/logging/etc.
9
+ */
10
+ export interface MiddlewareArgs {
11
+ /** Filter by type: auth, logging, validation, error, all */
12
+ type?: 'auth' | 'logging' | 'validation' | 'error' | 'all';
13
+ /** Framework filter: express, koa, fastify, nestjs, laravel, spring */
14
+ framework?: string;
15
+ /** Max results */
16
+ limit?: number;
17
+ }
18
+ export interface MiddlewareInfo {
19
+ name: string;
20
+ file: string;
21
+ line: number;
22
+ type: string;
23
+ framework?: string | undefined;
24
+ usages: number;
25
+ parameters?: string[] | undefined;
26
+ }
27
+ export interface MiddlewareData {
28
+ middleware: MiddlewareInfo[];
29
+ byType: Record<string, number>;
30
+ stats: {
31
+ total: number;
32
+ authCount: number;
33
+ loggingCount: number;
34
+ validationCount: number;
35
+ errorCount: number;
36
+ };
37
+ }
38
+ export declare function handleMiddleware(args: MiddlewareArgs, rootDir: string): Promise<{
39
+ content: Array<{
40
+ type: string;
41
+ text: string;
42
+ }>;
43
+ }>;
44
+ /**
45
+ * Tool definition for MCP registration
46
+ */
47
+ export declare const middlewareToolDefinition: {
48
+ name: string;
49
+ description: string;
50
+ inputSchema: {
51
+ type: "object";
52
+ properties: {
53
+ type: {
54
+ type: string;
55
+ enum: string[];
56
+ description: string;
57
+ };
58
+ framework: {
59
+ type: string;
60
+ description: string;
61
+ };
62
+ limit: {
63
+ type: string;
64
+ description: string;
65
+ };
66
+ };
67
+ };
68
+ };
69
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/tools/surgical/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,I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