@tekyzinc/gsd-t 4.9.14 → 4.10.10
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/CHANGELOG.md +15 -0
- package/README.md +1 -1
- package/bin/gsd-t-competition-judge.cjs +7 -1
- package/bin/gsd-t-context-brief-kinds/impact.cjs +91 -4
- package/bin/gsd-t-context-brief-kinds/partition.cjs +95 -0
- package/bin/gsd-t-context-brief-kinds/plan.cjs +110 -4
- package/bin/gsd-t-file-disjointness.cjs +319 -7
- package/bin/gsd-t-graph-anti-grep-lint.cjs +515 -0
- package/bin/gsd-t-graph-edge-extract.cjs +612 -0
- package/bin/gsd-t-graph-freshness.cjs +506 -0
- package/bin/gsd-t-graph-index.cjs +540 -0
- package/bin/gsd-t-graph-k1-sqlite-stream.cjs +251 -0
- package/bin/gsd-t-graph-query-cli.cjs +1182 -0
- package/bin/gsd-t-graph-scip-upgrade.cjs +440 -0
- package/bin/gsd-t-graph-store-bakeoff.cjs +889 -0
- package/bin/gsd-t-graph-synthetic-gen.cjs +304 -0
- package/bin/gsd-t-graph-ts-throughput.cjs +587 -0
- package/bin/gsd-t-scip-reader.cjs +167 -0
- package/bin/gsd-t.js +166 -48
- package/commands/gsd-t-debug.md +10 -0
- package/commands/gsd-t-design-build.md +10 -0
- package/commands/gsd-t-execute.md +15 -0
- package/commands/gsd-t-feature.md +15 -7
- package/commands/gsd-t-gap-analysis.md +17 -7
- package/commands/gsd-t-impact.md +25 -0
- package/commands/gsd-t-integrate.md +25 -0
- package/commands/gsd-t-partition.md +18 -0
- package/commands/gsd-t-plan.md +16 -0
- package/commands/gsd-t-populate.md +16 -5
- package/commands/gsd-t-prd.md +18 -0
- package/commands/gsd-t-project.md +19 -0
- package/commands/gsd-t-promote-debt.md +16 -5
- package/commands/gsd-t-qa.md +20 -8
- package/commands/gsd-t-quick.md +10 -0
- package/commands/gsd-t-scan.md +21 -3
- package/commands/gsd-t-test-sync.md +10 -0
- package/commands/gsd-t-verify.md +25 -0
- package/commands/gsd-t-wave.md +8 -0
- package/package.json +10 -2
- package/templates/workflows/gsd-t-debug.workflow.js +81 -0
- package/templates/workflows/gsd-t-integrate.workflow.js +47 -1
- package/templates/workflows/gsd-t-phase.workflow.js +84 -0
- package/templates/workflows/gsd-t-quick.workflow.js +64 -0
- package/templates/workflows/gsd-t-scan.workflow.js +200 -9
- package/templates/workflows/gsd-t-verify.workflow.js +50 -1
- package/bin/graph-cgc.js +0 -510
- package/bin/graph-indexer.js +0 -147
- package/bin/graph-overlay.js +0 -195
- package/bin/graph-parsers.js +0 -327
- package/bin/graph-query.js +0 -453
- package/bin/graph-store.js +0 -154
package/bin/graph-overlay.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* GSD-T context mapper — enriches code entities with
|
|
7
|
-
* domain ownership, contract mapping, requirement traceability,
|
|
8
|
-
* test mapping, debt mapping, and surface detection.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
function readFileOrEmpty(filePath) {
|
|
12
|
-
try { return fs.readFileSync(filePath, 'utf8'); }
|
|
13
|
-
catch { return ''; }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function listDirs(dirPath) {
|
|
17
|
-
try {
|
|
18
|
-
return fs.readdirSync(dirPath, { withFileTypes: true })
|
|
19
|
-
.filter(d => d.isDirectory())
|
|
20
|
-
.map(d => d.name);
|
|
21
|
-
} catch { return []; }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function buildDomainMap(projectRoot) {
|
|
25
|
-
const domainsDir = path.join(projectRoot, '.gsd-t', 'domains');
|
|
26
|
-
const map = {};
|
|
27
|
-
for (const domain of listDirs(domainsDir)) {
|
|
28
|
-
const scopePath = path.join(domainsDir, domain, 'scope.md');
|
|
29
|
-
const content = readFileOrEmpty(scopePath);
|
|
30
|
-
const fileRefs = [];
|
|
31
|
-
for (const line of content.split('\n')) {
|
|
32
|
-
const m = line.match(/[-*]\s+`([^`]+)`/);
|
|
33
|
-
if (m) fileRefs.push(m[1].replace(/\s*\(.*\)/, '').trim());
|
|
34
|
-
}
|
|
35
|
-
map[domain] = fileRefs;
|
|
36
|
-
}
|
|
37
|
-
return map;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function mapDomains(entities, projectRoot) {
|
|
41
|
-
const domainMap = buildDomainMap(projectRoot);
|
|
42
|
-
for (const entity of entities) {
|
|
43
|
-
for (const [domain, files] of Object.entries(domainMap)) {
|
|
44
|
-
if (files.some(f => entity.file.includes(f))) {
|
|
45
|
-
entity.domain = domain;
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function mapContracts(entities, projectRoot) {
|
|
53
|
-
const contractsDir = path.join(
|
|
54
|
-
projectRoot, '.gsd-t', 'contracts'
|
|
55
|
-
);
|
|
56
|
-
const mappings = [];
|
|
57
|
-
try {
|
|
58
|
-
const files = fs.readdirSync(contractsDir)
|
|
59
|
-
.filter(f => f.endsWith('.md'));
|
|
60
|
-
for (const file of files) {
|
|
61
|
-
const content = readFileOrEmpty(
|
|
62
|
-
path.join(contractsDir, file)
|
|
63
|
-
);
|
|
64
|
-
for (const entity of entities) {
|
|
65
|
-
if (content.includes(entity.name)) {
|
|
66
|
-
mappings.push({
|
|
67
|
-
entity: entity.id,
|
|
68
|
-
contract: file,
|
|
69
|
-
section: ''
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} catch { /* no contracts dir */ }
|
|
75
|
-
return { mappings };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function mapRequirements(entities, projectRoot) {
|
|
79
|
-
const reqPath = path.join(
|
|
80
|
-
projectRoot, 'docs', 'requirements.md'
|
|
81
|
-
);
|
|
82
|
-
const content = readFileOrEmpty(reqPath);
|
|
83
|
-
const mappings = [];
|
|
84
|
-
if (!content) return { mappings };
|
|
85
|
-
|
|
86
|
-
const reqLines = content.split('\n');
|
|
87
|
-
for (const entity of entities) {
|
|
88
|
-
for (const line of reqLines) {
|
|
89
|
-
const reqMatch = line.match(/(REQ-\d+)/);
|
|
90
|
-
if (reqMatch && line.includes(entity.name)) {
|
|
91
|
-
mappings.push({
|
|
92
|
-
entity: entity.id,
|
|
93
|
-
requirement: reqMatch[1]
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return { mappings };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function mapTests(entities, projectRoot) {
|
|
102
|
-
const mappings = [];
|
|
103
|
-
const testDirs = ['test', 'tests', '__tests__', 'spec'];
|
|
104
|
-
for (const dir of testDirs) {
|
|
105
|
-
const testDir = path.join(projectRoot, dir);
|
|
106
|
-
try {
|
|
107
|
-
const files = fs.readdirSync(testDir)
|
|
108
|
-
.filter(f => /\.(test|spec)\.(js|ts|py)$/.test(f));
|
|
109
|
-
for (const testFile of files) {
|
|
110
|
-
const content = readFileOrEmpty(
|
|
111
|
-
path.join(testDir, testFile)
|
|
112
|
-
);
|
|
113
|
-
for (const entity of entities) {
|
|
114
|
-
if (content.includes(entity.name)) {
|
|
115
|
-
mappings.push({
|
|
116
|
-
entity: entity.id,
|
|
117
|
-
testFile: path.join(dir, testFile),
|
|
118
|
-
testName: ''
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} catch { /* no test dir */ }
|
|
124
|
-
}
|
|
125
|
-
return { mappings };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function mapDebt(entities, projectRoot) {
|
|
129
|
-
const debtPath = path.join(
|
|
130
|
-
projectRoot, '.gsd-t', 'techdebt.md'
|
|
131
|
-
);
|
|
132
|
-
const content = readFileOrEmpty(debtPath);
|
|
133
|
-
const mappings = [];
|
|
134
|
-
if (!content) return mappings;
|
|
135
|
-
|
|
136
|
-
for (const entity of entities) {
|
|
137
|
-
const lines = content.split('\n');
|
|
138
|
-
for (const line of lines) {
|
|
139
|
-
const debtMatch = line.match(/(TD-\d+)/);
|
|
140
|
-
if (debtMatch && (
|
|
141
|
-
line.includes(entity.name) ||
|
|
142
|
-
line.includes(entity.file)
|
|
143
|
-
)) {
|
|
144
|
-
mappings.push({
|
|
145
|
-
id: debtMatch[1],
|
|
146
|
-
entity: entity.id,
|
|
147
|
-
description: line.trim()
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return mappings;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function detectSurfaces(entities, projectRoot) {
|
|
156
|
-
const surfaceDirs = {
|
|
157
|
-
'web': ['web', 'frontend', 'client', 'webapp', 'www'],
|
|
158
|
-
'mobile': ['mobile', 'app', 'ios', 'android', 'react-native'],
|
|
159
|
-
'cli': ['cli', 'bin', 'commands'],
|
|
160
|
-
'api': ['api', 'server', 'backend', 'routes'],
|
|
161
|
-
'shared': ['shared', 'common', 'lib', 'utils', 'core']
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const mappings = [];
|
|
165
|
-
for (const entity of entities) {
|
|
166
|
-
const surfaces = [];
|
|
167
|
-
for (const [surface, dirs] of Object.entries(surfaceDirs)) {
|
|
168
|
-
if (dirs.some(d => entity.file.startsWith(d + '/') ||
|
|
169
|
-
entity.file.startsWith(d + '\\'))) {
|
|
170
|
-
surfaces.push(surface);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (surfaces.length > 0) {
|
|
174
|
-
mappings.push({ entity: entity.id, surfaces });
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return { mappings };
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function buildOverlay(projectRoot, entities) {
|
|
181
|
-
mapDomains(entities, projectRoot);
|
|
182
|
-
const contracts = mapContracts(entities, projectRoot);
|
|
183
|
-
const requirements = mapRequirements(entities, projectRoot);
|
|
184
|
-
const tests = mapTests(entities, projectRoot);
|
|
185
|
-
const surfaces = detectSurfaces(entities, projectRoot);
|
|
186
|
-
const debt = mapDebt(entities, projectRoot);
|
|
187
|
-
|
|
188
|
-
return { contracts, requirements, tests, surfaces, debt };
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
module.exports = {
|
|
192
|
-
buildOverlay, buildDomainMap, mapDomains,
|
|
193
|
-
mapContracts, mapRequirements, mapTests,
|
|
194
|
-
mapDebt, detectSurfaces
|
|
195
|
-
};
|
package/bin/graph-parsers.js
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Language-specific parsers for extracting code entities.
|
|
5
|
-
* Zero external dependencies — regex-based only.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// --- JS/TS Parser ---
|
|
9
|
-
|
|
10
|
-
const JS_FUNC_PATTERNS = [
|
|
11
|
-
// function declarations: function name(, async function name(
|
|
12
|
-
/^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/gm,
|
|
13
|
-
// arrow/const: const name = (, const name = function(, const name = async (
|
|
14
|
-
/^\s*(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?(?:function\s*)?\(/gm,
|
|
15
|
-
// arrow with =>: const name = (...) =>
|
|
16
|
-
/^\s*(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/gm,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const JS_CLASS_PATTERN = /^\s*(?:export\s+)?(?:default\s+)?class\s+(\w+)/gm;
|
|
20
|
-
|
|
21
|
-
const JS_METHOD_PATTERN = /^\s+(?:async\s+)?(\w+)\s*\([^)]*\)\s*\{/gm;
|
|
22
|
-
|
|
23
|
-
const JS_IMPORT_PATTERNS = [
|
|
24
|
-
// import { x, y } from 'module'
|
|
25
|
-
/^\s*import\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/gm,
|
|
26
|
-
// import x from 'module'
|
|
27
|
-
/^\s*import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/gm,
|
|
28
|
-
// import * as x from 'module'
|
|
29
|
-
/^\s*import\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]/gm,
|
|
30
|
-
// const x = require('module')
|
|
31
|
-
/^\s*(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))\s*=\s*require\(\s*['"]([^'"]+)['"]\s*\)/gm,
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
const JS_EXPORT_PATTERNS = [
|
|
35
|
-
// module.exports = { ... } or module.exports = name
|
|
36
|
-
/^\s*module\.exports\s*=\s*/gm,
|
|
37
|
-
// export default
|
|
38
|
-
/^\s*export\s+default\s+/gm,
|
|
39
|
-
// export { x, y }
|
|
40
|
-
/^\s*export\s+\{([^}]+)\}/gm,
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
function parseJavaScript(content, filePath) {
|
|
44
|
-
const entities = [];
|
|
45
|
-
const imports = [];
|
|
46
|
-
const calls = [];
|
|
47
|
-
const lines = content.split('\n');
|
|
48
|
-
const exportedNames = new Set();
|
|
49
|
-
let currentClass = null;
|
|
50
|
-
|
|
51
|
-
// Collect exported names
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
if (/^\s*export\s+/.test(line)) {
|
|
54
|
-
const m = line.match(/(?:function|class|const|let|var)\s+(\w+)/);
|
|
55
|
-
if (m) exportedNames.add(m[1]);
|
|
56
|
-
}
|
|
57
|
-
const exportMatch = line.match(/^\s*export\s+\{([^}]+)\}/);
|
|
58
|
-
if (exportMatch) {
|
|
59
|
-
exportMatch[1].split(',').forEach(n => {
|
|
60
|
-
const name = n.trim().split(/\s+as\s+/)[0].trim();
|
|
61
|
-
if (name) exportedNames.add(name);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (/module\.exports/.test(line)) {
|
|
65
|
-
const m = line.match(/module\.exports\s*=\s*\{\s*([^}]+)\}/);
|
|
66
|
-
if (m) {
|
|
67
|
-
m[1].split(',').forEach(n => {
|
|
68
|
-
const name = n.trim().split(':')[0].trim();
|
|
69
|
-
if (name) exportedNames.add(name);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Extract entities line by line
|
|
76
|
-
for (let i = 0; i < lines.length; i++) {
|
|
77
|
-
const line = lines[i];
|
|
78
|
-
const lineNum = i + 1;
|
|
79
|
-
|
|
80
|
-
// Class declarations
|
|
81
|
-
const classMatch = line.match(
|
|
82
|
-
/^\s*(?:export\s+)?(?:default\s+)?class\s+(\w+)/
|
|
83
|
-
);
|
|
84
|
-
if (classMatch) {
|
|
85
|
-
currentClass = classMatch[1];
|
|
86
|
-
entities.push({
|
|
87
|
-
id: `${filePath}:${lineNum}:${classMatch[1]}`,
|
|
88
|
-
name: classMatch[1],
|
|
89
|
-
type: 'class',
|
|
90
|
-
file: filePath,
|
|
91
|
-
line: lineNum,
|
|
92
|
-
domain: null,
|
|
93
|
-
exported: exportedNames.has(classMatch[1]) ||
|
|
94
|
-
/export/.test(line)
|
|
95
|
-
});
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Method declarations (inside class)
|
|
100
|
-
if (currentClass) {
|
|
101
|
-
const methodMatch = line.match(
|
|
102
|
-
/^\s+(?:static\s+)?(?:async\s+)?(\w+)\s*\([^)]*\)\s*\{/
|
|
103
|
-
);
|
|
104
|
-
if (methodMatch && methodMatch[1] !== 'constructor') {
|
|
105
|
-
entities.push({
|
|
106
|
-
id: `${filePath}:${lineNum}:${methodMatch[1]}`,
|
|
107
|
-
name: methodMatch[1],
|
|
108
|
-
type: 'method',
|
|
109
|
-
file: filePath,
|
|
110
|
-
line: lineNum,
|
|
111
|
-
domain: null,
|
|
112
|
-
exported: exportedNames.has(currentClass)
|
|
113
|
-
});
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
// Detect end of class
|
|
117
|
-
if (/^}/.test(line)) currentClass = null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Function declarations
|
|
121
|
-
const funcMatch = line.match(
|
|
122
|
-
/^\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/
|
|
123
|
-
);
|
|
124
|
-
if (funcMatch) {
|
|
125
|
-
entities.push({
|
|
126
|
-
id: `${filePath}:${lineNum}:${funcMatch[1]}`,
|
|
127
|
-
name: funcMatch[1],
|
|
128
|
-
type: 'function',
|
|
129
|
-
file: filePath,
|
|
130
|
-
line: lineNum,
|
|
131
|
-
domain: null,
|
|
132
|
-
exported: exportedNames.has(funcMatch[1]) ||
|
|
133
|
-
/export/.test(line)
|
|
134
|
-
});
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Arrow/const functions
|
|
139
|
-
const arrowMatch = line.match(
|
|
140
|
-
/^\s*(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?(?:function\s*)?\(/
|
|
141
|
-
) || line.match(
|
|
142
|
-
/^\s*(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/
|
|
143
|
-
);
|
|
144
|
-
if (arrowMatch) {
|
|
145
|
-
entities.push({
|
|
146
|
-
id: `${filePath}:${lineNum}:${arrowMatch[1]}`,
|
|
147
|
-
name: arrowMatch[1],
|
|
148
|
-
type: 'function',
|
|
149
|
-
file: filePath,
|
|
150
|
-
line: lineNum,
|
|
151
|
-
domain: null,
|
|
152
|
-
exported: exportedNames.has(arrowMatch[1]) ||
|
|
153
|
-
/export/.test(line)
|
|
154
|
-
});
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Import statements
|
|
159
|
-
const esImportNamed = line.match(
|
|
160
|
-
/^\s*import\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/
|
|
161
|
-
);
|
|
162
|
-
if (esImportNamed) {
|
|
163
|
-
const names = esImportNamed[1].split(',').map(n =>
|
|
164
|
-
n.trim().split(/\s+as\s+/)[0].trim()
|
|
165
|
-
).filter(Boolean);
|
|
166
|
-
imports.push({
|
|
167
|
-
source: filePath,
|
|
168
|
-
target: esImportNamed[2],
|
|
169
|
-
names,
|
|
170
|
-
line: lineNum
|
|
171
|
-
});
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const esImportDefault = line.match(
|
|
176
|
-
/^\s*import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/
|
|
177
|
-
);
|
|
178
|
-
if (esImportDefault) {
|
|
179
|
-
imports.push({
|
|
180
|
-
source: filePath,
|
|
181
|
-
target: esImportDefault[2],
|
|
182
|
-
names: [esImportDefault[1]],
|
|
183
|
-
line: lineNum
|
|
184
|
-
});
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const esImportStar = line.match(
|
|
189
|
-
/^\s*import\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]/
|
|
190
|
-
);
|
|
191
|
-
if (esImportStar) {
|
|
192
|
-
imports.push({
|
|
193
|
-
source: filePath,
|
|
194
|
-
target: esImportStar[2],
|
|
195
|
-
names: [esImportStar[1]],
|
|
196
|
-
line: lineNum
|
|
197
|
-
});
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const requireMatch = line.match(
|
|
202
|
-
/^\s*(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))\s*=\s*require\(\s*['"]([^'"]+)['"]\s*\)/
|
|
203
|
-
);
|
|
204
|
-
if (requireMatch) {
|
|
205
|
-
const names = requireMatch[1]
|
|
206
|
-
? requireMatch[1].split(',').map(n =>
|
|
207
|
-
n.trim().split(':')[0].trim()
|
|
208
|
-
).filter(Boolean)
|
|
209
|
-
: [requireMatch[2]];
|
|
210
|
-
imports.push({
|
|
211
|
-
source: filePath,
|
|
212
|
-
target: requireMatch[3],
|
|
213
|
-
names,
|
|
214
|
-
line: lineNum
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Extract calls (best-effort: known entity names followed by '(')
|
|
220
|
-
const entityNames = new Set(entities.map(e => e.name));
|
|
221
|
-
for (let i = 0; i < lines.length; i++) {
|
|
222
|
-
const line = lines[i];
|
|
223
|
-
// Skip declarations, imports, comments
|
|
224
|
-
if (/^\s*(\/\/|\/\*|import |const |let |var |function |class |export )/.test(line)) continue;
|
|
225
|
-
for (const name of entityNames) {
|
|
226
|
-
const re = new RegExp(`\\b${name}\\s*\\(`, 'g');
|
|
227
|
-
if (re.test(line)) {
|
|
228
|
-
calls.push({ caller: `${filePath}:${i + 1}:_caller`, callee: name, line: i + 1 });
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return { entities, imports, calls };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// --- Python Parser ---
|
|
237
|
-
|
|
238
|
-
function parsePython(content, filePath) {
|
|
239
|
-
const entities = [];
|
|
240
|
-
const imports = [];
|
|
241
|
-
const calls = [];
|
|
242
|
-
const lines = content.split('\n');
|
|
243
|
-
let currentClass = null;
|
|
244
|
-
|
|
245
|
-
for (let i = 0; i < lines.length; i++) {
|
|
246
|
-
const line = lines[i];
|
|
247
|
-
const lineNum = i + 1;
|
|
248
|
-
|
|
249
|
-
// Class declaration
|
|
250
|
-
const classMatch = line.match(/^class\s+(\w+)\s*[:(]/);
|
|
251
|
-
if (classMatch) {
|
|
252
|
-
currentClass = classMatch[1];
|
|
253
|
-
entities.push({
|
|
254
|
-
id: `${filePath}:${lineNum}:${classMatch[1]}`,
|
|
255
|
-
name: classMatch[1],
|
|
256
|
-
type: 'class',
|
|
257
|
-
file: filePath,
|
|
258
|
-
line: lineNum,
|
|
259
|
-
domain: null,
|
|
260
|
-
exported: true
|
|
261
|
-
});
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Function/method declaration
|
|
266
|
-
const defMatch = line.match(/^(\s*)def\s+(\w+)\s*\(/);
|
|
267
|
-
if (defMatch) {
|
|
268
|
-
const indent = defMatch[1].length;
|
|
269
|
-
const isMethod = indent > 0 && currentClass;
|
|
270
|
-
if (!defMatch[2].startsWith('_') || defMatch[2] === '__init__') {
|
|
271
|
-
entities.push({
|
|
272
|
-
id: `${filePath}:${lineNum}:${defMatch[2]}`,
|
|
273
|
-
name: defMatch[2],
|
|
274
|
-
type: isMethod ? 'method' : 'function',
|
|
275
|
-
file: filePath,
|
|
276
|
-
line: lineNum,
|
|
277
|
-
domain: null,
|
|
278
|
-
exported: !defMatch[2].startsWith('_')
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Reset class context on unindented non-empty line
|
|
285
|
-
if (currentClass && /^\S/.test(line) && line.trim()) {
|
|
286
|
-
currentClass = null;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// import x, import x as y
|
|
290
|
-
const importMatch = line.match(/^import\s+([\w.]+)/);
|
|
291
|
-
if (importMatch) {
|
|
292
|
-
imports.push({
|
|
293
|
-
source: filePath,
|
|
294
|
-
target: importMatch[1],
|
|
295
|
-
names: [importMatch[1].split('.').pop()],
|
|
296
|
-
line: lineNum
|
|
297
|
-
});
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// from x import y, z
|
|
302
|
-
const fromMatch = line.match(/^from\s+([\w.]+)\s+import\s+(.+)/);
|
|
303
|
-
if (fromMatch) {
|
|
304
|
-
const names = fromMatch[2].split(',').map(n =>
|
|
305
|
-
n.trim().split(/\s+as\s+/)[0].trim()
|
|
306
|
-
).filter(Boolean);
|
|
307
|
-
imports.push({
|
|
308
|
-
source: filePath,
|
|
309
|
-
target: fromMatch[1],
|
|
310
|
-
names,
|
|
311
|
-
line: lineNum
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return { entities, imports, calls };
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function getParser(ext) {
|
|
320
|
-
if (['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx'].includes(ext)) {
|
|
321
|
-
return parseJavaScript;
|
|
322
|
-
}
|
|
323
|
-
if (ext === '.py') return parsePython;
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
module.exports = { parseJavaScript, parsePython, getParser };
|