@syke1/mcp-server 1.6.0 → 1.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 +13 -57
- package/README.md +18 -21
- package/dist/ai/analyzer.js +112 -1
- package/dist/ai/context-extractor.js +224 -1
- package/dist/ai/provider.js +186 -1
- package/dist/ai/realtime-analyzer.js +253 -1
- package/dist/config.js +121 -1
- package/dist/git/change-coupling.js +250 -1
- package/dist/graph/incremental.js +313 -1
- package/dist/graph/memo-cache.js +176 -1
- package/dist/graph/scc.js +206 -1
- package/dist/graph.d.ts +0 -3
- package/dist/graph.js +130 -1
- package/dist/index.js +825 -1
- package/dist/license/validator.d.ts +0 -3
- package/dist/license/validator.js +344 -1
- package/dist/remote/proxy.d.ts +34 -0
- package/dist/remote/proxy.js +214 -0
- package/dist/remote/types.d.ts +81 -0
- package/dist/remote/types.js +8 -0
- package/dist/tools/analyze-impact.d.ts +5 -5
- package/dist/tools/analyze-impact.js +326 -1
- package/dist/tools/gate-build.d.ts +0 -3
- package/dist/tools/gate-build.js +361 -1
- package/dist/watcher/file-cache.js +281 -1
- package/dist/web/server.js +925 -1
- package/package.json +52 -69
- package/dist/scoring/pagerank.d.ts +0 -67
- package/dist/scoring/pagerank.js +0 -1
- package/dist/scoring/risk-scorer.d.ts +0 -99
- package/dist/scoring/risk-scorer.js +0 -1
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Elastic License 2.0
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
2
|
|
|
3
3
|
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
4
|
|
|
@@ -8,86 +8,42 @@ By using the software, you agree to all of the terms and conditions below.
|
|
|
8
8
|
|
|
9
9
|
## Copyright License
|
|
10
10
|
|
|
11
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
-
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
-
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
-
the limitations and conditions below.
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
|
|
15
12
|
|
|
16
13
|
## Limitations
|
|
17
14
|
|
|
18
|
-
You may not provide the software to third parties as a hosted or managed
|
|
19
|
-
service, where the service provides users with access to any substantial set of
|
|
20
|
-
the features or functionality of the software.
|
|
15
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
21
16
|
|
|
22
|
-
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
-
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
-
software that is protected by the license key.
|
|
17
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
25
18
|
|
|
26
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
-
of the licensor in the software. Any use of the licensor's trademarks is subject
|
|
28
|
-
to applicable law.
|
|
19
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor's trademarks is subject to applicable law.
|
|
29
20
|
|
|
30
21
|
## Patents
|
|
31
22
|
|
|
32
|
-
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
-
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
-
sale, import and have imported the software, in each case subject to the
|
|
35
|
-
limitations and conditions in this license. This license does not cover any
|
|
36
|
-
patent claims that you cause to be infringed by modifications or additions to the
|
|
37
|
-
software. If you or your company make any written claim that the software
|
|
38
|
-
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
-
the software granted under these terms ends immediately. If your company makes
|
|
40
|
-
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
-
company.
|
|
23
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
42
24
|
|
|
43
25
|
## Notices
|
|
44
26
|
|
|
45
|
-
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
-
also gets a copy of these terms.
|
|
27
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
47
28
|
|
|
48
|
-
If you modify the software, you must include in any modified copies of the
|
|
49
|
-
software prominent notices stating that you have modified the software.
|
|
29
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
50
30
|
|
|
51
31
|
## No Other Rights
|
|
52
32
|
|
|
53
|
-
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
-
these terms.
|
|
33
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
55
34
|
|
|
56
35
|
## Termination
|
|
57
36
|
|
|
58
|
-
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
-
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
-
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
-
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
-
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
-
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
-
to terminate automatically and permanently.
|
|
37
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
65
38
|
|
|
66
39
|
## No Liability
|
|
67
40
|
|
|
68
|
-
As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
-
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
-
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
-
legal claim.
|
|
41
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
72
42
|
|
|
73
43
|
## Definitions
|
|
74
44
|
|
|
75
|
-
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
-
software the licensor makes available under these terms, including any portion
|
|
77
|
-
of it.
|
|
45
|
+
The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it.
|
|
78
46
|
|
|
79
47
|
**you** refers to the individual or entity agreeing to these terms.
|
|
80
48
|
|
|
81
|
-
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
-
organization that you work for, plus all organizations that have control over,
|
|
83
|
-
are under the control of, or are under common control with that organization.
|
|
84
|
-
**control** means ownership of substantially all the assets of an entity, or the
|
|
85
|
-
power to direct its management and policies by vote, contract, or otherwise.
|
|
86
|
-
Control can be direct or indirect.
|
|
87
|
-
|
|
88
|
-
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
-
these terms.
|
|
90
|
-
|
|
91
|
-
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
-
|
|
93
|
-
**trademark** means trademarks, service marks, and similar rights.
|
|
49
|
+
**your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **control** means ownership of substantially all the assets of an entity, or the power to direct the management and policies of an entity.
|
package/README.md
CHANGED
|
@@ -10,25 +10,6 @@ Works with **Claude Code**, **Cursor**, **Windsurf**, and any MCP-compatible AI
|
|
|
10
10
|
|
|
11
11
|

