@nahisaho/musubix-pattern-mcp 1.0.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/dist/compression/index.d.ts +7 -0
- package/dist/compression/index.d.ts.map +1 -0
- package/dist/compression/index.js +7 -0
- package/dist/compression/index.js.map +1 -0
- package/dist/compression/pattern-compressor.d.ts +111 -0
- package/dist/compression/pattern-compressor.d.ts.map +1 -0
- package/dist/compression/pattern-compressor.js +307 -0
- package/dist/compression/pattern-compressor.js.map +1 -0
- package/dist/compression/quality-evaluator.d.ts +97 -0
- package/dist/compression/quality-evaluator.d.ts.map +1 -0
- package/dist/compression/quality-evaluator.js +210 -0
- package/dist/compression/quality-evaluator.js.map +1 -0
- package/dist/extractor/anti-unifier.d.ts +63 -0
- package/dist/extractor/anti-unifier.d.ts.map +1 -0
- package/dist/extractor/anti-unifier.js +167 -0
- package/dist/extractor/anti-unifier.js.map +1 -0
- package/dist/extractor/index.d.ts +9 -0
- package/dist/extractor/index.d.ts.map +1 -0
- package/dist/extractor/index.js +9 -0
- package/dist/extractor/index.js.map +1 -0
- package/dist/extractor/pattern-extractor.d.ts +58 -0
- package/dist/extractor/pattern-extractor.d.ts.map +1 -0
- package/dist/extractor/pattern-extractor.js +201 -0
- package/dist/extractor/pattern-extractor.js.map +1 -0
- package/dist/extractor/subtree-finder.d.ts +81 -0
- package/dist/extractor/subtree-finder.d.ts.map +1 -0
- package/dist/extractor/subtree-finder.js +155 -0
- package/dist/extractor/subtree-finder.js.map +1 -0
- package/dist/extractor/typescript-parser.d.ts +91 -0
- package/dist/extractor/typescript-parser.d.ts.map +1 -0
- package/dist/extractor/typescript-parser.js +219 -0
- package/dist/extractor/typescript-parser.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/learning/index.d.ts +6 -0
- package/dist/learning/index.d.ts.map +1 -0
- package/dist/learning/index.js +6 -0
- package/dist/learning/index.js.map +1 -0
- package/dist/learning/wake-sleep.d.ts +144 -0
- package/dist/learning/wake-sleep.d.ts.map +1 -0
- package/dist/learning/wake-sleep.js +312 -0
- package/dist/learning/wake-sleep.js.map +1 -0
- package/dist/library/index.d.ts +6 -0
- package/dist/library/index.d.ts.map +1 -0
- package/dist/library/index.js +6 -0
- package/dist/library/index.js.map +1 -0
- package/dist/library/pattern-library.d.ts +59 -0
- package/dist/library/pattern-library.d.ts.map +1 -0
- package/dist/library/pattern-library.js +139 -0
- package/dist/library/pattern-library.js.map +1 -0
- package/dist/privacy/index.d.ts +6 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +6 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/privacy/privacy-filter.d.ts +46 -0
- package/dist/privacy/privacy-filter.d.ts.map +1 -0
- package/dist/privacy/privacy-filter.js +105 -0
- package/dist/privacy/privacy-filter.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Privacy filter for pattern library
|
|
3
|
+
* @traceability TSK-PATTERN-007, REQ-PATTERN-001-F007
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULT_SENSITIVE_PATTERNS = [
|
|
6
|
+
// API keys and tokens
|
|
7
|
+
'api[_-]?key',
|
|
8
|
+
'secret[_-]?key',
|
|
9
|
+
'access[_-]?token',
|
|
10
|
+
'auth[_-]?token',
|
|
11
|
+
'bearer',
|
|
12
|
+
// Credentials
|
|
13
|
+
'password',
|
|
14
|
+
'passwd',
|
|
15
|
+
'credential',
|
|
16
|
+
// AWS
|
|
17
|
+
'aws[_-]?access',
|
|
18
|
+
'aws[_-]?secret',
|
|
19
|
+
// Private keys
|
|
20
|
+
'private[_-]?key',
|
|
21
|
+
'ssh[_-]?key',
|
|
22
|
+
// Database
|
|
23
|
+
'connection[_-]?string',
|
|
24
|
+
'database[_-]?url',
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Privacy filter to prevent sensitive data leakage
|
|
28
|
+
*
|
|
29
|
+
* @description
|
|
30
|
+
* - Filters patterns containing sensitive information
|
|
31
|
+
* - Blocks all external network communication
|
|
32
|
+
* - All data stays local (Article: privacy protection)
|
|
33
|
+
*/
|
|
34
|
+
export class PrivacyFilter {
|
|
35
|
+
config;
|
|
36
|
+
sensitiveRegexes;
|
|
37
|
+
constructor(config = {}) {
|
|
38
|
+
this.config = {
|
|
39
|
+
sensitivePatterns: config.sensitivePatterns ?? DEFAULT_SENSITIVE_PATTERNS,
|
|
40
|
+
blockExternalCommunication: config.blockExternalCommunication ?? true,
|
|
41
|
+
};
|
|
42
|
+
this.sensitiveRegexes = this.config.sensitivePatterns.map(p => new RegExp(p, 'i'));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if pattern contains sensitive data
|
|
46
|
+
*/
|
|
47
|
+
filter(pattern) {
|
|
48
|
+
// Check pattern name
|
|
49
|
+
for (const regex of this.sensitiveRegexes) {
|
|
50
|
+
if (regex.test(pattern.name)) {
|
|
51
|
+
return {
|
|
52
|
+
filtered: true,
|
|
53
|
+
reason: `Pattern name matches sensitive pattern: ${regex.source}`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Check AST values recursively
|
|
58
|
+
const sensitiveValue = this.findSensitiveValue(pattern.ast);
|
|
59
|
+
if (sensitiveValue) {
|
|
60
|
+
return {
|
|
61
|
+
filtered: true,
|
|
62
|
+
reason: `Pattern contains sensitive value: ${sensitiveValue.pattern}`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return { filtered: false };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Recursively check AST for sensitive values
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
findSensitiveValue(node) {
|
|
72
|
+
if (node.value) {
|
|
73
|
+
for (const regex of this.sensitiveRegexes) {
|
|
74
|
+
if (regex.test(node.value)) {
|
|
75
|
+
return { pattern: regex.source };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const child of node.children) {
|
|
80
|
+
if (typeof child === 'object' && child !== null) {
|
|
81
|
+
const result = this.findSensitiveValue(child);
|
|
82
|
+
if (result)
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Assert no external communication is allowed
|
|
90
|
+
* @throws Error if external communication is attempted
|
|
91
|
+
*/
|
|
92
|
+
assertNoExternalCommunication() {
|
|
93
|
+
if (this.config.blockExternalCommunication) {
|
|
94
|
+
// This is a policy assertion - actual network blocking
|
|
95
|
+
// would be implemented at the transport layer
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if external communication is blocked
|
|
100
|
+
*/
|
|
101
|
+
isExternalCommunicationBlocked() {
|
|
102
|
+
return this.config.blockExternalCommunication;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=privacy-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privacy-filter.js","sourceRoot":"","sources":["../../src/privacy/privacy-filter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,MAAM,0BAA0B,GAAG;IACjC,sBAAsB;IACtB,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,gBAAgB;IAChB,QAAQ;IACR,cAAc;IACd,UAAU;IACV,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,gBAAgB;IAChB,gBAAgB;IAChB,eAAe;IACf,iBAAiB;IACjB,aAAa;IACb,WAAW;IACX,uBAAuB;IACvB,kBAAkB;CACnB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;I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AO,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBAChD,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CACpC,KAA8D,CAC/D,CAAC;gBACF,IAAI,MAAM;oBAAE,OAAO,MAAM,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,6BAA6B;QAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,0BAA0B,EAAE,CAAC;YAC3C,uDAAuD;YACvD,8CAA8C;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,8BAA8B;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC;IAChD,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pattern MCP type definitions
|
|
3
|
+
* @traceability REQ-PATTERN-001
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* AST node representation for pattern extraction
|
|
7
|
+
*/
|
|
8
|
+
export interface ASTNode {
|
|
9
|
+
type: string;
|
|
10
|
+
children: ASTNode[];
|
|
11
|
+
value?: string;
|
|
12
|
+
startPosition: Position;
|
|
13
|
+
endPosition: Position;
|
|
14
|
+
}
|
|
15
|
+
export interface Position {
|
|
16
|
+
row: number;
|
|
17
|
+
column: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracted pattern structure
|
|
21
|
+
*/
|
|
22
|
+
export interface Pattern {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
language: string;
|
|
26
|
+
ast: ASTNode;
|
|
27
|
+
holes: PatternHole[];
|
|
28
|
+
frequency: number;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hole in abstract pattern (placeholder for variable parts)
|
|
34
|
+
*/
|
|
35
|
+
export interface PatternHole {
|
|
36
|
+
id: string;
|
|
37
|
+
type: string;
|
|
38
|
+
constraints?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pattern library configuration
|
|
42
|
+
*/
|
|
43
|
+
export interface PatternLibraryConfig {
|
|
44
|
+
storagePath: string;
|
|
45
|
+
maxPatterns: number;
|
|
46
|
+
enablePrivacyFilter: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Pattern extraction options
|
|
50
|
+
*/
|
|
51
|
+
export interface ExtractionOptions {
|
|
52
|
+
language: string;
|
|
53
|
+
minFrequency: number;
|
|
54
|
+
maxDepth: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Similarity calculation result
|
|
58
|
+
*/
|
|
59
|
+
export interface SimilarityResult {
|
|
60
|
+
patternA: string;
|
|
61
|
+
patternB: string;
|
|
62
|
+
score: number;
|
|
63
|
+
method: 'cosine' | 'jaccard' | 'structural';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Similarity matrix for batch calculations
|
|
67
|
+
*/
|
|
68
|
+
export interface SimilarityMatrix {
|
|
69
|
+
patternIds: string[];
|
|
70
|
+
scores: number[][];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Pattern cluster
|
|
74
|
+
*/
|
|
75
|
+
export interface PatternCluster {
|
|
76
|
+
id: string;
|
|
77
|
+
centroid: Pattern;
|
|
78
|
+
members: string[];
|
|
79
|
+
cohesion: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Privacy filter result
|
|
83
|
+
*/
|
|
84
|
+
export interface PrivacyFilterResult {
|
|
85
|
+
filtered: boolean;
|
|
86
|
+
reason?: string;
|
|
87
|
+
sanitizedPattern?: Pattern;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,QAAQ,CAAC;IACxB,WAAW,EAAE,QAAQ,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nahisaho/musubix-pattern-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MUSUBIX Pattern Library Learning MCP - AST-based pattern extraction and abstraction",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"musubix",
|
|
25
|
+
"pattern",
|
|
26
|
+
"mcp",
|
|
27
|
+
"ast",
|
|
28
|
+
"tree-sitter"
|
|
29
|
+
],
|
|
30
|
+
"author": "nahisaho",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/nahisaho/MUSUBIX.git",
|
|
35
|
+
"directory": "packages/pattern-mcp"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"typescript": "^5.7.0",
|
|
42
|
+
"vitest": "^3.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@nahisaho/musubix-core": "^1.2.0"
|
|
46
|
+
}
|
|
47
|
+
}
|