driftdetect-mcp 0.6.1 → 0.7.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.
- package/LICENSE +21 -0
- package/dist/bin/server.js +0 -0
- package/dist/enterprise-server.d.ts +1 -0
- package/dist/enterprise-server.d.ts.map +1 -1
- package/dist/enterprise-server.js +8 -1
- package/dist/enterprise-server.js.map +1 -1
- package/dist/tools/analysis/constants.d.ts +99 -0
- package/dist/tools/analysis/constants.d.ts.map +1 -0
- package/dist/tools/analysis/constants.js +421 -0
- package/dist/tools/analysis/constants.js.map +1 -0
- package/dist/tools/analysis/index.d.ts +1 -0
- package/dist/tools/analysis/index.d.ts.map +1 -1
- package/dist/tools/analysis/index.js +70 -0
- package/dist/tools/analysis/index.js.map +1 -1
- package/dist/tools/exploration/env.d.ts +53 -0
- package/dist/tools/exploration/env.d.ts.map +1 -0
- package/dist/tools/exploration/env.js +283 -0
- package/dist/tools/exploration/env.js.map +1 -0
- package/dist/tools/exploration/index.d.ts +2 -0
- package/dist/tools/exploration/index.d.ts.map +1 -1
- package/dist/tools/exploration/index.js +32 -0
- package/dist/tools/exploration/index.js.map +1 -1
- package/dist/tools/index.d.ts +6 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +6 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/registry.d.ts +7 -5
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +10 -4
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/surgical/callers.d.ts +85 -0
- package/dist/tools/surgical/callers.d.ts.map +1 -0
- package/dist/tools/surgical/callers.js +239 -0
- package/dist/tools/surgical/callers.js.map +1 -0
- package/dist/tools/surgical/dependencies.d.ts +96 -0
- package/dist/tools/surgical/dependencies.d.ts.map +1 -0
- package/dist/tools/surgical/dependencies.js +433 -0
- package/dist/tools/surgical/dependencies.js.map +1 -0
- package/dist/tools/surgical/errors.d.ts +88 -0
- package/dist/tools/surgical/errors.d.ts.map +1 -0
- package/dist/tools/surgical/errors.js +275 -0
- package/dist/tools/surgical/errors.js.map +1 -0
- package/dist/tools/surgical/hooks.d.ts +69 -0
- package/dist/tools/surgical/hooks.d.ts.map +1 -0
- package/dist/tools/surgical/hooks.js +247 -0
- package/dist/tools/surgical/hooks.js.map +1 -0
- package/dist/tools/surgical/imports.d.ts +61 -0
- package/dist/tools/surgical/imports.d.ts.map +1 -0
- package/dist/tools/surgical/imports.js +211 -0
- package/dist/tools/surgical/imports.js.map +1 -0
- package/dist/tools/surgical/index.d.ts +42 -0
- package/dist/tools/surgical/index.d.ts.map +1 -0
- package/dist/tools/surgical/index.js +66 -0
- package/dist/tools/surgical/index.js.map +1 -0
- package/dist/tools/surgical/middleware.d.ts +69 -0
- package/dist/tools/surgical/middleware.d.ts.map +1 -0
- package/dist/tools/surgical/middleware.js +237 -0
- package/dist/tools/surgical/middleware.js.map +1 -0
- package/dist/tools/surgical/prevalidate.d.ts +76 -0
- package/dist/tools/surgical/prevalidate.d.ts.map +1 -0
- package/dist/tools/surgical/prevalidate.js +303 -0
- package/dist/tools/surgical/prevalidate.js.map +1 -0
- package/dist/tools/surgical/recent.d.ts +66 -0
- package/dist/tools/surgical/recent.d.ts.map +1 -0
- package/dist/tools/surgical/recent.js +238 -0
- package/dist/tools/surgical/recent.js.map +1 -0
- package/dist/tools/surgical/signature.d.ts +73 -0
- package/dist/tools/surgical/signature.d.ts.map +1 -0
- package/dist/tools/surgical/signature.js +190 -0
- package/dist/tools/surgical/signature.js.map +1 -0
- package/dist/tools/surgical/similar.d.ts +77 -0
- package/dist/tools/surgical/similar.d.ts.map +1 -0
- package/dist/tools/surgical/similar.js +285 -0
- package/dist/tools/surgical/similar.js.map +1 -0
- package/dist/tools/surgical/test-template.d.ts +70 -0
- package/dist/tools/surgical/test-template.d.ts.map +1 -0
- package/dist/tools/surgical/test-template.js +298 -0
- package/dist/tools/surgical/test-template.js.map +1 -0
- package/dist/tools/surgical/type.d.ts +69 -0
- package/dist/tools/surgical/type.d.ts.map +1 -0
- package/dist/tools/surgical/type.js +289 -0
- package/dist/tools/surgical/type.js.map +1 -0
- package/package.json +11 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Geoffrey Fernald
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/bin/server.js
CHANGED
|
File without changes
|
|
@@ -34,6 +34,7 @@ export declare function createEnterpriseMCPServer(config: EnterpriseMCPConfig):
|
|
|
34
34
|
export declare function getToolCategories(): {
|
|
35
35
|
orchestration: string[];
|
|
36
36
|
discovery: string[];
|
|
37
|
+
surgical: string[];
|
|
37
38
|
exploration: string[];
|
|
38
39
|
detail: string[];
|
|
39
40
|
analysis: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enterprise-server.d.ts","sourceRoot":"","sources":["../src/enterprise-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"enterprise-server.d.ts","sourceRoot":"","sources":["../src/enterprise-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AA0EnE,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAyG7E;AA0ND;;GAEG;AACH,wBAAgB,iBAAiB;;;;;;;;EAEhC;AAED;;GAEG;AACH,wBAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAE1B"}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
21
21
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
22
|
-
import { PatternStore, ManifestStore, HistoryStore, DNAStore, BoundaryStore, ContractStore, CallGraphStore, createDataLake, createPatternServiceFromStore, } from 'driftdetect-core';
|
|
22
|
+
import { PatternStore, ManifestStore, HistoryStore, DNAStore, BoundaryStore, ContractStore, CallGraphStore, EnvStore, createDataLake, createPatternServiceFromStore, } from 'driftdetect-core';
|
|
23
23
|
// Infrastructure
|
|
24
24
|
import { handleError, rateLimiter, metrics, createCache, } from './infrastructure/index.js';
|
|
25
25
|
// Tool definitions
|
|
@@ -32,6 +32,7 @@ import { handlePatternsList, handlePatternsListWithService } from './tools/explo
|
|
|
32
32
|
import { handleSecuritySummary } from './tools/exploration/security-summary.js';
|
|
33
33
|
import { handleContractsList } from './tools/exploration/contracts-list.js';
|
|
34
34
|
import { handleTrends } from './tools/exploration/trends.js';
|
|
35
|
+
import { handleEnv } from './tools/exploration/env.js';
|
|
35
36
|
// Detail handlers
|
|
36
37
|
import { handlePatternGet, handlePatternGetWithService } from './tools/detail/pattern-get.js';
|
|
37
38
|
import { handleCodeExamples, handleCodeExamplesWithService } from './tools/detail/code-examples.js';
|
|
@@ -58,6 +59,7 @@ import { handleSimulate } from './tools/analysis/simulate.js';
|
|
|
58
59
|
import { handleConstraints } from './tools/analysis/constraints.js';
|
|
59
60
|
import { executeWpfTool } from './tools/analysis/wpf.js';
|
|
60
61
|
import { executeGoTool } from './tools/analysis/go.js';
|
|
62
|
+
import { handleConstants } from './tools/analysis/constants.js';
|
|
61
63
|
export function createEnterpriseMCPServer(config) {
|
|
62
64
|
const server = new Server({ name: 'drift-enterprise', version: '2.0.0' }, { capabilities: { tools: {} } });
|
|
63
65
|
// Initialize stores
|
|
@@ -69,6 +71,7 @@ export function createEnterpriseMCPServer(config) {
|
|
|
69
71
|
boundary: new BoundaryStore({ rootDir: config.projectRoot }),
|
|
70
72
|
contract: new ContractStore({ rootDir: config.projectRoot }),
|
|
71
73
|
callGraph: new CallGraphStore({ rootDir: config.projectRoot }),
|
|
74
|
+
env: new EnvStore({ rootDir: config.projectRoot }),
|
|
72
75
|
};
|
|
73
76
|
// Initialize pattern service (wraps PatternStore with unified interface)
|
|
74
77
|
// Default to using the new service for better abstraction
|
|
@@ -186,6 +189,8 @@ async function routeToolCall(name, args, stores, projectRoot, dataLake, patternS
|
|
|
186
189
|
return handleContractsList(stores.contract, args);
|
|
187
190
|
case 'drift_trends':
|
|
188
191
|
return handleTrends(stores.history, args);
|
|
192
|
+
case 'drift_env':
|
|
193
|
+
return handleEnv(stores.env, args);
|
|
189
194
|
}
|
|
190
195
|
// ============================================================================
|
|
191
196
|
// Detail Tools (Layer 3)
|
|
@@ -241,6 +246,8 @@ async function routeToolCall(name, args, stores, projectRoot, dataLake, patternS
|
|
|
241
246
|
return executeWpfTool(args, { projectRoot });
|
|
242
247
|
case 'drift_go':
|
|
243
248
|
return executeGoTool(args, { projectRoot });
|
|
249
|
+
case 'drift_constants':
|
|
250
|
+
return handleConstants(projectRoot, args);
|
|
244
251
|
}
|
|
245
252
|
// ============================================================================
|
|
246
253
|
// Generation Tools (AI-Powered Code Intelligence)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enterprise-server.js","sourceRoot":"","sources":["../src/enterprise-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,6BAA6B,GAG9B,MAAM,kBAAkB,CAAC;AAE1B,iBAAiB;AACjB,OAAO,EACL,WAAW,EACX,WAAW,EACX,OAAO,EACP,WAAW,GACZ,MAAM,2BAA2B,CAAC;AAEnC,mBAAmB;AACnB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEjE,qBAAqB;AACrB,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,uBAAuB;AACvB,OAAO,EAAE,kBA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CAC9D,CAAC;QAEJ,KAAK,uBAAuB;YAC1B,OAAO,oBAAoB,CACzB,MAAM,CAAC,OAAO,EACd,WAAW,EACX,IAA6D,CAC9D,CAAC;QAEJ,KAAK,eAAe;YAClB,OAAO,aAAa,CAClB;gBACE,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B,EACD,WAAW,EACX,IAAsD,CACvD,CAAC;IACN,CAAC;IAED,eAAe;IACf,OAAO;QACL,OAAO,EAAE,CAAC;gBACR,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,KAAK,EAAE,iBAAiB,IAAI,EAAE;oBAC9B,IAAI,EAAE,+CAA+C;oBACrD,cAAc,EAAE,eAAe;iBAChC,CAAC;aACH,CAAC;QACF,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* drift_constants - Constant & Enum Analysis
|
|
3
|
+
*
|
|
4
|
+
* Analysis tool for constants, enums, and exported values:
|
|
5
|
+
* - Overview of constants by category and language
|
|
6
|
+
* - List constants with filtering
|
|
7
|
+
* - Get constant details and usages
|
|
8
|
+
* - Find magic values that should be constants
|
|
9
|
+
* - Find dead (unused) constants
|
|
10
|
+
* - Detect potential hardcoded secrets
|
|
11
|
+
* - Find inconsistent constant values
|
|
12
|
+
*/
|
|
13
|
+
import { type ConstantExtraction, type EnumExtraction, type ConstantCategory, type ConstantLanguage, type PotentialSecret, type InconsistentConstant, type IssueSeverity } from 'driftdetect-core';
|
|
14
|
+
export type ConstantsAction = 'status' | 'list' | 'get' | 'usages' | 'magic' | 'dead' | 'secrets' | 'inconsistent';
|
|
15
|
+
export interface ConstantsArgs {
|
|
16
|
+
action?: ConstantsAction;
|
|
17
|
+
category?: ConstantCategory;
|
|
18
|
+
language?: ConstantLanguage;
|
|
19
|
+
file?: string;
|
|
20
|
+
search?: string;
|
|
21
|
+
exported?: boolean;
|
|
22
|
+
limit?: number;
|
|
23
|
+
cursor?: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
constantId?: string;
|
|
27
|
+
minOccurrences?: number;
|
|
28
|
+
includeStrings?: boolean;
|
|
29
|
+
includeNumbers?: boolean;
|
|
30
|
+
severity?: IssueSeverity;
|
|
31
|
+
}
|
|
32
|
+
export interface ConstantsStatusData {
|
|
33
|
+
totalConstants: number;
|
|
34
|
+
totalEnums: number;
|
|
35
|
+
byLanguage: Record<string, number>;
|
|
36
|
+
byCategory: Record<string, number>;
|
|
37
|
+
issues: {
|
|
38
|
+
magicValues: number;
|
|
39
|
+
deadConstants: number;
|
|
40
|
+
potentialSecrets: number;
|
|
41
|
+
inconsistentValues: number;
|
|
42
|
+
};
|
|
43
|
+
lastScanAt?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ConstantsListData {
|
|
46
|
+
constants: Array<{
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
qualifiedName: string;
|
|
50
|
+
file: string;
|
|
51
|
+
line: number;
|
|
52
|
+
language: string;
|
|
53
|
+
kind: string;
|
|
54
|
+
category: string;
|
|
55
|
+
value?: string | number | boolean | null | undefined;
|
|
56
|
+
isExported: boolean;
|
|
57
|
+
}>;
|
|
58
|
+
enums: Array<{
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
file: string;
|
|
62
|
+
line: number;
|
|
63
|
+
memberCount: number;
|
|
64
|
+
}>;
|
|
65
|
+
total: number;
|
|
66
|
+
cursor?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ConstantDetailData {
|
|
69
|
+
constant?: ConstantExtraction | undefined;
|
|
70
|
+
enum?: EnumExtraction | undefined;
|
|
71
|
+
usages: Array<{
|
|
72
|
+
file: string;
|
|
73
|
+
line: number;
|
|
74
|
+
context?: string;
|
|
75
|
+
containingFunction?: string;
|
|
76
|
+
}>;
|
|
77
|
+
usageCount: number;
|
|
78
|
+
relatedConstants: Array<{
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
reason: string;
|
|
82
|
+
}>;
|
|
83
|
+
}
|
|
84
|
+
export interface SecretsData {
|
|
85
|
+
potentialSecrets: PotentialSecret[];
|
|
86
|
+
total: number;
|
|
87
|
+
bySeverity: Record<IssueSeverity, number>;
|
|
88
|
+
}
|
|
89
|
+
export interface InconsistentData {
|
|
90
|
+
inconsistencies: InconsistentConstant[];
|
|
91
|
+
total: number;
|
|
92
|
+
}
|
|
93
|
+
export declare function handleConstants(projectRoot: string, args: ConstantsArgs): Promise<{
|
|
94
|
+
content: Array<{
|
|
95
|
+
type: string;
|
|
96
|
+
text: string;
|
|
97
|
+
}>;
|
|
98
|
+
}>;
|
|
99
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/tools/analysis/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAO1B,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,MAAM,GACN,KAAK,GACL,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,GACT,cAAc,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,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EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA0B7D"}
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* drift_constants - Constant & Enum Analysis
|
|
3
|
+
*
|
|
4
|
+
* Analysis tool for constants, enums, and exported values:
|
|
5
|
+
* - Overview of constants by category and language
|
|
6
|
+
* - List constants with filtering
|
|
7
|
+
* - Get constant details and usages
|
|
8
|
+
* - Find magic values that should be constants
|
|
9
|
+
* - Find dead (unused) constants
|
|
10
|
+
* - Detect potential hardcoded secrets
|
|
11
|
+
* - Find inconsistent constant values
|
|
12
|
+
*/
|
|
13
|
+
import { ConstantStore, ConstantSecurityScanner, ConsistencyAnalyzer, } from 'driftdetect-core';
|
|
14
|
+
import { createResponseBuilder, Errors } from '../../infrastructure/index.js';
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Constants
|
|
17
|
+
// ============================================================================
|
|
18
|
+
const DEFAULT_LIMIT = 20;
|
|
19
|
+
const MAX_LIMIT = 50;
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// Handler
|
|
22
|
+
// ============================================================================
|
|
23
|
+
export async function handleConstants(projectRoot, args) {
|
|
24
|
+
const action = args.action ?? 'status';
|
|
25
|
+
switch (action) {
|
|
26
|
+
case 'status':
|
|
27
|
+
return handleStatus(projectRoot);
|
|
28
|
+
case 'list':
|
|
29
|
+
return handleList(projectRoot, args);
|
|
30
|
+
case 'get':
|
|
31
|
+
return handleGet(projectRoot, args);
|
|
32
|
+
case 'usages':
|
|
33
|
+
return handleUsages(projectRoot, args);
|
|
34
|
+
case 'magic':
|
|
35
|
+
return handleMagic(projectRoot, args);
|
|
36
|
+
case 'dead':
|
|
37
|
+
return handleDead(projectRoot, args);
|
|
38
|
+
case 'secrets':
|
|
39
|
+
return handleSecrets(projectRoot, args);
|
|
40
|
+
case 'inconsistent':
|
|
41
|
+
return handleInconsistent(projectRoot, args);
|
|
42
|
+
default:
|
|
43
|
+
throw Errors.invalidArgument('action', `Invalid action: ${action}. Valid: status, list, get, usages, magic, dead, secrets, inconsistent`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Action Handlers
|
|
48
|
+
// ============================================================================
|
|
49
|
+
async function handleStatus(projectRoot) {
|
|
50
|
+
const builder = createResponseBuilder();
|
|
51
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
52
|
+
try {
|
|
53
|
+
const stats = await store.getStats();
|
|
54
|
+
const index = await store.getIndex();
|
|
55
|
+
const data = {
|
|
56
|
+
totalConstants: stats.totalConstants,
|
|
57
|
+
totalEnums: stats.totalEnums,
|
|
58
|
+
byLanguage: stats.byLanguage,
|
|
59
|
+
byCategory: stats.byCategory,
|
|
60
|
+
issues: stats.issues,
|
|
61
|
+
lastScanAt: index.generatedAt,
|
|
62
|
+
};
|
|
63
|
+
let summary = `📊 ${stats.totalConstants} constants, ${stats.totalEnums} enums. `;
|
|
64
|
+
// Add language breakdown
|
|
65
|
+
const topLanguages = Object.entries(stats.byLanguage)
|
|
66
|
+
.sort(([, a], [, b]) => b - a)
|
|
67
|
+
.slice(0, 3)
|
|
68
|
+
.map(([lang, count]) => `${lang}: ${count}`)
|
|
69
|
+
.join(', ');
|
|
70
|
+
if (topLanguages) {
|
|
71
|
+
summary += `Languages: ${topLanguages}. `;
|
|
72
|
+
}
|
|
73
|
+
// Add issues
|
|
74
|
+
const issueCount = stats.issues.magicValues +
|
|
75
|
+
stats.issues.deadConstants +
|
|
76
|
+
stats.issues.potentialSecrets +
|
|
77
|
+
stats.issues.inconsistentValues;
|
|
78
|
+
if (issueCount > 0) {
|
|
79
|
+
summary += `⚠️ ${issueCount} issues found.`;
|
|
80
|
+
}
|
|
81
|
+
const warnings = [];
|
|
82
|
+
if (stats.issues.potentialSecrets > 0) {
|
|
83
|
+
warnings.push(`${stats.issues.potentialSecrets} potential hardcoded secrets detected`);
|
|
84
|
+
}
|
|
85
|
+
if (stats.issues.inconsistentValues > 0) {
|
|
86
|
+
warnings.push(`${stats.issues.inconsistentValues} constants have inconsistent values`);
|
|
87
|
+
}
|
|
88
|
+
return builder
|
|
89
|
+
.withSummary(summary)
|
|
90
|
+
.withData(data)
|
|
91
|
+
.withHints({
|
|
92
|
+
nextActions: stats.issues.potentialSecrets > 0
|
|
93
|
+
? ['Run action="secrets" to review potential secrets']
|
|
94
|
+
: stats.totalConstants > 0
|
|
95
|
+
? ['Run action="list" to browse constants']
|
|
96
|
+
: ['Run drift scan to extract constants'],
|
|
97
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
98
|
+
relatedTools: ['drift_constants action="list"', 'drift_constants action="secrets"'],
|
|
99
|
+
})
|
|
100
|
+
.buildContent();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return builder
|
|
104
|
+
.withSummary('No constant data found. Run `drift scan` first.')
|
|
105
|
+
.withHints({
|
|
106
|
+
nextActions: ['Run drift scan to extract constants from your codebase'],
|
|
107
|
+
relatedTools: ['drift_status'],
|
|
108
|
+
})
|
|
109
|
+
.buildContent();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function handleList(projectRoot, args) {
|
|
113
|
+
const builder = createResponseBuilder();
|
|
114
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
115
|
+
const limit = Math.min(args.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
|
|
116
|
+
let constants = await store.getAllConstants();
|
|
117
|
+
let enums = await store.getAllEnums();
|
|
118
|
+
// Apply filters
|
|
119
|
+
if (args.category) {
|
|
120
|
+
constants = constants.filter((c) => c.category === args.category);
|
|
121
|
+
}
|
|
122
|
+
if (args.language) {
|
|
123
|
+
constants = constants.filter((c) => c.language === args.language);
|
|
124
|
+
enums = enums.filter((e) => e.language === args.language);
|
|
125
|
+
}
|
|
126
|
+
if (args.file) {
|
|
127
|
+
constants = constants.filter((c) => c.file.includes(args.file));
|
|
128
|
+
enums = enums.filter((e) => e.file.includes(args.file));
|
|
129
|
+
}
|
|
130
|
+
if (args.search) {
|
|
131
|
+
const searchLower = args.search.toLowerCase();
|
|
132
|
+
constants = constants.filter((c) => c.name.toLowerCase().includes(searchLower) ||
|
|
133
|
+
c.qualifiedName.toLowerCase().includes(searchLower));
|
|
134
|
+
enums = enums.filter((e) => e.name.toLowerCase().includes(searchLower));
|
|
135
|
+
}
|
|
136
|
+
if (args.exported !== undefined) {
|
|
137
|
+
constants = constants.filter((c) => c.isExported === args.exported);
|
|
138
|
+
enums = enums.filter((e) => e.isExported === args.exported);
|
|
139
|
+
}
|
|
140
|
+
// Pagination
|
|
141
|
+
const total = constants.length + enums.length;
|
|
142
|
+
const paginatedConstants = constants.slice(0, limit);
|
|
143
|
+
const paginatedEnums = enums.slice(0, Math.max(0, limit - paginatedConstants.length));
|
|
144
|
+
const data = {
|
|
145
|
+
constants: paginatedConstants.map((c) => ({
|
|
146
|
+
id: c.id,
|
|
147
|
+
name: c.name,
|
|
148
|
+
qualifiedName: c.qualifiedName,
|
|
149
|
+
file: c.file,
|
|
150
|
+
line: c.line,
|
|
151
|
+
language: c.language,
|
|
152
|
+
kind: c.kind,
|
|
153
|
+
category: c.category,
|
|
154
|
+
value: c.value,
|
|
155
|
+
isExported: c.isExported,
|
|
156
|
+
})),
|
|
157
|
+
enums: paginatedEnums.map((e) => ({
|
|
158
|
+
id: e.id,
|
|
159
|
+
name: e.name,
|
|
160
|
+
file: e.file,
|
|
161
|
+
line: e.line,
|
|
162
|
+
memberCount: e.members.length,
|
|
163
|
+
})),
|
|
164
|
+
total,
|
|
165
|
+
};
|
|
166
|
+
let summary = `Found ${constants.length} constants`;
|
|
167
|
+
if (enums.length > 0) {
|
|
168
|
+
summary += `, ${enums.length} enums`;
|
|
169
|
+
}
|
|
170
|
+
if (args.category) {
|
|
171
|
+
summary += ` in category "${args.category}"`;
|
|
172
|
+
}
|
|
173
|
+
if (args.language) {
|
|
174
|
+
summary += ` (${args.language})`;
|
|
175
|
+
}
|
|
176
|
+
summary += '.';
|
|
177
|
+
return builder
|
|
178
|
+
.withSummary(summary)
|
|
179
|
+
.withData(data)
|
|
180
|
+
.withHints({
|
|
181
|
+
nextActions: ['Use action="get" with id or name to see constant details'],
|
|
182
|
+
relatedTools: ['drift_constants action="get"', 'drift_file_patterns'],
|
|
183
|
+
})
|
|
184
|
+
.buildContent();
|
|
185
|
+
}
|
|
186
|
+
async function handleGet(projectRoot, args) {
|
|
187
|
+
const builder = createResponseBuilder();
|
|
188
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
189
|
+
if (!args.id && !args.name) {
|
|
190
|
+
throw Errors.missingParameter('id or name');
|
|
191
|
+
}
|
|
192
|
+
let constant = null;
|
|
193
|
+
let enumDef = null;
|
|
194
|
+
if (args.id) {
|
|
195
|
+
constant = await store.getConstantById(args.id);
|
|
196
|
+
if (!constant) {
|
|
197
|
+
enumDef = await store.getEnumById(args.id);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (args.name) {
|
|
201
|
+
const results = await store.searchByName(args.name);
|
|
202
|
+
if (results.length > 0) {
|
|
203
|
+
constant = results[0];
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const enums = await store.getAllEnums();
|
|
207
|
+
enumDef = enums.find((e) => e.name === args.name) ?? null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (!constant && !enumDef) {
|
|
211
|
+
throw Errors.custom('NOT_FOUND', `Constant or enum not found: ${args.id ?? args.name}`, [
|
|
212
|
+
'Check the ID or name',
|
|
213
|
+
'Use action="list" to see available constants',
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
// Find related constants (same file or same category)
|
|
217
|
+
const allConstants = await store.getAllConstants();
|
|
218
|
+
const relatedConstants = [];
|
|
219
|
+
if (constant) {
|
|
220
|
+
const sameFile = allConstants
|
|
221
|
+
.filter((c) => c.file === constant.file && c.id !== constant.id)
|
|
222
|
+
.slice(0, 3);
|
|
223
|
+
for (const c of sameFile) {
|
|
224
|
+
relatedConstants.push({ id: c.id, name: c.name, reason: 'same_file' });
|
|
225
|
+
}
|
|
226
|
+
const sameCategory = allConstants
|
|
227
|
+
.filter((c) => c.category === constant.category &&
|
|
228
|
+
c.id !== constant.id &&
|
|
229
|
+
!sameFile.some((sf) => sf.id === c.id))
|
|
230
|
+
.slice(0, 2);
|
|
231
|
+
for (const c of sameCategory) {
|
|
232
|
+
relatedConstants.push({ id: c.id, name: c.name, reason: 'same_category' });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const data = {
|
|
236
|
+
constant: constant ?? undefined,
|
|
237
|
+
enum: enumDef ?? undefined,
|
|
238
|
+
usages: [], // Would need reference tracking to populate
|
|
239
|
+
usageCount: 0,
|
|
240
|
+
relatedConstants,
|
|
241
|
+
};
|
|
242
|
+
const item = constant ?? enumDef;
|
|
243
|
+
let summary = `${item.name}: ${constant ? constant.kind : 'enum'} in ${item.file}:${item.line}`;
|
|
244
|
+
if (constant?.value !== undefined) {
|
|
245
|
+
const valueStr = String(constant.value);
|
|
246
|
+
summary += ` = ${valueStr.length > 50 ? valueStr.slice(0, 50) + '...' : valueStr}`;
|
|
247
|
+
}
|
|
248
|
+
if (enumDef) {
|
|
249
|
+
summary += ` (${enumDef.members.length} members)`;
|
|
250
|
+
}
|
|
251
|
+
return builder
|
|
252
|
+
.withSummary(summary)
|
|
253
|
+
.withData(data)
|
|
254
|
+
.withHints({
|
|
255
|
+
nextActions: ['Use action="usages" to find where this constant is used'],
|
|
256
|
+
relatedTools: ['drift_constants action="usages"', 'drift_impact_analysis'],
|
|
257
|
+
})
|
|
258
|
+
.buildContent();
|
|
259
|
+
}
|
|
260
|
+
async function handleUsages(projectRoot, args) {
|
|
261
|
+
const builder = createResponseBuilder();
|
|
262
|
+
if (!args.constantId && !args.id && !args.name) {
|
|
263
|
+
throw Errors.missingParameter('constantId, id, or name');
|
|
264
|
+
}
|
|
265
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
266
|
+
const constantId = args.constantId ?? args.id ?? args.name;
|
|
267
|
+
// Get the constant
|
|
268
|
+
let constant = await store.getConstantById(constantId);
|
|
269
|
+
if (!constant && args.name) {
|
|
270
|
+
const results = await store.searchByName(args.name);
|
|
271
|
+
constant = results[0] ?? null;
|
|
272
|
+
}
|
|
273
|
+
if (!constant) {
|
|
274
|
+
throw Errors.custom('NOT_FOUND', `Constant not found: ${constantId}`, [
|
|
275
|
+
'Use action="list" to see available constants',
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
// Note: Full usage tracking requires reference analysis
|
|
279
|
+
// For now, return placeholder
|
|
280
|
+
const data = {
|
|
281
|
+
constantId: constant.id,
|
|
282
|
+
usages: [],
|
|
283
|
+
total: 0,
|
|
284
|
+
};
|
|
285
|
+
return builder
|
|
286
|
+
.withSummary(`${constant.name}: Usage tracking requires reference analysis. Run drift scan with reference tracking enabled.`)
|
|
287
|
+
.withData(data)
|
|
288
|
+
.withHints({
|
|
289
|
+
nextActions: ['Enable reference tracking in drift config for full usage analysis'],
|
|
290
|
+
relatedTools: ['drift_reachability', 'drift_impact_analysis'],
|
|
291
|
+
})
|
|
292
|
+
.buildContent();
|
|
293
|
+
}
|
|
294
|
+
async function handleMagic(_projectRoot, _args) {
|
|
295
|
+
const builder = createResponseBuilder();
|
|
296
|
+
// Magic value detection requires scanning file content for literals
|
|
297
|
+
// This is a placeholder - full implementation would scan files
|
|
298
|
+
const data = {
|
|
299
|
+
magicValues: [],
|
|
300
|
+
total: 0,
|
|
301
|
+
};
|
|
302
|
+
return builder
|
|
303
|
+
.withSummary('Magic value detection requires file content scanning. Run drift scan with magic value detection enabled.')
|
|
304
|
+
.withData(data)
|
|
305
|
+
.withHints({
|
|
306
|
+
nextActions: ['Enable magic value detection in drift config'],
|
|
307
|
+
relatedTools: ['drift_constants action="list"'],
|
|
308
|
+
})
|
|
309
|
+
.buildContent();
|
|
310
|
+
}
|
|
311
|
+
async function handleDead(projectRoot, args) {
|
|
312
|
+
const builder = createResponseBuilder();
|
|
313
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
314
|
+
const limit = Math.min(args.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
|
|
315
|
+
// Get constants that are not exported and uncategorized (likely unused)
|
|
316
|
+
const constants = await store.getAllConstants();
|
|
317
|
+
const potentiallyDead = constants
|
|
318
|
+
.filter((c) => !c.isExported && c.category === 'uncategorized')
|
|
319
|
+
.slice(0, limit);
|
|
320
|
+
const data = {
|
|
321
|
+
deadConstants: potentiallyDead.map((c) => ({
|
|
322
|
+
id: c.id,
|
|
323
|
+
name: c.name,
|
|
324
|
+
file: c.file,
|
|
325
|
+
line: c.line,
|
|
326
|
+
confidence: 0.5,
|
|
327
|
+
reason: 'not_exported_uncategorized',
|
|
328
|
+
})),
|
|
329
|
+
total: potentiallyDead.length,
|
|
330
|
+
};
|
|
331
|
+
let summary = `Found ${potentiallyDead.length} potentially unused constants. `;
|
|
332
|
+
summary += 'Note: Full dead code detection requires reference analysis.';
|
|
333
|
+
return builder
|
|
334
|
+
.withSummary(summary)
|
|
335
|
+
.withData(data)
|
|
336
|
+
.withHints({
|
|
337
|
+
nextActions: potentiallyDead.length > 0
|
|
338
|
+
? ['Review these constants - they may be unused']
|
|
339
|
+
: ['No obvious dead constants found'],
|
|
340
|
+
relatedTools: ['drift_dead_code', 'drift_constants action="usages"'],
|
|
341
|
+
})
|
|
342
|
+
.buildContent();
|
|
343
|
+
}
|
|
344
|
+
async function handleSecrets(projectRoot, args) {
|
|
345
|
+
const builder = createResponseBuilder();
|
|
346
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
347
|
+
const scanner = new ConstantSecurityScanner();
|
|
348
|
+
const constants = await store.getAllConstants();
|
|
349
|
+
const result = scanner.scan(constants);
|
|
350
|
+
// Filter by severity if specified
|
|
351
|
+
let secrets = result.secrets;
|
|
352
|
+
if (args.severity) {
|
|
353
|
+
const severityOrder = ['info', 'low', 'medium', 'high', 'critical'];
|
|
354
|
+
const minIndex = severityOrder.indexOf(args.severity);
|
|
355
|
+
secrets = secrets.filter((s) => severityOrder.indexOf(s.severity) >= minIndex);
|
|
356
|
+
}
|
|
357
|
+
const limit = Math.min(args.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
|
|
358
|
+
const paginatedSecrets = secrets.slice(0, limit);
|
|
359
|
+
const bySeverity = {
|
|
360
|
+
info: 0,
|
|
361
|
+
low: 0,
|
|
362
|
+
medium: 0,
|
|
363
|
+
high: 0,
|
|
364
|
+
critical: 0,
|
|
365
|
+
};
|
|
366
|
+
for (const secret of secrets) {
|
|
367
|
+
bySeverity[secret.severity]++;
|
|
368
|
+
}
|
|
369
|
+
const data = {
|
|
370
|
+
potentialSecrets: paginatedSecrets,
|
|
371
|
+
total: secrets.length,
|
|
372
|
+
bySeverity,
|
|
373
|
+
};
|
|
374
|
+
let summary = `🔐 ${secrets.length} potential secrets detected. `;
|
|
375
|
+
if (bySeverity.critical > 0) {
|
|
376
|
+
summary += `🔴 ${bySeverity.critical} critical. `;
|
|
377
|
+
}
|
|
378
|
+
if (bySeverity.high > 0) {
|
|
379
|
+
summary += `🟠 ${bySeverity.high} high. `;
|
|
380
|
+
}
|
|
381
|
+
const warnings = [];
|
|
382
|
+
if (bySeverity.critical > 0) {
|
|
383
|
+
warnings.push('Critical secrets found - immediate action required!');
|
|
384
|
+
}
|
|
385
|
+
return builder
|
|
386
|
+
.withSummary(summary)
|
|
387
|
+
.withData(data)
|
|
388
|
+
.withHints({
|
|
389
|
+
nextActions: secrets.length > 0
|
|
390
|
+
? ['Move secrets to environment variables', 'Use a secrets manager']
|
|
391
|
+
: ['No hardcoded secrets detected'],
|
|
392
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
393
|
+
relatedTools: ['drift_security_summary', 'drift_env'],
|
|
394
|
+
})
|
|
395
|
+
.buildContent();
|
|
396
|
+
}
|
|
397
|
+
async function handleInconsistent(projectRoot, args) {
|
|
398
|
+
const builder = createResponseBuilder();
|
|
399
|
+
const store = new ConstantStore({ rootDir: projectRoot });
|
|
400
|
+
const analyzer = new ConsistencyAnalyzer();
|
|
401
|
+
const constants = await store.getAllConstants();
|
|
402
|
+
const result = analyzer.analyze(constants);
|
|
403
|
+
const limit = Math.min(args.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
|
|
404
|
+
const paginatedInconsistencies = result.inconsistencies.slice(0, limit);
|
|
405
|
+
const data = {
|
|
406
|
+
inconsistencies: paginatedInconsistencies,
|
|
407
|
+
total: result.inconsistencies.length,
|
|
408
|
+
};
|
|
409
|
+
let summary = `⚡ ${result.inconsistencies.length} constants have inconsistent values across files.`;
|
|
410
|
+
return builder
|
|
411
|
+
.withSummary(summary)
|
|
412
|
+
.withData(data)
|
|
413
|
+
.withHints({
|
|
414
|
+
nextActions: result.inconsistencies.length > 0
|
|
415
|
+
? ['Consolidate constants to a single source of truth']
|
|
416
|
+
: ['No inconsistent constants found'],
|
|
417
|
+
relatedTools: ['drift_constants action="get"', 'drift_constants action="list"'],
|
|
418
|
+
})
|
|
419
|
+
.buildContent();
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=constants.js.map
|