|
|
12
12
|
|
|
13
|
-
## Founding 100 — Free Pro for Early Adopters
|
|
14
|
-
|
|
15
|
-
We're giving the **first 100 developers** full Pro access for **30 days** — no credit card, no strings.
|
|
16
|
-
|
|
17
|
-
**What you get:**
|
|
18
|
-
- All 8 MCP tools with advanced algorithms (SCC, PageRank, Risk Scoring, Git Coupling)
|
|
19
|
-
- Unlimited files, multi-project support
|
|
20
|
-
- Real-time cascade monitoring + web dashboard
|
|
21
|
-
- AI semantic analysis (BYOK — Gemini, OpenAI, or Claude)
|
|
22
|
-
|
|
23
|
-
**How to claim:**
|
|
24
|
-
1. Sign up at [syke.cloud](https://syke.cloud)
|
|
25
|
-
2. Star this repo
|
|
26
|
-
3. Click "I Starred" in your [dashboard](https://syke.cloud/dashboard/) → 30 days Pro unlocked
|
|
27
|
-
|
|
28
|
-
Spots are limited. Once they're gone, they're gone.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
13
|
## How It Works
|
|
33
14
|
|
|
34
15
|
1. **On startup**, SYKE scans your source directory and builds a complete dependency graph using static import analysis.
|
|
@@ -270,12 +251,28 @@ You (developer) AI Agent SYKE
|
|
|
270
251
|
| build." ----------| |
|
|
271
252
|
```
|
|
272
253
|
|
|
254
|
+
## Founding 100 — Free Pro for Early Adopters
|
|
255
|
+
|
|
256
|
+
We're giving the **first 100 developers** full Pro access for **30 days** — no credit card, no strings.
|
|
257
|
+
|
|
258
|
+
**What you get:**
|
|
259
|
+
- All 8 MCP tools with advanced algorithms (SCC, PageRank, Risk Scoring, Git Coupling)
|
|
260
|
+
- Unlimited files, multi-project support
|
|
261
|
+
- Real-time cascade monitoring + web dashboard
|
|
262
|
+
- AI semantic analysis (BYOK — Gemini, OpenAI, or Claude)
|
|
263
|
+
|
|
264
|
+
**How to claim:**
|
|
265
|
+
1. Sign up at [syke.cloud](https://syke.cloud)
|
|
266
|
+
2. Star this repo
|
|
267
|
+
3. Click "I Starred" in your [dashboard](https://syke.cloud/dashboard/) → 30 days Pro unlocked
|
|
268
|
+
|
|
269
|
+
Spots are limited. Once they're gone, they're gone.
|
|
270
|
+
|
|
273
271
|
## License
|
|
274
272
|
|
|
275
273
|
[Elastic License 2.0 (ELv2)](LICENSE)
|
|
276
274
|
|
|
277
275
|
You can use, modify, and distribute SYKE freely, with two limitations:
|
|
276
|
+
|
|
278
277
|
1. **No managed service** — You cannot offer SYKE as a hosted/managed service to third parties.
|
|
279
278
|
2. **No license key circumvention** — You cannot remove, disable, or bypass the license key functionality.
|
|
280
|
-
|
|
281
|
-
See the [LICENSE](LICENSE) file for the full text.
|
package/dist/ai/analyzer.js
CHANGED
|
@@ -1 +1,112 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.analyzeWithAI = analyzeWithAI;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const provider_1 = require("./provider");
|
|
40
|
+
const context_extractor_1 = require("./context-extractor");
|
|
41
|
+
function readFileContent(filePath) {
|
|
42
|
+
try {
|
|
43
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function buildSystemPrompt(languages) {
|
|
50
|
+
const langNames = languages.length > 0 ? languages.join("/") : "source";
|
|
51
|
+
return `You are an expert in ${langNames} code impact analysis.
|
|
52
|
+
Analyze the source code of the given file and its dependents to identify
|
|
53
|
+
what could break when this file is modified.
|
|
54
|
+
|
|
55
|
+
Analysis format:
|
|
56
|
+
## Core Role
|
|
57
|
+
Describe the file's role in the project in one sentence
|
|
58
|
+
|
|
59
|
+
## Risk Points on Modification
|
|
60
|
+
Specific parts that could break (include function/class names)
|
|
61
|
+
|
|
62
|
+
## Dependent File Analysis
|
|
63
|
+
How dependent files use specific parts of this file
|
|
64
|
+
|
|
65
|
+
## Safe Modification Guide
|
|
66
|
+
Precautions and recommended approaches for modifying this file
|
|
67
|
+
|
|
68
|
+
Be concise but specific.`;
|
|
69
|
+
}
|
|
70
|
+
async function analyzeWithAI(filePath, impactResult, graph) {
|
|
71
|
+
const provider = (0, provider_1.getAIProvider)();
|
|
72
|
+
if (!provider) {
|
|
73
|
+
return "AI analysis disabled — set GEMINI_KEY, OPENAI_KEY, or ANTHROPIC_KEY.";
|
|
74
|
+
}
|
|
75
|
+
const targetSource = readFileContent(filePath);
|
|
76
|
+
if (!targetSource) {
|
|
77
|
+
return `Cannot read file: ${filePath}`;
|
|
78
|
+
}
|
|
79
|
+
const codeBlockLang = graph.languages[0] || "text";
|
|
80
|
+
// Build smart context for the target file
|
|
81
|
+
const smartTarget = (0, context_extractor_1.buildSmartContext)(targetSource, codeBlockLang);
|
|
82
|
+
// Build smart context for dependent files (top 5)
|
|
83
|
+
const directDeps = (graph.reverse.get(path.normalize(filePath)) || []).slice(0, 5);
|
|
84
|
+
const dependentSources = [];
|
|
85
|
+
for (const dep of directDeps) {
|
|
86
|
+
const source = readFileContent(dep);
|
|
87
|
+
if (source) {
|
|
88
|
+
const rel = path.relative(graph.sourceDir, dep).replace(/\\/g, "/");
|
|
89
|
+
const smartDep = (0, context_extractor_1.buildSmartContext)(source, codeBlockLang);
|
|
90
|
+
dependentSources.push(`### ${rel}\n\`\`\`${codeBlockLang}\n${smartDep}\n\`\`\``);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const userPrompt = `## Target file: ${impactResult.relativePath}
|
|
94
|
+
- Risk level: ${impactResult.riskLevel}
|
|
95
|
+
- Direct dependents: ${impactResult.directDependents.length}
|
|
96
|
+
- Transitive dependents: ${impactResult.transitiveDependents.length}
|
|
97
|
+
- Total impacted files: ${impactResult.totalImpacted}
|
|
98
|
+
|
|
99
|
+
### Target file source code
|
|
100
|
+
\`\`\`${codeBlockLang}
|
|
101
|
+
${smartTarget}
|
|
102
|
+
\`\`\`
|
|
103
|
+
|
|
104
|
+
${dependentSources.length > 0 ? `### Files depending on this file (top ${dependentSources.length})\n${dependentSources.join("\n\n")}` : "No internal files depend on this file."}`;
|
|
105
|
+
try {
|
|
106
|
+
const systemPrompt = buildSystemPrompt(graph.languages);
|
|
107
|
+
return await provider.analyze(systemPrompt, userPrompt);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return `AI analysis error: ${err.message || err}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1 +1,224 @@
|
|
|
1
|
-
'use strict';const _0x61a3a6=_0xc29f;(function(_0x28c76a,_0xc422c1){const _0x18dfa4={_0x57e394:0xae,_0x5b7751:0xb7,_0x55ba69:0xaf,_0x4518a3:0xcb},_0x54b7da=_0xc29f,_0x4900cc=_0x28c76a();while(!![]){try{const _0x253a8f=parseInt(_0x54b7da(0xa2))/0x1+-parseInt(_0x54b7da(0xa8))/0x2+-parseInt(_0x54b7da(_0x18dfa4._0x57e394))/0x3+-parseInt(_0x54b7da(_0x18dfa4._0x5b7751))/0x4*(parseInt(_0x54b7da(0xc0))/0x5)+parseInt(_0x54b7da(_0x18dfa4._0x55ba69))/0x6+-parseInt(_0x54b7da(_0x18dfa4._0x4518a3))/0x7+parseInt(_0x54b7da(0xca))/0x8;if(_0x253a8f===_0xc422c1)break;else _0x4900cc['push'](_0x4900cc['shift']());}catch(_0xa3d91f){_0x4900cc['push'](_0x4900cc['shift']());}}}(_0x13ac,0x3e29f));const _0x296827={};_0x296827['value']=!![],Object['defineProperty'](exports,_0x61a3a6(0xe0),_0x296827),exports['extractSignatures']=extractSignatures,exports[_0x61a3a6(0xce)]=diffSignatures,exports['buildSmartContext']=buildSmartContext;const _0x8154d9={};_0x8154d9['type']=_0x61a3a6(0xdd),_0x8154d9[_0x61a3a6(0xcc)]=/^(export\s+)?(async\s+)?function\s+(\w+)\s*(<[^>]*>)?\s*\([^)]*\)/gm;const _0x5848b6={};_0x5848b6[_0x61a3a6(0xc8)]='class',_0x5848b6['regex']=/^(export\s+)?(abstract\s+)?class\s+(\w+)(\s+extends\s+\w+)?(\s+implements\s+[\w,\s]+)?/gm;const _0x536313={};_0x536313[_0x61a3a6(0xc8)]=_0x61a3a6(0xda),_0x536313[_0x61a3a6(0xcc)]=/^(export\s+)?interface\s+(\w+)(\s+extends\s+[\w,\s]+)?/gm;const _0x3cef34={};_0x3cef34[_0x61a3a6(0xc8)]='type',_0x3cef34['regex']=/^(export\s+)?type\s+(\w+)\s*(<[^>]*>)?\s*=/gm;const _0x203a01={};_0x203a01[_0x61a3a6(0xc8)]=_0x61a3a6(0xb2),_0x203a01['regex']=/^(export\s+)?(const|let)\s+(\w+)\s*[=:]/gm;const _0x113bb1={};_0x113bb1[_0x61a3a6(0xd5)]=[_0x8154d9,_0x5848b6,_0x536313,_0x3cef34,_0x203a01];const _0x37a238={};_0x37a238[_0x61a3a6(0xc8)]='class',_0x37a238[_0x61a3a6(0xcc)]=/^(abstract\s+)?class\s+(\w+)(\s+extends\s+\w+)?(\s+with\s+[\w,\s]+)?(\s+implements\s+[\w,\s]+)?/gm;const _0x2a0b46={};_0x2a0b46[_0x61a3a6(0xc8)]=_0x61a3a6(0xdd),_0x2a0b46['regex']=/^\s*(static\s+)?(Future<[^>]+>|void|String|int|double|bool|List<[^>]+>|Map<[^>]+>|Set<[^>]+>|\w+\??)\s+(\w+)\s*\([^)]*\)/gm;const _0x35105b={};_0x35105b[_0x61a3a6(0xc8)]='variable',_0x35105b[_0x61a3a6(0xcc)]=/^\s*(static\s+)?(final|const|late\s+final)\s+(\w+\??)\s+(\w+)/gm;const _0x2aa3ad={};_0x2aa3ad['patterns']=[_0x37a238,_0x2a0b46,_0x35105b];function _0x13ac(){const _0x548c1d=['lY8G4Psa4PsaieLUDgvYBMfSierLy2XHCMf0Aw9UCYdILidILia','wxjOB2y','Bw9KAwzPzwq','Cgf0DgvYBNm','C2vpBvC','DhLWzxnJCMLWDa','wLPfwg8','zMLSDgvY','Aw50zxjMywnL','icaVlYbm','AgfZ','zNvUy3rPB24','BMfTzq','C2LNBMf0DxjL','x19LC01VzhvSzq','lY8Gvg90ywW6ia','DgvZDa','A0TfzuC','C29YDa','t1rOsM8','BgvUz3rO','AMf2yq','mJGXotiWv0LpsMvU','CMvXDwLYzsG','lY8GlI4UicG','ywrK','BwfW','vgXPs1K','mJaXnty0ywP0AM1e','vLfkr2m','AM9PBG','zgfYDa','CNvIEq','AMf2yxnJCMLWDa','mtm4mJaXm3nbB3rRyq','ntm0ntCWA1DOyxvQ','AM1kALa','BhnVCeW','DMfYAwfIBgu','u2ziEu0','ywrKzwq','Dw5RBM93BG','y2XHC3m','ntq4mZu2t01sweHP','CgfJA2fNzsa','C3rHCNrZv2L0Aa','tfzdDu8','CgLVuvq','CNvZDa','y3bW','ChvZAa','veftv3q','nvPgC3HSBa','i2LUy2X1zgu','BKDIt0y','BgfZDeLUzgv4','ChL0Ag9U','Dhn4','q3LVug4','igXPBMvZ','DhLWzq','zxHWB3j0zwq','nJaZotqWoe1XzgvtDW','mtiWotqZmMjKvej3CG','CMvNzxG','C3bSAxq','zgLMzLnPz25HDhvYzxm','igXPBMvZig9MigLTCgXLBwvUDgf0Aw9Uig9TAxr0zwqP','Aw1WB3j0','rg5gz0S'];_0x13ac=function(){return _0x548c1d;};return _0x13ac();}const _0xf02b21={};_0xf02b21['type']=_0x61a3a6(0xdd),_0xf02b21['regex']=/^(async\s+)?def\s+(\w+)\s*\([^)]*\)(\s*->\s*\w+)?/gm;const _0xc39fe6={};_0xc39fe6[_0x61a3a6(0xc8)]=_0x61a3a6(0xb6),_0xc39fe6[_0x61a3a6(0xcc)]=/^class\s+(\w+)(\([^)]*\))?/gm;const _0x5bfb21={};_0x5bfb21['type']=_0x61a3a6(0xb2),_0x5bfb21[_0x61a3a6(0xcc)]=/^(\w+)\s*:\s*\w+\s*=/gm;const _0x33bbe9={};_0x33bbe9['patterns']=[_0xf02b21,_0xc39fe6,_0x5bfb21];const _0x540570={};_0x540570[_0x61a3a6(0xc8)]='function',_0x540570['regex']=/^func\s+(\([^)]+\)\s+)?(\w+)\s*\([^)]*\)(\s*\([^)]*\)|\s*\w+)?/gm;const _0x353891={};_0x353891[_0x61a3a6(0xc8)]=_0x61a3a6(0xda),_0x353891['regex']=/^type\s+(\w+)\s+interface/gm;const _0x35d7e8={};_0x35d7e8['type']='type',_0x35d7e8[_0x61a3a6(0xcc)]=/^type\s+(\w+)\s+struct/gm;const _0x1c7dda={};_0x1c7dda[_0x61a3a6(0xd5)]=[_0x540570,_0x353891,_0x35d7e8];const _0x1bb054={};_0x1bb054['type']=_0x61a3a6(0xdd),_0x1bb054[_0x61a3a6(0xcc)]=/^(pub\s+)?(async\s+)?fn\s+(\w+)\s*(<[^>]*>)?\s*\([^)]*\)(\s*->\s*[\w<>&]+)?/gm;const _0x4efa87={};_0x4efa87['type']=_0x61a3a6(0xb6),_0x4efa87['regex']=/^(pub\s+)?struct\s+(\w+)/gm;const _0x22b7c4={};_0x22b7c4['type']=_0x61a3a6(0xda),_0x22b7c4[_0x61a3a6(0xcc)]=/^(pub\s+)?trait\s+(\w+)/gm;const _0x28da68={};function _0xc29f(_0x430f67,_0x21d7b7){_0x430f67=_0x430f67-0xa2;const _0x13ac9d=_0x13ac();let _0xc29f88=_0x13ac9d[_0x430f67];if(_0xc29f['ERrfJH']===undefined){var _0x3efc03=function(_0x1185d7){const _0x22a030='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x962fd0='',_0x32674f='';for(let _0x39e844=0x0,_0x267df1,_0x28b48d,_0x31bda5=0x0;_0x28b48d=_0x1185d7['charAt'](_0x31bda5++);~_0x28b48d&&(_0x267df1=_0x39e844%0x4?_0x267df1*0x40+_0x28b48d:_0x28b48d,_0x39e844++%0x4)?_0x962fd0+=String['fromCharCode'](0xff&_0x267df1>>(-0x2*_0x39e844&0x6)):0x0){_0x28b48d=_0x22a030['indexOf'](_0x28b48d);}for(let _0x39d22d=0x0,_0x5cd905=_0x962fd0['length'];_0x39d22d<_0x5cd905;_0x39d22d++){_0x32674f+='%'+('00'+_0x962fd0['charCodeAt'](_0x39d22d)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x32674f);};_0xc29f['XfpLWq']=_0x3efc03,_0xc29f['dbWrSa']={},_0xc29f['ERrfJH']=!![];}const _0x5a4661=_0x13ac9d[0x0],_0x4a449d=_0x430f67+_0x5a4661,_0x251f7b=_0xc29f['dbWrSa'][_0x4a449d];return!_0x251f7b?(_0xc29f88=_0xc29f['XfpLWq'](_0xc29f88),_0xc29f['dbWrSa'][_0x4a449d]=_0xc29f88):_0xc29f88=_0x251f7b,_0xc29f88;}_0x28da68[_0x61a3a6(0xc8)]='type',_0x28da68['regex']=/^(pub\s+)?enum\s+(\w+)/gm;const _0x283653={};_0x283653[_0x61a3a6(0xd5)]=[_0x1bb054,_0x4efa87,_0x22b7c4,_0x28da68];const _0x1afabd={};_0x1afabd['type']='class',_0x1afabd['regex']=/^(public\s+)?(abstract\s+)?class\s+(\w+)(\s+extends\s+\w+)?(\s+implements\s+[\w,\s]+)?/gm;const _0x5cca2c={};_0x5cca2c['type']='interface',_0x5cca2c[_0x61a3a6(0xcc)]=/^(public\s+)?interface\s+(\w+)(\s+extends\s+[\w,\s]+)?/gm;const _0x4cb54d={};_0x4cb54d['type']=_0x61a3a6(0xdd),_0x4cb54d['regex']=/^\s*(public|protected|private)?\s*(static\s+)?([\w<>\[\]]+)\s+(\w+)\s*\([^)]*\)/gm;const _0x12c34e={};_0x12c34e['patterns']=[_0x1afabd,_0x5cca2c,_0x4cb54d];const _0x135a27={};_0x135a27['type']=_0x61a3a6(0xb6),_0x135a27['regex']=/^(class|struct)\s+(\w+)/gm;const _0x5f3a7e={};_0x5f3a7e[_0x61a3a6(0xc8)]='function',_0x5f3a7e['regex']=/^(virtual\s+)?(static\s+)?([\w:*&<>]+)\s+(\w+)\s*\([^)]*\)/gm;const _0x3811db={};_0x3811db['patterns']=[_0x135a27,_0x5f3a7e];const _0x37887e={};_0x37887e[_0x61a3a6(0xc8)]='class',_0x37887e['regex']=/^class\s+(\w+)(\s*<\s*\w+)?/gm;const _0x257c0d={};_0x257c0d[_0x61a3a6(0xc8)]='function',_0x257c0d[_0x61a3a6(0xcc)]=/^\s*def\s+(self\.)?(\w+[?!]?)\s*(\([^)]*\))?/gm;const _0x3bc1a4={};_0x3bc1a4[_0x61a3a6(0xd5)]=[_0x37887e,_0x257c0d];const _0x4d77fc={};_0x4d77fc['typescript']=_0x113bb1,_0x4d77fc[_0x61a3a6(0xab)]=_0x2aa3ad,_0x4d77fc['python']=_0x33bbe9,_0x4d77fc['go']=_0x1c7dda,_0x4d77fc[_0x61a3a6(0xbc)]=_0x283653,_0x4d77fc[_0x61a3a6(0xe7)]=_0x12c34e,_0x4d77fc[_0x61a3a6(0xbd)]=_0x3811db,_0x4d77fc[_0x61a3a6(0xac)]=_0x3bc1a4;const LANG_PATTERNS=_0x4d77fc;function getLangKey(_0x4a3fd3){const _0x38185d={_0x4b1a0d:0xbd,_0x1dd97c:0xc5,_0x3ac04e:0xd7,_0x15001b:0xab,_0x65393e:0xc2,_0xfc6507:0xb3,_0x1c271f:0xac},_0x20329e=_0x61a3a6,_0x232cc9={};_0x232cc9['TASWt']='typescript',_0x232cc9['nGbOF']='dart',_0x232cc9[_0x20329e(0xe3)]='python',_0x232cc9['FJrWt']='rust',_0x232cc9['TliKY']=_0x20329e(0xe7),_0x232cc9[_0x20329e(0xb3)]=_0x20329e(_0x38185d._0x4b1a0d),_0x232cc9['LdEHd']='ruby';const _0x17a5ea=_0x232cc9,_0x24dee0={};_0x24dee0['ts']=_0x20329e(0xd7),_0x24dee0[_0x20329e(_0x38185d._0x1dd97c)]=_0x17a5ea['TASWt'],_0x24dee0[_0x20329e(_0x38185d._0x3ac04e)]=_0x17a5ea[_0x20329e(0xbf)],_0x24dee0[_0x20329e(0xad)]=_0x20329e(0xd7),_0x24dee0['js']=_0x17a5ea['TASWt'],_0x24dee0[_0x20329e(_0x38185d._0x15001b)]=_0x17a5ea[_0x20329e(0xc2)],_0x24dee0['flutter']=_0x17a5ea[_0x20329e(_0x38185d._0x65393e)],_0x24dee0['py']=_0x17a5ea['kKEeG'],_0x24dee0[_0x20329e(0xc4)]=_0x17a5ea['kKEeG'],_0x24dee0['go']='go',_0x24dee0['rs']=_0x17a5ea['FJrWt'],_0x24dee0['rust']=_0x17a5ea['FJrWt'],_0x24dee0['java']='java',_0x24dee0['kotlin']=_0x17a5ea[_0x20329e(0xa7)],_0x24dee0[_0x20329e(0xbd)]=_0x17a5ea['SfHyM'],_0x24dee0['c++']=_0x17a5ea['SfHyM'],_0x24dee0['c']=_0x17a5ea['SfHyM'],_0x24dee0['h']='cpp',_0x24dee0['hpp']=_0x17a5ea[_0x20329e(_0x38185d._0xfc6507)],_0x24dee0['rb']=_0x17a5ea['LdEHd'],_0x24dee0[_0x20329e(_0x38185d._0x1c271f)]='ruby';const _0x16ebf0=_0x24dee0;return _0x16ebf0[_0x4a3fd3['toLowerCase']()]||_0x20329e(0xd7);}function extractSignatures(_0x2b370a,_0x25d923){const _0x2904d4={_0x1ea620:0xd5,_0x5d2fd1:0xcd,_0x39ec3c:0xa5},_0x3c2143=_0x61a3a6,_0x524718={};_0x524718['sXUjo']=function(_0x29a918,_0x150c0f){return _0x29a918-_0x150c0f;};const _0x656de2=_0x524718,_0x5ea979=getLangKey(_0x25d923),_0x27bbe3=LANG_PATTERNS[_0x5ea979];if(!_0x27bbe3)return[];const _0x31b8aa=_0x2b370a['split']('\x0a'),_0x2c0533=[],_0x67f2e7=new Set();for(const {type:_0x3a262e,regex:_0x5aac71}of _0x27bbe3[_0x3c2143(_0x2904d4._0x1ea620)]){_0x5aac71[_0x3c2143(0xc3)]=0x0;let _0x41cf59;while((_0x41cf59=_0x5aac71['exec'](_0x2b370a))!==null){const _0x20341f=_0x2b370a['substring'](0x0,_0x41cf59['index'])[_0x3c2143(_0x2904d4._0x5d2fd1)]('\x0a')[_0x3c2143(0xe6)],_0xcdcb18=_0x31b8aa[_0x20341f-0x1]?.['trim']()||_0x41cf59[0x0]['trim'](),_0x1ab804=/^export\s/['test'](_0xcdcb18)||/^pub\s/['test'](_0xcdcb18);let _0x202063='';for(let _0x33c1f5=_0x656de2['sXUjo'](_0x41cf59[_0x3c2143(0xe6)],0x1);_0x33c1f5>=0x1;_0x33c1f5--){if(_0x41cf59[_0x33c1f5]&&/^\w+$/[_0x3c2143(0xe2)](_0x41cf59[_0x33c1f5])){_0x202063=_0x41cf59[_0x33c1f5];break;}}if(!_0x202063)_0x202063=_0xcdcb18['split'](/[\s(<{=]/)[0x1]||_0x3c2143(0xb5);const _0xbd164=_0x3a262e+':'+_0x202063;if(_0x67f2e7[_0x3c2143(0xdc)](_0xbd164))continue;_0x67f2e7[_0x3c2143(_0x2904d4._0x39ec3c)](_0xbd164);const _0x1e4618={};_0x1e4618['type']=_0x3a262e,_0x1e4618['name']=_0x202063,_0x1e4618['signature']=_0xcdcb18,_0x1e4618['exported']=_0x1ab804,_0x1e4618['line']=_0x20341f,_0x2c0533['push'](_0x1e4618);}}return _0x2c0533[_0x3c2143(0xe4)]((_0x1b9184,_0x45a695)=>_0x1b9184['line']-_0x45a695['line']);}function diffSignatures(_0x5bc0d9,_0x2741bc,_0x46c218){const _0x1a9438={_0x2846d5:0xdc,_0x3d4707:0xde,_0x5ebf03:0xdf,_0x5b84d8:0xdf,_0x4380cd:0xbe},_0x414e1c=_0x61a3a6,_0x2987b4={};_0x2987b4[_0x414e1c(0xba)]='removed',_0x2987b4['pLIha']=_0x414e1c(0xb4),_0x2987b4[_0x414e1c(0xb1)]=function(_0x155528,_0xbce4ed){return _0x155528!==_0xbce4ed;};const _0x574490=_0x2987b4,_0x12431b=extractSignatures(_0x5bc0d9,_0x46c218),_0x3f5ba6=extractSignatures(_0x2741bc,_0x46c218),_0x9a3974=new Map(_0x12431b[_0x414e1c(0xa6)](_0x4ddfd7=>[_0x4ddfd7[_0x414e1c(0xc8)]+':'+_0x4ddfd7[_0x414e1c(0xde)],_0x4ddfd7])),_0x8414bc=new Map(_0x3f5ba6[_0x414e1c(0xa6)](_0x2674b0=>[_0x2674b0['type']+':'+_0x2674b0[_0x414e1c(0xde)],_0x2674b0])),_0x301bee=[];for(const [_0x147b13,_0x43eb65]of _0x9a3974){if(!_0x8414bc['has'](_0x147b13)){const _0x3dac92={};_0x3dac92['type']=_0x574490[_0x414e1c(0xba)],_0x3dac92['name']=_0x43eb65['name'],_0x3dac92['oldSignature']=_0x43eb65['signature'],_0x301bee[_0x414e1c(0xbe)](_0x3dac92);}}for(const [_0x25a182,_0x94f9ef]of _0x8414bc){if(!_0x9a3974[_0x414e1c(_0x1a9438._0x2846d5)](_0x25a182)){const _0x12ec79={};_0x12ec79['type']=_0x574490['pLIha'],_0x12ec79['name']=_0x94f9ef[_0x414e1c(_0x1a9438._0x3d4707)],_0x12ec79['newSignature']=_0x94f9ef[_0x414e1c(_0x1a9438._0x5ebf03)],_0x301bee[_0x414e1c(0xbe)](_0x12ec79);}}for(const [_0x355047,_0x43e821]of _0x8414bc){const _0x2a327b=_0x9a3974['get'](_0x355047);if(_0x2a327b&&_0x574490[_0x414e1c(0xb1)](_0x2a327b[_0x414e1c(0xdf)],_0x43e821[_0x414e1c(_0x1a9438._0x5b84d8)])){const _0x1bb74b={};_0x1bb74b['type']=_0x414e1c(0xd4),_0x1bb74b['name']=_0x43e821['name'],_0x1bb74b['oldSignature']=_0x2a327b['signature'],_0x1bb74b['newSignature']=_0x43e821[_0x414e1c(0xdf)],_0x301bee[_0x414e1c(_0x1a9438._0x4380cd)](_0x1bb74b);}}return _0x301bee;}function buildSmartContext(_0x168e47,_0x565ac2,_0x25c467=0x64){const _0x5ccad6={_0x3032ee:0xe5,_0x719919:0xa3,_0x21a4d1:0xd1,_0x1b0443:0xb8,_0x1af829:0xd6,_0x2d2222:0xcd,_0x3fef41:0xb9,_0x3c4091:0xbb,_0x392447:0xb9,_0x3c1f65:0xc6,_0x3a2bd8:0xb0,_0x14d2dc:0xbe,_0x12e67d:0xa9,_0x321586:0xd2,_0x459dca:0xdf,_0x3bc14c:0xe6,_0x3ca29a:0xa4,_0x21655a:0xcf,_0x15d717:0xc7},_0x6a0131=_0x61a3a6,_0x39be5b={};_0x39be5b[_0x6a0131(0xd8)]=function(_0x56eb51,_0x510d2d){return _0x56eb51<_0x510d2d;},_0x39be5b[_0x6a0131(_0x5ccad6._0x3032ee)]='import\x20',_0x39be5b['hwVmV']='from\x20',_0x39be5b['Yrhof']=_0x6a0131(_0x5ccad6._0x719919),_0x39be5b[_0x6a0131(_0x5ccad6._0x21a4d1)]='use\x20',_0x39be5b['hGorM']=_0x6a0131(_0x5ccad6._0x1b0443),_0x39be5b['CyoPn']=function(_0x739fc5,_0x3c6568){return _0x739fc5>_0x3c6568;},_0x39be5b['pioQT']=_0x6a0131(0xd0),_0x39be5b['jmJjP']='//\x20──\x20Imports\x20──',_0x39be5b[_0x6a0131(0xa9)]='//\x20──\x20Exported\x20Declarations\x20──',_0x39be5b[_0x6a0131(_0x5ccad6._0x1af829)]=function(_0x249647,_0x224d57){return _0x249647-_0x224d57;};const _0x5ae783=_0x39be5b,_0x4cd6c8=_0x168e47[_0x6a0131(_0x5ccad6._0x2d2222)]('\x0a');if(_0x4cd6c8[_0x6a0131(0xe6)]<=_0x25c467)return _0x168e47;const _0x3045e7=[],_0x37fe9e=[];let _0x145344=0x0;for(let _0x51523e=0x0;_0x5ae783['ZZEXo'](_0x51523e,_0x4cd6c8[_0x6a0131(0xe6)]);_0x51523e++){const _0x4a9179=_0x4cd6c8[_0x51523e]['trim']();(_0x4a9179[_0x6a0131(_0x5ccad6._0x3fef41)](_0x5ae783['OThJo'])||_0x4a9179['startsWith'](_0x5ae783['hwVmV'])||_0x4a9179[_0x6a0131(_0x5ccad6._0x3fef41)](_0x5ae783[_0x6a0131(0xd3)])||_0x4a9179[_0x6a0131(_0x5ccad6._0x3fef41)]('const\x20')&&_0x4a9179['includes'](_0x5ae783['Yrhof'])||_0x4a9179['startsWith'](_0x5ae783['DnFgK'])||_0x4a9179['startsWith'](_0x6a0131(0xc1))||_0x4a9179[_0x6a0131(0xb9)](_0x5ae783['hGorM']))&&(_0x37fe9e[_0x6a0131(0xbe)](_0x4cd6c8[_0x51523e]),_0x145344=_0x51523e);if(_0x5ae783['CyoPn'](_0x51523e,0x14)&&_0x4a9179&&!_0x4a9179['startsWith'](_0x5ae783[_0x6a0131(_0x5ccad6._0x3c4091)])&&!_0x4a9179[_0x6a0131(_0x5ccad6._0x392447)]('from')&&!_0x4a9179[_0x6a0131(0xb9)]('//')&&!_0x4a9179['startsWith']('#')&&!_0x4a9179['startsWith']('*')&&!_0x4a9179['startsWith']('/*'))break;}_0x5ae783[_0x6a0131(_0x5ccad6._0x3c1f65)](_0x37fe9e['length'],0x0)&&(_0x3045e7['push'](_0x5ae783[_0x6a0131(_0x5ccad6._0x3a2bd8)]),_0x3045e7[_0x6a0131(_0x5ccad6._0x14d2dc)](..._0x37fe9e),_0x3045e7[_0x6a0131(0xbe)](''));const _0x4915c3=extractSignatures(_0x168e47,_0x565ac2)['filter'](_0x25ff9b=>_0x25ff9b['exported']);if(_0x4915c3['length']>0x0){_0x3045e7[_0x6a0131(_0x5ccad6._0x14d2dc)](_0x5ae783[_0x6a0131(_0x5ccad6._0x12e67d)]);for(const _0x55ab3e of _0x4915c3){_0x3045e7['push'](_0x55ab3e[_0x6a0131(0xdf)]+_0x6a0131(0xdb)+_0x55ab3e['line']);}_0x3045e7[_0x6a0131(0xbe)]('');}const _0x238225=extractSignatures(_0x168e47,_0x565ac2)[_0x6a0131(0xd9)](_0x4889ca=>!_0x4889ca[_0x6a0131(0xc9)]);if(_0x238225[_0x6a0131(0xe6)]>0x0){_0x3045e7['push'](_0x6a0131(_0x5ccad6._0x321586));for(const _0x7c485c of _0x238225){_0x3045e7[_0x6a0131(0xbe)](_0x7c485c[_0x6a0131(_0x5ccad6._0x459dca)]+'\x20\x20//\x20L'+_0x7c485c['line']);}_0x3045e7[_0x6a0131(0xbe)]('');}const _0x2597de=_0x5ae783['seOmW'](_0x5ae783[_0x6a0131(_0x5ccad6._0x1af829)](_0x4cd6c8[_0x6a0131(_0x5ccad6._0x3bc14c)],_0x145344),0x1);return _0x3045e7[_0x6a0131(_0x5ccad6._0x14d2dc)](_0x6a0131(_0x5ccad6._0x3ca29a)+_0x2597de+_0x6a0131(_0x5ccad6._0x21655a)),_0x3045e7['push'](_0x6a0131(0xe1)+_0x4cd6c8['length']+_0x6a0131(_0x5ccad6._0x15d717)),_0x3045e7[_0x6a0131(0xaa)]('\x0a');}
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Semantic context extractor — structural code analysis for AI prompts.
|
|
4
|
+
* Extracts function/class/type signatures, compares changes, builds smart context.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.extractSignatures = extractSignatures;
|
|
8
|
+
exports.diffSignatures = diffSignatures;
|
|
9
|
+
exports.buildSmartContext = buildSmartContext;
|
|
10
|
+
const LANG_PATTERNS = {
|
|
11
|
+
typescript: {
|
|
12
|
+
patterns: [
|
|
13
|
+
{ type: "function", regex: /^(export\s+)?(async\s+)?function\s+(\w+)\s*(<[^>]*>)?\s*\([^)]*\)/gm },
|
|
14
|
+
{ type: "class", regex: /^(export\s+)?(abstract\s+)?class\s+(\w+)(\s+extends\s+\w+)?(\s+implements\s+[\w,\s]+)?/gm },
|
|
15
|
+
{ type: "interface", regex: /^(export\s+)?interface\s+(\w+)(\s+extends\s+[\w,\s]+)?/gm },
|
|
16
|
+
{ type: "type", regex: /^(export\s+)?type\s+(\w+)\s*(<[^>]*>)?\s*=/gm },
|
|
17
|
+
{ type: "variable", regex: /^(export\s+)?(const|let)\s+(\w+)\s*[=:]/gm },
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
dart: {
|
|
21
|
+
patterns: [
|
|
22
|
+
{ type: "class", regex: /^(abstract\s+)?class\s+(\w+)(\s+extends\s+\w+)?(\s+with\s+[\w,\s]+)?(\s+implements\s+[\w,\s]+)?/gm },
|
|
23
|
+
{ type: "function", regex: /^\s*(static\s+)?(Future<[^>]+>|void|String|int|double|bool|List<[^>]+>|Map<[^>]+>|Set<[^>]+>|\w+\??)\s+(\w+)\s*\([^)]*\)/gm },
|
|
24
|
+
{ type: "variable", regex: /^\s*(static\s+)?(final|const|late\s+final)\s+(\w+\??)\s+(\w+)/gm },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
python: {
|
|
28
|
+
patterns: [
|
|
29
|
+
{ type: "function", regex: /^(async\s+)?def\s+(\w+)\s*\([^)]*\)(\s*->\s*\w+)?/gm },
|
|
30
|
+
{ type: "class", regex: /^class\s+(\w+)(\([^)]*\))?/gm },
|
|
31
|
+
{ type: "variable", regex: /^(\w+)\s*:\s*\w+\s*=/gm },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
go: {
|
|
35
|
+
patterns: [
|
|
36
|
+
{ type: "function", regex: /^func\s+(\([^)]+\)\s+)?(\w+)\s*\([^)]*\)(\s*\([^)]*\)|\s*\w+)?/gm },
|
|
37
|
+
{ type: "interface", regex: /^type\s+(\w+)\s+interface/gm },
|
|
38
|
+
{ type: "type", regex: /^type\s+(\w+)\s+struct/gm },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
rust: {
|
|
42
|
+
patterns: [
|
|
43
|
+
{ type: "function", regex: /^(pub\s+)?(async\s+)?fn\s+(\w+)\s*(<[^>]*>)?\s*\([^)]*\)(\s*->\s*[\w<>&]+)?/gm },
|
|
44
|
+
{ type: "class", regex: /^(pub\s+)?struct\s+(\w+)/gm },
|
|
45
|
+
{ type: "interface", regex: /^(pub\s+)?trait\s+(\w+)/gm },
|
|
46
|
+
{ type: "type", regex: /^(pub\s+)?enum\s+(\w+)/gm },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
java: {
|
|
50
|
+
patterns: [
|
|
51
|
+
{ type: "class", regex: /^(public\s+)?(abstract\s+)?class\s+(\w+)(\s+extends\s+\w+)?(\s+implements\s+[\w,\s]+)?/gm },
|
|
52
|
+
{ type: "interface", regex: /^(public\s+)?interface\s+(\w+)(\s+extends\s+[\w,\s]+)?/gm },
|
|
53
|
+
{ type: "function", regex: /^\s*(public|protected|private)?\s*(static\s+)?([\w<>\[\]]+)\s+(\w+)\s*\([^)]*\)/gm },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
cpp: {
|
|
57
|
+
patterns: [
|
|
58
|
+
{ type: "class", regex: /^(class|struct)\s+(\w+)/gm },
|
|
59
|
+
{ type: "function", regex: /^(virtual\s+)?(static\s+)?([\w:*&<>]+)\s+(\w+)\s*\([^)]*\)/gm },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
ruby: {
|
|
63
|
+
patterns: [
|
|
64
|
+
{ type: "class", regex: /^class\s+(\w+)(\s*<\s*\w+)?/gm },
|
|
65
|
+
{ type: "function", regex: /^\s*def\s+(self\.)?(\w+[?!]?)\s*(\([^)]*\))?/gm },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
// Map file extensions / language names to pattern keys
|
|
70
|
+
function getLangKey(lang) {
|
|
71
|
+
const map = {
|
|
72
|
+
ts: "typescript", tsx: "typescript", typescript: "typescript", javascript: "typescript", js: "typescript",
|
|
73
|
+
dart: "dart", flutter: "dart",
|
|
74
|
+
py: "python", python: "python",
|
|
75
|
+
go: "go",
|
|
76
|
+
rs: "rust", rust: "rust",
|
|
77
|
+
java: "java", kotlin: "java",
|
|
78
|
+
cpp: "cpp", "c++": "cpp", c: "cpp", h: "cpp", hpp: "cpp",
|
|
79
|
+
rb: "ruby", ruby: "ruby",
|
|
80
|
+
};
|
|
81
|
+
return map[lang.toLowerCase()] || "typescript"; // fallback to TS patterns
|
|
82
|
+
}
|
|
83
|
+
// ── Signature Extraction ────────────────────────────────────────────
|
|
84
|
+
/**
|
|
85
|
+
* Extract function/class/type signatures from source code.
|
|
86
|
+
*/
|
|
87
|
+
function extractSignatures(content, lang) {
|
|
88
|
+
const langKey = getLangKey(lang);
|
|
89
|
+
const langPatterns = LANG_PATTERNS[langKey];
|
|
90
|
+
if (!langPatterns)
|
|
91
|
+
return [];
|
|
92
|
+
const lines = content.split("\n");
|
|
93
|
+
const signatures = [];
|
|
94
|
+
const seen = new Set();
|
|
95
|
+
for (const { type, regex } of langPatterns.patterns) {
|
|
96
|
+
// Reset regex state
|
|
97
|
+
regex.lastIndex = 0;
|
|
98
|
+
let match;
|
|
99
|
+
while ((match = regex.exec(content)) !== null) {
|
|
100
|
+
const matchLine = content.substring(0, match.index).split("\n").length;
|
|
101
|
+
const fullLine = lines[matchLine - 1]?.trim() || match[0].trim();
|
|
102
|
+
const exported = /^export\s/.test(fullLine) || /^pub\s/.test(fullLine);
|
|
103
|
+
// Extract name (last capturing group that looks like a name)
|
|
104
|
+
let name = "";
|
|
105
|
+
for (let i = match.length - 1; i >= 1; i--) {
|
|
106
|
+
if (match[i] && /^\w+$/.test(match[i])) {
|
|
107
|
+
name = match[i];
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!name)
|
|
112
|
+
name = fullLine.split(/[\s(<{=]/)[1] || "unknown";
|
|
113
|
+
const key = `${type}:${name}`;
|
|
114
|
+
if (seen.has(key))
|
|
115
|
+
continue;
|
|
116
|
+
seen.add(key);
|
|
117
|
+
signatures.push({
|
|
118
|
+
type,
|
|
119
|
+
name,
|
|
120
|
+
signature: fullLine,
|
|
121
|
+
exported,
|
|
122
|
+
line: matchLine,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return signatures.sort((a, b) => a.line - b.line);
|
|
127
|
+
}
|
|
128
|
+
// ── Signature Diff ──────────────────────────────────────────────────
|
|
129
|
+
/**
|
|
130
|
+
* Compare signatures between old and new file content.
|
|
131
|
+
* Returns structural changes (added/removed/modified declarations).
|
|
132
|
+
*/
|
|
133
|
+
function diffSignatures(oldContent, newContent, lang) {
|
|
134
|
+
const oldSigs = extractSignatures(oldContent, lang);
|
|
135
|
+
const newSigs = extractSignatures(newContent, lang);
|
|
136
|
+
const oldMap = new Map(oldSigs.map((s) => [`${s.type}:${s.name}`, s]));
|
|
137
|
+
const newMap = new Map(newSigs.map((s) => [`${s.type}:${s.name}`, s]));
|
|
138
|
+
const changes = [];
|
|
139
|
+
// Removed
|
|
140
|
+
for (const [key, sig] of oldMap) {
|
|
141
|
+
if (!newMap.has(key)) {
|
|
142
|
+
changes.push({ type: "removed", name: sig.name, oldSignature: sig.signature });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Added
|
|
146
|
+
for (const [key, sig] of newMap) {
|
|
147
|
+
if (!oldMap.has(key)) {
|
|
148
|
+
changes.push({ type: "added", name: sig.name, newSignature: sig.signature });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Modified
|
|
152
|
+
for (const [key, newSig] of newMap) {
|
|
153
|
+
const oldSig = oldMap.get(key);
|
|
154
|
+
if (oldSig && oldSig.signature !== newSig.signature) {
|
|
155
|
+
changes.push({
|
|
156
|
+
type: "modified",
|
|
157
|
+
name: newSig.name,
|
|
158
|
+
oldSignature: oldSig.signature,
|
|
159
|
+
newSignature: newSig.signature,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return changes;
|
|
164
|
+
}
|
|
165
|
+
// ── Smart Context Builder ───────────────────────────────────────────
|
|
166
|
+
/**
|
|
167
|
+
* Build a smart context summary of a file for AI prompts.
|
|
168
|
+
* Short files (<100 lines) are passed through as-is.
|
|
169
|
+
* Longer files get: imports + exported signatures + body summary.
|
|
170
|
+
*/
|
|
171
|
+
function buildSmartContext(content, lang, maxLines = 100) {
|
|
172
|
+
const lines = content.split("\n");
|
|
173
|
+
// Short files: return as-is
|
|
174
|
+
if (lines.length <= maxLines)
|
|
175
|
+
return content;
|
|
176
|
+
const parts = [];
|
|
177
|
+
const importLines = [];
|
|
178
|
+
let lastImportLine = 0;
|
|
179
|
+
// Collect imports
|
|
180
|
+
for (let i = 0; i < lines.length; i++) {
|
|
181
|
+
const line = lines[i].trim();
|
|
182
|
+
if (line.startsWith("import ") ||
|
|
183
|
+
line.startsWith("from ") ||
|
|
184
|
+
line.startsWith("require(") ||
|
|
185
|
+
line.startsWith("const ") && line.includes("require(") ||
|
|
186
|
+
line.startsWith("use ") ||
|
|
187
|
+
line.startsWith("#include") ||
|
|
188
|
+
line.startsWith("package ")) {
|
|
189
|
+
importLines.push(lines[i]);
|
|
190
|
+
lastImportLine = i;
|
|
191
|
+
}
|
|
192
|
+
// Stop scanning after a non-import, non-blank line beyond the header
|
|
193
|
+
if (i > 20 && line && !line.startsWith("import") && !line.startsWith("from") && !line.startsWith("//") && !line.startsWith("#") && !line.startsWith("*") && !line.startsWith("/*")) {
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (importLines.length > 0) {
|
|
198
|
+
parts.push("// ── Imports ──");
|
|
199
|
+
parts.push(...importLines);
|
|
200
|
+
parts.push("");
|
|
201
|
+
}
|
|
202
|
+
// Collect exported signatures
|
|
203
|
+
const sigs = extractSignatures(content, lang).filter((s) => s.exported);
|
|
204
|
+
if (sigs.length > 0) {
|
|
205
|
+
parts.push("// ── Exported Declarations ──");
|
|
206
|
+
for (const sig of sigs) {
|
|
207
|
+
parts.push(`${sig.signature} // L${sig.line}`);
|
|
208
|
+
}
|
|
209
|
+
parts.push("");
|
|
210
|
+
}
|
|
211
|
+
// All signatures (non-exported)
|
|
212
|
+
const privateSigs = extractSignatures(content, lang).filter((s) => !s.exported);
|
|
213
|
+
if (privateSigs.length > 0) {
|
|
214
|
+
parts.push("// ── Internal Declarations ──");
|
|
215
|
+
for (const sig of privateSigs) {
|
|
216
|
+
parts.push(`${sig.signature} // L${sig.line}`);
|
|
217
|
+
}
|
|
218
|
+
parts.push("");
|
|
219
|
+
}
|
|
220
|
+
const bodyLines = lines.length - lastImportLine - 1;
|
|
221
|
+
parts.push(`// ... (${bodyLines} lines of implementation omitted)`);
|
|
222
|
+
parts.push(`// Total: ${lines.length} lines`);
|
|
223
|
+
return parts.join("\n");
|
|
224
|
+
}
|