sigmap 6.10.1 → 6.10.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/AGENTS.md +466 -208
- package/CHANGELOG.md +28 -0
- package/README.md +22 -9
- package/gen-context.js +223 -3
- package/package.json +1 -1
- package/packages/adapters/index.js +4 -2
- package/packages/adapters/willow.js +200 -0
- package/packages/cli/package.json +1 -1
- package/packages/core/index.js +1 -0
- package/packages/core/package.json +1 -1
- package/src/discovery/language-detector.js +1 -0
- package/src/eval/analyzer.js +1 -0
- package/src/extractors/gdscript.js +131 -0
- package/src/map/import-graph.js +1 -1
- package/src/mcp/server.js +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extract signatures from Godot GDScript source code.
|
|
5
|
+
* @param {string} src - Raw file content
|
|
6
|
+
* @returns {string[]} Array of signature strings
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function extract(src) {
|
|
10
|
+
if (!src || typeof src !== 'string') return [];
|
|
11
|
+
const sigs = [];
|
|
12
|
+
|
|
13
|
+
const stripped = src.replace(/#.*$/gm, '');
|
|
14
|
+
|
|
15
|
+
let className = null;
|
|
16
|
+
let baseName = null;
|
|
17
|
+
const addedClasses = new Set();
|
|
18
|
+
|
|
19
|
+
const cm = stripped.match(/^class_name\s+(\w+)(?:\s+extends\s+([\w.]+))?/m);
|
|
20
|
+
if (cm) {
|
|
21
|
+
className = cm[1];
|
|
22
|
+
if (cm[2]) baseName = cm[2];
|
|
23
|
+
}
|
|
24
|
+
if (!baseName) {
|
|
25
|
+
const em = stripped.match(/^extends\s+([\w."/]+)/m);
|
|
26
|
+
if (em) baseName = em[1];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (className) {
|
|
30
|
+
sigs.push(baseName ? `class ${className}(${baseName})` : `class ${className}`);
|
|
31
|
+
addedClasses.add(className);
|
|
32
|
+
} else if (baseName) {
|
|
33
|
+
sigs.push(`extends ${baseName}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const indent = (className || baseName) ? ' ' : '';
|
|
37
|
+
|
|
38
|
+
for (const m of stripped.matchAll(/^signal\s+(\w+)(?:\s*\(([^)]*)\))?/gm)) {
|
|
39
|
+
sigs.push(`${indent}signal ${m[1]}(${normalizeParams(m[2] || '')})`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const m of stripped.matchAll(/^enum\s+(\w+)\s*\{([^}]*)\}/gm)) {
|
|
43
|
+
const members = m[2]
|
|
44
|
+
.split(',')
|
|
45
|
+
.map((s) => s.trim().split(/\s*=/)[0].trim())
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
sigs.push(`${indent}enum ${m[1]} { ${members.slice(0, 6).join(', ')} }`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let constCount = 0;
|
|
51
|
+
for (const m of stripped.matchAll(/^const\s+(\w+)(?:\s*:\s*[^=\n]+)?\s*:?=\s*([^\n]+)$/gm)) {
|
|
52
|
+
let val = m[2].trim();
|
|
53
|
+
const preloadMatch = val.match(/^preload\s*\(([^)]+)\)/);
|
|
54
|
+
if (preloadMatch) {
|
|
55
|
+
val = `preload(${preloadMatch[1]})`;
|
|
56
|
+
} else if (val.length > 40) {
|
|
57
|
+
val = val.slice(0, 37) + '...';
|
|
58
|
+
}
|
|
59
|
+
sigs.push(`${indent}const ${m[1]} = ${val}`);
|
|
60
|
+
if (++constCount >= 5) break;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (const m of stripped.matchAll(/^((?:@\w+(?:\([^)]*\))?\s+)*)var\s+(\w+)(?:\s*:\s*([^=\n]+?))?(?:\s*:?=\s*[^\n]+)?$/gm)) {
|
|
64
|
+
const decorators = m[1] || '';
|
|
65
|
+
const name = m[2];
|
|
66
|
+
const hasDecorator = /@\w+/.test(decorators);
|
|
67
|
+
if (!hasDecorator && name.startsWith('_')) continue;
|
|
68
|
+
|
|
69
|
+
let prefix = decorators.replace(/\([^)]*\)/g, '').trim().split(/\s+/).join(' ');
|
|
70
|
+
if (prefix) prefix += ' ';
|
|
71
|
+
|
|
72
|
+
const type = (m[3] || '').trim();
|
|
73
|
+
const typeStr = type ? `: ${type}` : '';
|
|
74
|
+
sigs.push(`${indent}${prefix}var ${name}${typeStr}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (const m of stripped.matchAll(/^(static\s+)?func\s+(\w+)\s*\(([^)]*)\)(?:\s*->\s*([^:\n]+))?\s*:/gm)) {
|
|
78
|
+
const params = normalizeParams(m[3]);
|
|
79
|
+
const ret = (m[4] || '').trim();
|
|
80
|
+
const retStr = ret ? ` → ${ret.slice(0, 30)}` : '';
|
|
81
|
+
const staticKw = m[1] ? 'static ' : '';
|
|
82
|
+
sigs.push(`${indent}${staticKw}func ${m[2]}(${params})${retStr}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const m of stripped.matchAll(/^class\s+(\w+)(?:\s+extends\s+(\w+))?\s*:/gm)) {
|
|
86
|
+
if (addedClasses.has(m[1])) continue;
|
|
87
|
+
addedClasses.add(m[1]);
|
|
88
|
+
sigs.push(m[2] ? `class ${m[1]}(${m[2]})` : `class ${m[1]}`);
|
|
89
|
+
const startIdx = m.index + m[0].length;
|
|
90
|
+
for (const meth of extractInnerMembers(stripped, startIdx)) {
|
|
91
|
+
sigs.push(` ${meth}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return sigs.slice(0, 25);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function extractInnerMembers(stripped, startIndex) {
|
|
99
|
+
const members = [];
|
|
100
|
+
const lines = stripped.slice(startIndex).split('\n');
|
|
101
|
+
for (const line of lines) {
|
|
102
|
+
if (line.trim() === '') continue;
|
|
103
|
+
if (!/^\s+/.test(line)) break;
|
|
104
|
+
const fm = line.match(/^\s+(static\s+)?func\s+(\w+)\s*\(([^)]*)\)(?:\s*->\s*([^:\n]+))?\s*:/);
|
|
105
|
+
if (fm) {
|
|
106
|
+
const params = normalizeParams(fm[3]);
|
|
107
|
+
const ret = (fm[4] || '').trim();
|
|
108
|
+
const retStr = ret ? ` → ${ret.slice(0, 30)}` : '';
|
|
109
|
+
const staticKw = fm[1] ? 'static ' : '';
|
|
110
|
+
members.push(`${staticKw}func ${fm[2]}(${params})${retStr}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return members.slice(0, 6);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeParams(params) {
|
|
117
|
+
if (!params) return '';
|
|
118
|
+
return params.trim()
|
|
119
|
+
.split(',')
|
|
120
|
+
.map((p) => {
|
|
121
|
+
const part = p.trim();
|
|
122
|
+
if (!part) return '';
|
|
123
|
+
const eqIdx = part.indexOf('=');
|
|
124
|
+
const noDefault = eqIdx !== -1 ? part.slice(0, eqIdx).trim() : part;
|
|
125
|
+
return noDefault.split(':')[0].trim();
|
|
126
|
+
})
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.join(', ');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = { extract };
|
package/src/map/import-graph.js
CHANGED
package/src/mcp/server.js
CHANGED