driftdetect-mcp 0.4.0 → 0.4.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.
- package/LICENSE +21 -0
- package/dist/bin/server.d.ts +12 -2
- package/dist/bin/server.d.ts.map +1 -1
- package/dist/bin/server.js +25 -5
- package/dist/bin/server.js.map +1 -1
- package/dist/enterprise-server.d.ts +78 -0
- package/dist/enterprise-server.d.ts.map +1 -0
- package/dist/enterprise-server.js +201 -0
- package/dist/enterprise-server.js.map +1 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/cache.d.ts +86 -0
- package/dist/infrastructure/cache.d.ts.map +1 -0
- package/dist/infrastructure/cache.js +271 -0
- package/dist/infrastructure/cache.js.map +1 -0
- package/dist/infrastructure/cursor-manager.d.ts +86 -0
- package/dist/infrastructure/cursor-manager.d.ts.map +1 -0
- package/dist/infrastructure/cursor-manager.js +175 -0
- package/dist/infrastructure/cursor-manager.js.map +1 -0
- package/dist/infrastructure/error-handler.d.ts +82 -0
- package/dist/infrastructure/error-handler.d.ts.map +1 -0
- package/dist/infrastructure/error-handler.js +226 -0
- package/dist/infrastructure/error-handler.js.map +1 -0
- package/dist/infrastructure/index.d.ts +19 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/index.js +26 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/infrastructure/metrics.d.ts +104 -0
- package/dist/infrastructure/metrics.d.ts.map +1 -0
- package/dist/infrastructure/metrics.js +291 -0
- package/dist/infrastructure/metrics.js.map +1 -0
- package/dist/infrastructure/rate-limiter.d.ts +59 -0
- package/dist/infrastructure/rate-limiter.d.ts.map +1 -0
- package/dist/infrastructure/rate-limiter.js +132 -0
- package/dist/infrastructure/rate-limiter.js.map +1 -0
- package/dist/infrastructure/response-builder.d.ts +104 -0
- package/dist/infrastructure/response-builder.d.ts.map +1 -0
- package/dist/infrastructure/response-builder.js +207 -0
- package/dist/infrastructure/response-builder.js.map +1 -0
- package/dist/infrastructure/token-estimator.d.ts +48 -0
- package/dist/infrastructure/token-estimator.d.ts.map +1 -0
- package/dist/infrastructure/token-estimator.js +131 -0
- package/dist/infrastructure/token-estimator.js.map +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1074 -17
- package/dist/server.js.map +1 -1
- package/dist/tools/detail/code-examples.d.ts +33 -0
- package/dist/tools/detail/code-examples.d.ts.map +1 -0
- package/dist/tools/detail/code-examples.js +126 -0
- package/dist/tools/detail/code-examples.js.map +1 -0
- package/dist/tools/detail/dna-check.d.ts +32 -0
- package/dist/tools/detail/dna-check.d.ts.map +1 -0
- package/dist/tools/detail/dna-check.js +231 -0
- package/dist/tools/detail/dna-check.js.map +1 -0
- package/dist/tools/detail/dna-profile.d.ts +37 -0
- package/dist/tools/detail/dna-profile.d.ts.map +1 -0
- package/dist/tools/detail/dna-profile.js +101 -0
- package/dist/tools/detail/dna-profile.js.map +1 -0
- package/dist/tools/detail/file-patterns.d.ts +39 -0
- package/dist/tools/detail/file-patterns.d.ts.map +1 -0
- package/dist/tools/detail/file-patterns.js +103 -0
- package/dist/tools/detail/file-patterns.js.map +1 -0
- package/dist/tools/detail/files-list.d.ts +30 -0
- package/dist/tools/detail/files-list.d.ts.map +1 -0
- package/dist/tools/detail/files-list.js +99 -0
- package/dist/tools/detail/files-list.js.map +1 -0
- package/dist/tools/detail/impact-analysis.d.ts +53 -0
- package/dist/tools/detail/impact-analysis.d.ts.map +1 -0
- package/dist/tools/detail/impact-analysis.js +130 -0
- package/dist/tools/detail/impact-analysis.js.map +1 -0
- package/dist/tools/detail/index.d.ts +23 -0
- package/dist/tools/detail/index.d.ts.map +1 -0
- package/dist/tools/detail/index.js +200 -0
- package/dist/tools/detail/index.js.map +1 -0
- package/dist/tools/detail/pattern-get.d.ts +45 -0
- package/dist/tools/detail/pattern-get.d.ts.map +1 -0
- package/dist/tools/detail/pattern-get.js +87 -0
- package/dist/tools/detail/pattern-get.js.map +1 -0
- package/dist/tools/detail/reachability.d.ts +60 -0
- package/dist/tools/detail/reachability.d.ts.map +1 -0
- package/dist/tools/detail/reachability.js +168 -0
- package/dist/tools/detail/reachability.js.map +1 -0
- package/dist/tools/discovery/capabilities.d.ts +28 -0
- package/dist/tools/discovery/capabilities.d.ts.map +1 -0
- package/dist/tools/discovery/capabilities.js +112 -0
- package/dist/tools/discovery/capabilities.js.map +1 -0
- package/dist/tools/discovery/index.d.ts +13 -0
- package/dist/tools/discovery/index.d.ts.map +1 -0
- package/dist/tools/discovery/index.js +30 -0
- package/dist/tools/discovery/index.js.map +1 -0
- package/dist/tools/discovery/projects.d.ts +26 -0
- package/dist/tools/discovery/projects.d.ts.map +1 -0
- package/dist/tools/discovery/projects.js +210 -0
- package/dist/tools/discovery/projects.js.map +1 -0
- package/dist/tools/discovery/status.d.ts +42 -0
- package/dist/tools/discovery/status.d.ts.map +1 -0
- package/dist/tools/discovery/status.js +157 -0
- package/dist/tools/discovery/status.js.map +1 -0
- package/dist/tools/exploration/contracts-list.d.ts +35 -0
- package/dist/tools/exploration/contracts-list.d.ts.map +1 -0
- package/dist/tools/exploration/contracts-list.js +106 -0
- package/dist/tools/exploration/contracts-list.js.map +1 -0
- package/dist/tools/exploration/files-list.d.ts +29 -0
- package/dist/tools/exploration/files-list.d.ts.map +1 -0
- package/dist/tools/exploration/files-list.js +94 -0
- package/dist/tools/exploration/files-list.js.map +1 -0
- package/dist/tools/exploration/index.d.ts +17 -0
- package/dist/tools/exploration/index.d.ts.map +1 -0
- package/dist/tools/exploration/index.js +126 -0
- package/dist/tools/exploration/index.js.map +1 -0
- package/dist/tools/exploration/patterns-list.d.ts +40 -0
- package/dist/tools/exploration/patterns-list.d.ts.map +1 -0
- package/dist/tools/exploration/patterns-list.js +172 -0
- package/dist/tools/exploration/patterns-list.js.map +1 -0
- package/dist/tools/exploration/security-summary.d.ts +49 -0
- package/dist/tools/exploration/security-summary.d.ts.map +1 -0
- package/dist/tools/exploration/security-summary.js +111 -0
- package/dist/tools/exploration/security-summary.js.map +1 -0
- package/dist/tools/exploration/trends.d.ts +49 -0
- package/dist/tools/exploration/trends.d.ts.map +1 -0
- package/dist/tools/exploration/trends.js +147 -0
- package/dist/tools/exploration/trends.js.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +13 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/orchestration/context.d.ts +72 -0
- package/dist/tools/orchestration/context.d.ts.map +1 -0
- package/dist/tools/orchestration/context.js +499 -0
- package/dist/tools/orchestration/context.js.map +1 -0
- package/dist/tools/orchestration/index.d.ts +11 -0
- package/dist/tools/orchestration/index.d.ts.map +1 -0
- package/dist/tools/orchestration/index.js +56 -0
- package/dist/tools/orchestration/index.js.map +1 -0
- package/dist/tools/registry.d.ts +41 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +64 -0
- package/dist/tools/registry.js.map +1 -0
- package/package.json +11 -11
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Estimator
|
|
3
|
+
*
|
|
4
|
+
* Estimates token count for responses to stay within context budgets.
|
|
5
|
+
* Uses heuristics based on typical tokenization patterns.
|
|
6
|
+
*/
|
|
7
|
+
export class TokenEstimator {
|
|
8
|
+
// Average characters per token for different content types
|
|
9
|
+
static CHARS_PER_TOKEN = {
|
|
10
|
+
english: 4,
|
|
11
|
+
code: 3.5,
|
|
12
|
+
json: 3,
|
|
13
|
+
mixed: 3.5,
|
|
14
|
+
};
|
|
15
|
+
// JSON structure overhead multiplier
|
|
16
|
+
static JSON_OVERHEAD = 1.15;
|
|
17
|
+
/**
|
|
18
|
+
* Estimate tokens for a string
|
|
19
|
+
*/
|
|
20
|
+
estimate(text) {
|
|
21
|
+
if (!text)
|
|
22
|
+
return 0;
|
|
23
|
+
const contentType = this.detectContentType(text);
|
|
24
|
+
const charsPerToken = TokenEstimator.CHARS_PER_TOKEN[contentType];
|
|
25
|
+
// Base token count
|
|
26
|
+
let tokens = Math.ceil(text.length / charsPerToken);
|
|
27
|
+
// Add overhead for JSON structure
|
|
28
|
+
if (contentType === 'json') {
|
|
29
|
+
tokens = Math.ceil(tokens * TokenEstimator.JSON_OVERHEAD);
|
|
30
|
+
}
|
|
31
|
+
return tokens;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Estimate with detailed breakdown
|
|
35
|
+
*/
|
|
36
|
+
estimateDetailed(text) {
|
|
37
|
+
if (!text) {
|
|
38
|
+
return { tokens: 0, confidence: 'high' };
|
|
39
|
+
}
|
|
40
|
+
const contentType = this.detectContentType(text);
|
|
41
|
+
const charsPerToken = TokenEstimator.CHARS_PER_TOKEN[contentType];
|
|
42
|
+
// Count different parts
|
|
43
|
+
const whitespaceCount = (text.match(/\s/g) || []).length;
|
|
44
|
+
const structureCount = (text.match(/[{}\[\]":,]/g) || []).length;
|
|
45
|
+
const textCount = text.length - whitespaceCount - structureCount;
|
|
46
|
+
// Estimate each part
|
|
47
|
+
const textTokens = Math.ceil(textCount / charsPerToken);
|
|
48
|
+
const structureTokens = Math.ceil(structureCount / 2); // Structure chars are often single tokens
|
|
49
|
+
const whitespaceTokens = Math.ceil(whitespaceCount / 10); // Whitespace is heavily compressed
|
|
50
|
+
const totalTokens = textTokens + structureTokens + whitespaceTokens;
|
|
51
|
+
// Confidence based on content type
|
|
52
|
+
const confidence = contentType === 'json' ? 'high' :
|
|
53
|
+
contentType === 'code' ? 'medium' : 'medium';
|
|
54
|
+
return {
|
|
55
|
+
tokens: totalTokens,
|
|
56
|
+
confidence,
|
|
57
|
+
breakdown: {
|
|
58
|
+
text: textTokens,
|
|
59
|
+
structure: structureTokens,
|
|
60
|
+
whitespace: whitespaceTokens,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Estimate tokens for an object (will be JSON serialized)
|
|
66
|
+
*/
|
|
67
|
+
estimateObject(obj) {
|
|
68
|
+
return this.estimate(JSON.stringify(obj, null, 2));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if content fits within a token budget
|
|
72
|
+
*/
|
|
73
|
+
fitsInBudget(text, budget) {
|
|
74
|
+
return this.estimate(text) <= budget;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Truncate text to fit within token budget
|
|
78
|
+
*/
|
|
79
|
+
truncateToFit(text, budget, suffix = '...[truncated]') {
|
|
80
|
+
const currentTokens = this.estimate(text);
|
|
81
|
+
if (currentTokens <= budget) {
|
|
82
|
+
return text;
|
|
83
|
+
}
|
|
84
|
+
// Estimate how much to keep
|
|
85
|
+
const ratio = budget / currentTokens;
|
|
86
|
+
const targetLength = Math.floor(text.length * ratio * 0.9); // 10% safety margin
|
|
87
|
+
const suffixLength = suffix.length;
|
|
88
|
+
return text.slice(0, targetLength - suffixLength) + suffix;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Detect content type for better estimation
|
|
92
|
+
*/
|
|
93
|
+
detectContentType(text) {
|
|
94
|
+
// Check for JSON
|
|
95
|
+
if (text.trim().startsWith('{') || text.trim().startsWith('[')) {
|
|
96
|
+
try {
|
|
97
|
+
JSON.parse(text);
|
|
98
|
+
return 'json';
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Not valid JSON, continue checking
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Check for code indicators
|
|
105
|
+
const codeIndicators = [
|
|
106
|
+
/function\s+\w+/,
|
|
107
|
+
/const\s+\w+\s*=/,
|
|
108
|
+
/class\s+\w+/,
|
|
109
|
+
/import\s+.*from/,
|
|
110
|
+
/def\s+\w+\(/,
|
|
111
|
+
/=>/,
|
|
112
|
+
];
|
|
113
|
+
const codeMatches = codeIndicators.filter(pattern => pattern.test(text)).length;
|
|
114
|
+
if (codeMatches >= 2) {
|
|
115
|
+
return 'code';
|
|
116
|
+
}
|
|
117
|
+
// Check JSON-like structure ratio
|
|
118
|
+
const structureChars = (text.match(/[{}\[\]":,]/g) || []).length;
|
|
119
|
+
const structureRatio = structureChars / text.length;
|
|
120
|
+
if (structureRatio > 0.1) {
|
|
121
|
+
return 'json';
|
|
122
|
+
}
|
|
123
|
+
// Default to mixed
|
|
124
|
+
return 'mixed';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Singleton instance for convenience
|
|
129
|
+
*/
|
|
130
|
+
export const tokenEstimator = new TokenEstimator();
|
|
131
|
+
//# sourceMappingURL=token-estimator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-estimator.js","sourceRoot":"","sources":["../../src/infrastructure/token-estimator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,MAAM,OAAO,cAAc;IACzB,2DAA2D;IACnD,MAAM,CAAU,eAAe,GAAG;QACxC,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,GAAG;KACX,CAAC;IAEF,qCAAqC;IAC7B,MAAM,CAAU,aAAa,GAAG,IAAI,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,IAAY;QACnB,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC;QAEpB,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,aAAa,GAAG,cAAc,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAElE,mBAAmB;QACnB,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;QAEpD,kCAAkC;QAClC,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3B,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC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MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;QACH,CAAC;QAED,4BAA4B;QAC5B,MAAM,cAAc,GAAG;YACrB,gBAAgB;YAChB,iBAAiB;YACjB,aAAa;YACb,iBAAiB;YACjB,aAAa;YACb,IAAI;SACL,CAAC;QAEF,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;QAChF,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,kCAAkC;QAClC,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACjE,MAAM,cAAc,GAAG,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;QAEpD,IAAI,cAAc,GAAG,GAAG,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,mBAAmB;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC;;AAGH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAsCnE,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB;AA8eD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAwLnE"}
|