forge-workflow 0.0.4 → 0.0.6
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/.claude/commands/dev.md +345 -340
- package/.claude/commands/plan.md +566 -521
- package/.claude/commands/premerge.md +186 -176
- package/.claude/commands/research.md +42 -42
- package/.claude/commands/review.md +448 -442
- package/.claude/commands/rollback.md +721 -721
- package/.claude/commands/ship.md +212 -164
- package/.claude/commands/sonarcloud.md +152 -152
- package/.claude/commands/status.md +90 -48
- package/.claude/commands/validate.md +288 -282
- package/.claude/commands/verify.md +269 -221
- package/.claude/rules/greptile-review-process.md +285 -285
- package/.claude/rules/workflow.md +121 -105
- package/.claude/scripts/greptile-resolve.sh +558 -526
- package/.claude/scripts/load-env.sh +32 -32
- package/.cline/workflows/dev.md +342 -337
- package/.cline/workflows/plan.md +563 -518
- package/.cline/workflows/premerge.md +183 -173
- package/.cline/workflows/research.md +39 -39
- package/.cline/workflows/review.md +445 -439
- package/.cline/workflows/rollback.md +718 -718
- package/.cline/workflows/ship.md +209 -161
- package/.cline/workflows/sonarcloud.md +146 -146
- package/.cline/workflows/status.md +87 -45
- package/.cline/workflows/validate.md +285 -279
- package/.cline/workflows/verify.md +266 -218
- package/.codex/config.toml +11 -11
- package/.codex/skills/dev/SKILL.md +345 -340
- package/.codex/skills/plan/SKILL.md +566 -521
- package/.codex/skills/premerge/SKILL.md +186 -176
- package/.codex/skills/research/SKILL.md +42 -42
- package/.codex/skills/review/SKILL.md +448 -442
- package/.codex/skills/rollback/SKILL.md +721 -721
- package/.codex/skills/ship/SKILL.md +212 -164
- package/.codex/skills/sonarcloud/SKILL.md +149 -149
- package/.codex/skills/status/SKILL.md +90 -48
- package/.codex/skills/validate/SKILL.md +288 -282
- package/.codex/skills/verify/SKILL.md +269 -221
- package/.cursor/commands/dev.md +342 -337
- package/.cursor/commands/plan.md +563 -518
- package/.cursor/commands/premerge.md +183 -173
- package/.cursor/commands/research.md +39 -39
- package/.cursor/commands/review.md +445 -439
- package/.cursor/commands/rollback.md +718 -718
- package/.cursor/commands/ship.md +209 -161
- package/.cursor/commands/sonarcloud.md +146 -146
- package/.cursor/commands/status.md +87 -45
- package/.cursor/commands/validate.md +285 -279
- package/.cursor/commands/verify.md +266 -218
- package/.cursor/rules/permissions-guidance.mdc +37 -37
- package/.forge/hooks/check-tdd.js +240 -240
- package/.github/PLUGIN_TEMPLATE.json +32 -32
- package/.github/prompts/dev.prompt.md +347 -342
- package/.github/prompts/plan.prompt.md +568 -523
- package/.github/prompts/premerge.prompt.md +188 -178
- package/.github/prompts/research.prompt.md +44 -44
- package/.github/prompts/review.prompt.md +450 -444
- package/.github/prompts/rollback.prompt.md +723 -723
- package/.github/prompts/ship.prompt.md +214 -166
- package/.github/prompts/sonarcloud.prompt.md +151 -151
- package/.github/prompts/status.prompt.md +92 -50
- package/.github/prompts/validate.prompt.md +290 -284
- package/.github/prompts/verify.prompt.md +271 -223
- package/.github/workflows/beads-to-github.yml +56 -0
- package/.github/workflows/github-to-beads.yml +97 -0
- package/.kilocode/workflows/dev.md +346 -341
- package/.kilocode/workflows/plan.md +567 -522
- package/.kilocode/workflows/premerge.md +187 -177
- package/.kilocode/workflows/research.md +43 -43
- package/.kilocode/workflows/review.md +449 -443
- package/.kilocode/workflows/rollback.md +722 -722
- package/.kilocode/workflows/ship.md +213 -165
- package/.kilocode/workflows/sonarcloud.md +150 -150
- package/.kilocode/workflows/status.md +91 -49
- package/.kilocode/workflows/validate.md +289 -283
- package/.kilocode/workflows/verify.md +270 -222
- package/.mcp.json.example +12 -12
- package/.opencode/commands/dev.md +345 -340
- package/.opencode/commands/plan.md +566 -521
- package/.opencode/commands/premerge.md +186 -176
- package/.opencode/commands/research.md +42 -42
- package/.opencode/commands/review.md +448 -442
- package/.opencode/commands/rollback.md +721 -721
- package/.opencode/commands/ship.md +212 -164
- package/.opencode/commands/sonarcloud.md +149 -149
- package/.opencode/commands/status.md +90 -48
- package/.opencode/commands/validate.md +288 -282
- package/.opencode/commands/verify.md +269 -221
- package/.roo/commands/dev.md +346 -341
- package/.roo/commands/plan.md +567 -522
- package/.roo/commands/premerge.md +187 -177
- package/.roo/commands/research.md +43 -43
- package/.roo/commands/review.md +449 -443
- package/.roo/commands/rollback.md +722 -722
- package/.roo/commands/ship.md +213 -165
- package/.roo/commands/sonarcloud.md +150 -150
- package/.roo/commands/status.md +91 -49
- package/.roo/commands/validate.md +289 -283
- package/.roo/commands/verify.md +270 -222
- package/AGENTS.md +272 -175
- package/CLAUDE.md +110 -100
- package/README.md +429 -416
- package/bin/forge-cmd.js +317 -313
- package/bin/forge-preflight.js +322 -309
- package/bin/forge.js +4765 -4303
- package/docs/AGENT_INSTALL_PROMPT.md +342 -342
- package/docs/BEADS_GITHUB_SYNC.md +251 -251
- package/docs/ENHANCED_ONBOARDING.md +612 -602
- package/docs/EXAMPLES.md +482 -482
- package/docs/GREPTILE_SETUP.md +400 -400
- package/docs/MANUAL_REVIEW_GUIDE.md +106 -106
- package/docs/ROADMAP.md +359 -359
- package/docs/SETUP.md +663 -631
- package/docs/TOOLCHAIN.md +653 -630
- package/docs/VALIDATION.md +363 -363
- package/install.sh +40 -1056
- package/lefthook.yml +50 -39
- package/lib/agents/README.md +198 -198
- package/lib/agents/claude.plugin.json +28 -28
- package/lib/agents/cline.plugin.json +22 -22
- package/lib/agents/codex.plugin.json +19 -19
- package/lib/agents/copilot.plugin.json +24 -24
- package/lib/agents/cursor.plugin.json +25 -25
- package/lib/agents/kilocode.plugin.json +22 -22
- package/lib/agents/opencode.plugin.json +20 -20
- package/lib/agents/roo.plugin.json +23 -23
- package/lib/agents-config.js +2112 -2112
- package/lib/beads-health-check.js +143 -0
- package/lib/beads-setup.js +341 -0
- package/lib/beads-sync-scaffold.js +260 -0
- package/lib/commands/_registry.js +134 -0
- package/lib/commands/clean.js +181 -0
- package/lib/commands/dev.js +571 -513
- package/lib/commands/plan.js +692 -692
- package/lib/commands/push.js +196 -0
- package/lib/commands/recommend.js +119 -119
- package/lib/commands/ship.js +377 -377
- package/lib/commands/status.js +378 -378
- package/lib/commands/sync.js +55 -0
- package/lib/commands/team.js +37 -0
- package/lib/commands/test.js +207 -0
- package/lib/commands/validate.js +602 -602
- package/lib/commands/worktree.js +310 -0
- package/lib/context-merge.js +359 -359
- package/lib/dep-guard/analyzer.js +294 -294
- package/lib/dep-guard/behavior-detector.js +98 -98
- package/lib/dep-guard/contract-detector.js +162 -162
- package/lib/dep-guard/import-detector.js +498 -498
- package/lib/dep-guard/path-utils.js +13 -13
- package/lib/dep-guard/rubric.js +120 -120
- package/lib/dep-guard/task-parser.js +318 -318
- package/lib/detect-agent.js +191 -191
- package/lib/detect-worktree.js +47 -47
- package/lib/docs-command.js +51 -0
- package/lib/docs-copy.js +50 -0
- package/lib/file-hash.js +26 -26
- package/lib/freshness-token.js +148 -0
- package/lib/greptile-match.js +80 -0
- package/lib/husky-migration.js +450 -0
- package/lib/lefthook-check.js +65 -0
- package/lib/pat-setup.js +207 -0
- package/lib/plugin-catalog.js +350 -350
- package/lib/plugin-manager.js +166 -166
- package/lib/plugin-recommender.js +141 -141
- package/lib/project-discovery.js +491 -491
- package/lib/reset.js +309 -0
- package/lib/setup-action-log.js +139 -139
- package/lib/setup-summary-renderer.js +106 -106
- package/lib/setup-utils.js +96 -0
- package/lib/setup.js +192 -192
- package/lib/smart-merge.js +64 -0
- package/lib/symlink-utils.js +81 -0
- package/lib/task-ownership.js +117 -0
- package/lib/workflow-profiles.js +197 -197
- package/package.json +131 -128
- package/scripts/beads-context.sh +426 -0
- package/scripts/beads-context.test.js +567 -0
- package/scripts/behavioral-judge.sh +378 -0
- package/scripts/benchmark.js +85 -0
- package/scripts/branch-protection.js +183 -0
- package/scripts/check-agents.js +172 -0
- package/scripts/check-forge-token.js +98 -0
- package/scripts/commitlint.js +42 -0
- package/scripts/conflict-detect.sh +323 -0
- package/scripts/dep-guard-analyze.js +71 -0
- package/scripts/dep-guard.sh +789 -0
- package/scripts/eval_win.py +249 -0
- package/scripts/file-index.sh +493 -0
- package/scripts/forge-team/index.sh +86 -0
- package/scripts/forge-team/lib/agent-prompt.sh +52 -0
- package/scripts/forge-team/lib/claim.sh +256 -0
- package/scripts/forge-team/lib/dashboard.sh +341 -0
- package/scripts/forge-team/lib/epic.sh +332 -0
- package/scripts/forge-team/lib/hooks.sh +253 -0
- package/scripts/forge-team/lib/identity.sh +235 -0
- package/scripts/forge-team/lib/sync-github.sh +317 -0
- package/scripts/forge-team/lib/verify.sh +284 -0
- package/scripts/forge-team/lib/workload.sh +296 -0
- package/scripts/forge-team/tests/agent-prompt.test.sh +72 -0
- package/scripts/forge-team/tests/claim.test.sh +179 -0
- package/scripts/forge-team/tests/dashboard.test.sh +170 -0
- package/scripts/forge-team/tests/dispatcher.test.sh +79 -0
- package/scripts/forge-team/tests/epic.test.sh +176 -0
- package/scripts/forge-team/tests/hooks.test.sh +239 -0
- package/scripts/forge-team/tests/identity.test.sh +176 -0
- package/scripts/forge-team/tests/integration.test.sh +371 -0
- package/scripts/forge-team/tests/sync-github.test.sh +209 -0
- package/scripts/forge-team/tests/verify.test.sh +314 -0
- package/scripts/forge-team/tests/workflow-integration.test.sh +43 -0
- package/scripts/forge-team/tests/workload.test.sh +209 -0
- package/scripts/github-beads-sync/comment.mjs +64 -0
- package/scripts/github-beads-sync/config.mjs +148 -0
- package/scripts/github-beads-sync/github-api.mjs +131 -0
- package/scripts/github-beads-sync/index.mjs +332 -0
- package/scripts/github-beads-sync/label-mapper.mjs +54 -0
- package/scripts/github-beads-sync/mapping.mjs +78 -0
- package/scripts/github-beads-sync/reverse-sync-cli.mjs +31 -0
- package/scripts/github-beads-sync/reverse-sync.mjs +138 -0
- package/scripts/github-beads-sync/run-bd.mjs +159 -0
- package/scripts/github-beads-sync/sanitize.mjs +121 -0
- package/scripts/github-beads-sync.config.json +26 -0
- package/scripts/improve-command.js +375 -0
- package/scripts/lib/eval-runner.js +268 -0
- package/scripts/lib/eval-schema.js +135 -0
- package/scripts/lib/eval-storage.js +78 -0
- package/scripts/lib/grading.js +203 -0
- package/scripts/lib/jsonl-lock.sh +48 -0
- package/scripts/lib/sanitize.sh +116 -0
- package/scripts/lib/transcript-parser.js +63 -0
- package/scripts/lint.js +47 -0
- package/scripts/migrate-to-bun-test.js +412 -0
- package/scripts/pr-coordinator.sh +706 -0
- package/scripts/run-command-eval.js +236 -0
- package/scripts/smart-status.sh +809 -0
- package/scripts/sync-commands.js +571 -0
- package/scripts/sync-utils.sh +455 -0
- package/scripts/test-dashboard.js +123 -0
- package/scripts/test.js +46 -0
- package/scripts/validate.sh +94 -0
- package/skills/parallel-deep-research/SKILL.md +108 -108
- package/skills/parallel-deep-research/evals/README.md +27 -27
- package/skills/parallel-deep-research/evals/evals.json +62 -62
- package/skills/sonarcloud-analysis/SKILL.md +171 -171
- package/skills/sonarcloud-analysis/evals/README.md +27 -27
- package/skills/sonarcloud-analysis/evals/evals.json +50 -50
- package/skills/sonarcloud-analysis/references/api-reference.md +466 -466
- package/.cursor/hooks/state/continual-learning-index.json +0 -19
- package/.cursor/hooks/state/continual-learning.json +0 -8
|
@@ -1,498 +1,498 @@
|
|
|
1
|
-
const fs = require('node:fs');
|
|
2
|
-
const path = require('node:path');
|
|
3
|
-
const { parse } = require('@babel/parser');
|
|
4
|
-
const { normalizeRepoPath } = require('./path-utils.js');
|
|
5
|
-
const { extractSymbols } = require('./task-parser.js');
|
|
6
|
-
|
|
7
|
-
const SOURCE_EXTENSIONS = new Set(['.js', '.cjs', '.mjs', '.jsx', '.ts', '.tsx']);
|
|
8
|
-
const DEFAULT_EXCLUDED_DIRECTORIES = new Set([
|
|
9
|
-
'.git',
|
|
10
|
-
'.worktrees',
|
|
11
|
-
'coverage',
|
|
12
|
-
'dist',
|
|
13
|
-
'build',
|
|
14
|
-
'docs',
|
|
15
|
-
'fixtures',
|
|
16
|
-
'node_modules',
|
|
17
|
-
'test',
|
|
18
|
-
'test-env',
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
function isIdentifierStart(character) {
|
|
22
|
-
return /[A-Za-z_]/.test(character);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isIdentifierPart(character) {
|
|
26
|
-
return /\w/.test(character);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function listSourceFiles(rootDir) {
|
|
30
|
-
const results = [];
|
|
31
|
-
const queue = [rootDir];
|
|
32
|
-
|
|
33
|
-
while (queue.length > 0) {
|
|
34
|
-
const current = queue.pop();
|
|
35
|
-
let entries;
|
|
36
|
-
try {
|
|
37
|
-
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
38
|
-
} catch (_error) {
|
|
39
|
-
// Inaccessible directory (permissions, broken symlink) — skip silently
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const entry of entries) {
|
|
44
|
-
if (entry.isDirectory() && DEFAULT_EXCLUDED_DIRECTORIES.has(entry.name)) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const absolutePath = path.join(current, entry.name);
|
|
49
|
-
if (entry.isDirectory()) {
|
|
50
|
-
queue.push(absolutePath);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (SOURCE_EXTENSIONS.has(path.extname(entry.name))) {
|
|
55
|
-
results.push(absolutePath);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return results;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function extractTargetSymbols(taskContext) {
|
|
64
|
-
const symbols = new Set();
|
|
65
|
-
|
|
66
|
-
for (const task of taskContext.tasks) {
|
|
67
|
-
for (const symbol of extractSymbols(task.whatToImplement ?? '')) {
|
|
68
|
-
if (symbol && isIdentifierStart(symbol[0]) && Array.from(symbol).every(isIdentifierPart)) {
|
|
69
|
-
symbols.add(symbol);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return symbols;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function extractTargetFiles(taskContext) {
|
|
78
|
-
const files = new Set();
|
|
79
|
-
|
|
80
|
-
for (const task of taskContext.tasks) {
|
|
81
|
-
for (const file of task.files) {
|
|
82
|
-
files.add(normalizeRepoPath(file));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return files;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function resolveImportSource(sourceFile, specifier, repositoryRoot) {
|
|
90
|
-
if (!specifier || typeof specifier !== 'string' || !specifier.startsWith('.')) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const basePath = path.resolve(path.dirname(sourceFile), specifier);
|
|
95
|
-
const candidates = [
|
|
96
|
-
basePath,
|
|
97
|
-
`${basePath}.js`,
|
|
98
|
-
`${basePath}.cjs`,
|
|
99
|
-
`${basePath}.mjs`,
|
|
100
|
-
`${basePath}.jsx`,
|
|
101
|
-
`${basePath}.ts`,
|
|
102
|
-
`${basePath}.tsx`,
|
|
103
|
-
path.join(basePath, 'index.js'),
|
|
104
|
-
path.join(basePath, 'index.cjs'),
|
|
105
|
-
path.join(basePath, 'index.mjs'),
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
for (const candidate of candidates) {
|
|
109
|
-
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
110
|
-
return normalizeRepoPath(path.relative(repositoryRoot, candidate));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function isAstNode(value) {
|
|
118
|
-
return Boolean(value) && typeof value === 'object' && typeof value.type === 'string';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function walkNode(node, visitor) {
|
|
122
|
-
if (!isAstNode(node)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
visitor(node);
|
|
127
|
-
|
|
128
|
-
for (const value of Object.values(node)) {
|
|
129
|
-
if (Array.isArray(value)) {
|
|
130
|
-
for (const item of value) {
|
|
131
|
-
if (isAstNode(item)) {
|
|
132
|
-
walkNode(item, visitor);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (isAstNode(value)) {
|
|
139
|
-
walkNode(value, visitor);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function collectFileAnalysis(filePath, repositoryRoot) {
|
|
145
|
-
const relativeFile = normalizeRepoPath(path.relative(repositoryRoot, filePath));
|
|
146
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
147
|
-
const ast = parse(content, {
|
|
148
|
-
sourceType: 'unambiguous',
|
|
149
|
-
errorRecovery: true,
|
|
150
|
-
plugins: ['jsx', 'typescript'],
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const directImports = new Map();
|
|
154
|
-
const defaultImports = new Map();
|
|
155
|
-
const namespaceImports = new Map();
|
|
156
|
-
const directCalls = new Set();
|
|
157
|
-
const memberCalls = [];
|
|
158
|
-
const defaultExportSymbols = new Set();
|
|
159
|
-
|
|
160
|
-
walkNode(ast, (node) => {
|
|
161
|
-
recordImportDeclaration(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports);
|
|
162
|
-
recordRequireDeclarator(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports);
|
|
163
|
-
recordCallExpression(node, directCalls, memberCalls);
|
|
164
|
-
recordDefaultExport(node, defaultExportSymbols);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
file: relativeFile,
|
|
169
|
-
directImports,
|
|
170
|
-
defaultImports,
|
|
171
|
-
namespaceImports,
|
|
172
|
-
directCalls,
|
|
173
|
-
memberCalls,
|
|
174
|
-
defaultExportSymbols,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function recordImportDeclaration(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports) {
|
|
179
|
-
if (node.type !== 'ImportDeclaration') {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const resolvedSource = resolveImportSource(filePath, node.source?.value, repositoryRoot);
|
|
184
|
-
if (!resolvedSource) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
for (const specifier of node.specifiers ?? []) {
|
|
189
|
-
if (specifier.type === 'ImportSpecifier') {
|
|
190
|
-
directImports.set(specifier.local.name, {
|
|
191
|
-
sourceFile: resolvedSource,
|
|
192
|
-
importedName: specifier.imported.name,
|
|
193
|
-
});
|
|
194
|
-
} else if (specifier.type === 'ImportDefaultSpecifier' && specifier.local?.name) {
|
|
195
|
-
defaultImports.set(specifier.local.name, {
|
|
196
|
-
sourceFile: resolvedSource,
|
|
197
|
-
});
|
|
198
|
-
} else if (specifier.local?.name) {
|
|
199
|
-
namespaceImports.set(specifier.local.name, {
|
|
200
|
-
sourceFile: resolvedSource,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function recordRequireDeclarator(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports) {
|
|
207
|
-
if (
|
|
208
|
-
node.type !== 'VariableDeclarator'
|
|
209
|
-
|| node.init?.type !== 'CallExpression'
|
|
210
|
-
|| node.init.callee?.type !== 'Identifier'
|
|
211
|
-
|| node.init.callee.name !== 'require'
|
|
212
|
-
|| node.init.arguments?.[0]?.type !== 'StringLiteral'
|
|
213
|
-
) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const resolvedSource = resolveImportSource(
|
|
218
|
-
filePath,
|
|
219
|
-
node.init.arguments[0].value,
|
|
220
|
-
repositoryRoot,
|
|
221
|
-
);
|
|
222
|
-
if (!resolvedSource) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (node.id.type === 'ObjectPattern') {
|
|
227
|
-
for (const property of node.id.properties ?? []) {
|
|
228
|
-
if (property.type !== 'ObjectProperty' || property.value?.type !== 'Identifier') {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const importedName = property.key?.name ?? property.key?.value;
|
|
233
|
-
if (!importedName) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
directImports.set(property.value.name, {
|
|
238
|
-
sourceFile: resolvedSource,
|
|
239
|
-
importedName,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (node.id.type === 'Identifier') {
|
|
246
|
-
defaultImports.set(node.id.name, {
|
|
247
|
-
sourceFile: resolvedSource,
|
|
248
|
-
});
|
|
249
|
-
namespaceImports.set(node.id.name, {
|
|
250
|
-
sourceFile: resolvedSource,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function recordCallExpression(node, directCalls, memberCalls) {
|
|
256
|
-
if (node.type !== 'CallExpression') {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (node.callee?.type === 'Identifier') {
|
|
261
|
-
directCalls.add(node.callee.name);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
node.callee?.type === 'MemberExpression'
|
|
267
|
-
&& node.callee.object?.type === 'Identifier'
|
|
268
|
-
&& !node.callee.computed
|
|
269
|
-
&& node.callee.property?.type === 'Identifier'
|
|
270
|
-
) {
|
|
271
|
-
memberCalls.push({
|
|
272
|
-
objectName: node.callee.object.name,
|
|
273
|
-
propertyName: node.callee.property.name,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function recordDefaultExport(node, defaultExportSymbols) {
|
|
279
|
-
if (node.type === 'ExportDefaultDeclaration') {
|
|
280
|
-
if (node.declaration?.type === 'Identifier') {
|
|
281
|
-
defaultExportSymbols.add(node.declaration.name);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (
|
|
286
|
-
(node.declaration?.type === 'FunctionDeclaration' || node.declaration?.type === 'ClassDeclaration')
|
|
287
|
-
&& node.declaration.id?.name
|
|
288
|
-
) {
|
|
289
|
-
defaultExportSymbols.add(node.declaration.id.name);
|
|
290
|
-
}
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (
|
|
295
|
-
node.type === 'AssignmentExpression'
|
|
296
|
-
&& node.operator === '='
|
|
297
|
-
&& node.left?.type === 'MemberExpression'
|
|
298
|
-
&& node.left.object?.type === 'Identifier'
|
|
299
|
-
&& node.left.object.name === 'module'
|
|
300
|
-
&& !node.left.computed
|
|
301
|
-
&& node.left.property?.type === 'Identifier'
|
|
302
|
-
&& node.left.property.name === 'exports'
|
|
303
|
-
) {
|
|
304
|
-
if (node.right?.type === 'Identifier') {
|
|
305
|
-
defaultExportSymbols.add(node.right.name);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (
|
|
310
|
-
(node.right?.type === 'FunctionExpression' || node.right?.type === 'ClassExpression')
|
|
311
|
-
&& node.right.id?.name
|
|
312
|
-
) {
|
|
313
|
-
defaultExportSymbols.add(node.right.id.name);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function issueTouchesFile(issue, filePath) {
|
|
319
|
-
if (issue.files.includes(filePath)) {
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return issue.contracts.some((contract) => typeof contract === 'string' && contract.startsWith(`${filePath}:`));
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function mergeEvidence(evidence) {
|
|
327
|
-
const seen = new Set();
|
|
328
|
-
return evidence.filter((item) => {
|
|
329
|
-
const key = `${item.type}:${item.consumerFile}:${item.targetFile}:${item.symbol}`;
|
|
330
|
-
if (seen.has(key)) {
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
seen.add(key);
|
|
334
|
-
return true;
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function collectDirectImportEvidence(analysis, targetFiles, targetSymbols) {
|
|
339
|
-
const evidence = [];
|
|
340
|
-
for (const [localName, importMeta] of analysis.directImports.entries()) {
|
|
341
|
-
if (!targetFiles.has(importMeta.sourceFile) || !targetSymbols.has(importMeta.importedName)) {
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
evidence.push({
|
|
346
|
-
type: 'import',
|
|
347
|
-
consumerFile: analysis.file,
|
|
348
|
-
sourceFile: analysis.file,
|
|
349
|
-
scoreContribution: 1,
|
|
350
|
-
targetFile: importMeta.sourceFile,
|
|
351
|
-
symbol: importMeta.importedName,
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
if (analysis.directCalls.has(localName)) {
|
|
355
|
-
evidence.push({
|
|
356
|
-
type: 'call',
|
|
357
|
-
consumerFile: analysis.file,
|
|
358
|
-
sourceFile: analysis.file,
|
|
359
|
-
scoreContribution: 1,
|
|
360
|
-
targetFile: importMeta.sourceFile,
|
|
361
|
-
symbol: importMeta.importedName,
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return evidence;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
function collectDefaultImportEvidence(analysis, targetFiles, targetSymbols, defaultExportSymbolsByFile) {
|
|
369
|
-
const evidence = [];
|
|
370
|
-
for (const [localName, importMeta] of analysis.defaultImports.entries()) {
|
|
371
|
-
if (!targetFiles.has(importMeta.sourceFile)) {
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const defaultExportSymbols = defaultExportSymbolsByFile.get(importMeta.sourceFile) ?? new Set();
|
|
376
|
-
const matchedSymbol = targetSymbols.has(localName)
|
|
377
|
-
? localName
|
|
378
|
-
: Array.from(defaultExportSymbols).find((symbol) => targetSymbols.has(symbol));
|
|
379
|
-
|
|
380
|
-
if (!matchedSymbol) {
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
evidence.push({
|
|
385
|
-
type: 'import',
|
|
386
|
-
consumerFile: analysis.file,
|
|
387
|
-
sourceFile: analysis.file,
|
|
388
|
-
scoreContribution: 1,
|
|
389
|
-
targetFile: importMeta.sourceFile,
|
|
390
|
-
symbol: matchedSymbol,
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
if (analysis.directCalls.has(localName)) {
|
|
394
|
-
evidence.push({
|
|
395
|
-
type: 'call',
|
|
396
|
-
consumerFile: analysis.file,
|
|
397
|
-
sourceFile: analysis.file,
|
|
398
|
-
scoreContribution: 1,
|
|
399
|
-
targetFile: importMeta.sourceFile,
|
|
400
|
-
symbol: matchedSymbol,
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return evidence;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
function collectMemberCallEvidence(analysis, targetFiles, targetSymbols) {
|
|
408
|
-
const evidence = [];
|
|
409
|
-
for (const memberCall of analysis.memberCalls) {
|
|
410
|
-
const namespaceImport = analysis.namespaceImports.get(memberCall.objectName);
|
|
411
|
-
if (!namespaceImport) {
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
if (!targetFiles.has(namespaceImport.sourceFile) || !targetSymbols.has(memberCall.propertyName)) {
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
evidence.push({
|
|
420
|
-
type: 'call',
|
|
421
|
-
consumerFile: analysis.file,
|
|
422
|
-
sourceFile: analysis.file,
|
|
423
|
-
scoreContribution: 1,
|
|
424
|
-
targetFile: namespaceImport.sourceFile,
|
|
425
|
-
symbol: memberCall.propertyName,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
return evidence;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function scoreImportDependencies(normalizedInput) {
|
|
432
|
-
const targetSymbols = extractTargetSymbols(normalizedInput.taskContext);
|
|
433
|
-
const targetFiles = extractTargetFiles(normalizedInput.taskContext);
|
|
434
|
-
|
|
435
|
-
if (targetSymbols.size === 0 || targetFiles.size === 0) {
|
|
436
|
-
return {
|
|
437
|
-
score: 0,
|
|
438
|
-
findings: [],
|
|
439
|
-
evidence: [],
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
const findings = [];
|
|
444
|
-
const evidence = [];
|
|
445
|
-
const analyses = [];
|
|
446
|
-
|
|
447
|
-
for (const absoluteFile of listSourceFiles(normalizedInput.repositoryRoot)) {
|
|
448
|
-
let analysis;
|
|
449
|
-
try {
|
|
450
|
-
analysis = collectFileAnalysis(absoluteFile, normalizedInput.repositoryRoot);
|
|
451
|
-
} catch (_error) {
|
|
452
|
-
// Unparseable file (binary, syntax error) — skip silently
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
analyses.push(analysis);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const defaultExportSymbolsByFile = new Map(
|
|
459
|
-
analyses.map((analysis) => [analysis.file, analysis.defaultExportSymbols]),
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
for (const analysis of analyses) {
|
|
463
|
-
const fileEvidence = [
|
|
464
|
-
...collectDirectImportEvidence(analysis, targetFiles, targetSymbols),
|
|
465
|
-
...collectDefaultImportEvidence(analysis, targetFiles, targetSymbols, defaultExportSymbolsByFile),
|
|
466
|
-
...collectMemberCallEvidence(analysis, targetFiles, targetSymbols),
|
|
467
|
-
];
|
|
468
|
-
|
|
469
|
-
if (fileEvidence.length === 0) {
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const touchedIssues = normalizedInput.openIssues.filter((issue) => issueTouchesFile(issue, analysis.file));
|
|
474
|
-
for (const issue of touchedIssues) {
|
|
475
|
-
const issueEvidence = mergeEvidence(fileEvidence);
|
|
476
|
-
const score = issueEvidence.length;
|
|
477
|
-
|
|
478
|
-
findings.push({
|
|
479
|
-
sourceIssueId: normalizedInput.currentIssue.id,
|
|
480
|
-
targetIssueId: issue.id,
|
|
481
|
-
score,
|
|
482
|
-
evidence: issueEvidence,
|
|
483
|
-
});
|
|
484
|
-
evidence.push(...issueEvidence);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
return {
|
|
489
|
-
score: findings.reduce((total, finding) => total + finding.score, 0),
|
|
490
|
-
findings,
|
|
491
|
-
evidence: mergeEvidence(evidence),
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
module.exports = {
|
|
496
|
-
normalizeRepoPath,
|
|
497
|
-
scoreImportDependencies,
|
|
498
|
-
};
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { parse } = require('@babel/parser');
|
|
4
|
+
const { normalizeRepoPath } = require('./path-utils.js');
|
|
5
|
+
const { extractSymbols } = require('./task-parser.js');
|
|
6
|
+
|
|
7
|
+
const SOURCE_EXTENSIONS = new Set(['.js', '.cjs', '.mjs', '.jsx', '.ts', '.tsx']);
|
|
8
|
+
const DEFAULT_EXCLUDED_DIRECTORIES = new Set([
|
|
9
|
+
'.git',
|
|
10
|
+
'.worktrees',
|
|
11
|
+
'coverage',
|
|
12
|
+
'dist',
|
|
13
|
+
'build',
|
|
14
|
+
'docs',
|
|
15
|
+
'fixtures',
|
|
16
|
+
'node_modules',
|
|
17
|
+
'test',
|
|
18
|
+
'test-env',
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
function isIdentifierStart(character) {
|
|
22
|
+
return /[A-Za-z_]/.test(character);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isIdentifierPart(character) {
|
|
26
|
+
return /\w/.test(character);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function listSourceFiles(rootDir) {
|
|
30
|
+
const results = [];
|
|
31
|
+
const queue = [rootDir];
|
|
32
|
+
|
|
33
|
+
while (queue.length > 0) {
|
|
34
|
+
const current = queue.pop();
|
|
35
|
+
let entries;
|
|
36
|
+
try {
|
|
37
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
38
|
+
} catch (_error) {
|
|
39
|
+
// Inaccessible directory (permissions, broken symlink) — skip silently
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.isDirectory() && DEFAULT_EXCLUDED_DIRECTORIES.has(entry.name)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const absolutePath = path.join(current, entry.name);
|
|
49
|
+
if (entry.isDirectory()) {
|
|
50
|
+
queue.push(absolutePath);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (SOURCE_EXTENSIONS.has(path.extname(entry.name))) {
|
|
55
|
+
results.push(absolutePath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function extractTargetSymbols(taskContext) {
|
|
64
|
+
const symbols = new Set();
|
|
65
|
+
|
|
66
|
+
for (const task of taskContext.tasks) {
|
|
67
|
+
for (const symbol of extractSymbols(task.whatToImplement ?? '')) {
|
|
68
|
+
if (symbol && isIdentifierStart(symbol[0]) && Array.from(symbol).every(isIdentifierPart)) {
|
|
69
|
+
symbols.add(symbol);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return symbols;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function extractTargetFiles(taskContext) {
|
|
78
|
+
const files = new Set();
|
|
79
|
+
|
|
80
|
+
for (const task of taskContext.tasks) {
|
|
81
|
+
for (const file of task.files) {
|
|
82
|
+
files.add(normalizeRepoPath(file));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return files;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function resolveImportSource(sourceFile, specifier, repositoryRoot) {
|
|
90
|
+
if (!specifier || typeof specifier !== 'string' || !specifier.startsWith('.')) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const basePath = path.resolve(path.dirname(sourceFile), specifier);
|
|
95
|
+
const candidates = [
|
|
96
|
+
basePath,
|
|
97
|
+
`${basePath}.js`,
|
|
98
|
+
`${basePath}.cjs`,
|
|
99
|
+
`${basePath}.mjs`,
|
|
100
|
+
`${basePath}.jsx`,
|
|
101
|
+
`${basePath}.ts`,
|
|
102
|
+
`${basePath}.tsx`,
|
|
103
|
+
path.join(basePath, 'index.js'),
|
|
104
|
+
path.join(basePath, 'index.cjs'),
|
|
105
|
+
path.join(basePath, 'index.mjs'),
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
for (const candidate of candidates) {
|
|
109
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
110
|
+
return normalizeRepoPath(path.relative(repositoryRoot, candidate));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function isAstNode(value) {
|
|
118
|
+
return Boolean(value) && typeof value === 'object' && typeof value.type === 'string';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function walkNode(node, visitor) {
|
|
122
|
+
if (!isAstNode(node)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
visitor(node);
|
|
127
|
+
|
|
128
|
+
for (const value of Object.values(node)) {
|
|
129
|
+
if (Array.isArray(value)) {
|
|
130
|
+
for (const item of value) {
|
|
131
|
+
if (isAstNode(item)) {
|
|
132
|
+
walkNode(item, visitor);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (isAstNode(value)) {
|
|
139
|
+
walkNode(value, visitor);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function collectFileAnalysis(filePath, repositoryRoot) {
|
|
145
|
+
const relativeFile = normalizeRepoPath(path.relative(repositoryRoot, filePath));
|
|
146
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
147
|
+
const ast = parse(content, {
|
|
148
|
+
sourceType: 'unambiguous',
|
|
149
|
+
errorRecovery: true,
|
|
150
|
+
plugins: ['jsx', 'typescript'],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const directImports = new Map();
|
|
154
|
+
const defaultImports = new Map();
|
|
155
|
+
const namespaceImports = new Map();
|
|
156
|
+
const directCalls = new Set();
|
|
157
|
+
const memberCalls = [];
|
|
158
|
+
const defaultExportSymbols = new Set();
|
|
159
|
+
|
|
160
|
+
walkNode(ast, (node) => {
|
|
161
|
+
recordImportDeclaration(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports);
|
|
162
|
+
recordRequireDeclarator(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports);
|
|
163
|
+
recordCallExpression(node, directCalls, memberCalls);
|
|
164
|
+
recordDefaultExport(node, defaultExportSymbols);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
file: relativeFile,
|
|
169
|
+
directImports,
|
|
170
|
+
defaultImports,
|
|
171
|
+
namespaceImports,
|
|
172
|
+
directCalls,
|
|
173
|
+
memberCalls,
|
|
174
|
+
defaultExportSymbols,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function recordImportDeclaration(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports) {
|
|
179
|
+
if (node.type !== 'ImportDeclaration') {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const resolvedSource = resolveImportSource(filePath, node.source?.value, repositoryRoot);
|
|
184
|
+
if (!resolvedSource) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
for (const specifier of node.specifiers ?? []) {
|
|
189
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
190
|
+
directImports.set(specifier.local.name, {
|
|
191
|
+
sourceFile: resolvedSource,
|
|
192
|
+
importedName: specifier.imported.name,
|
|
193
|
+
});
|
|
194
|
+
} else if (specifier.type === 'ImportDefaultSpecifier' && specifier.local?.name) {
|
|
195
|
+
defaultImports.set(specifier.local.name, {
|
|
196
|
+
sourceFile: resolvedSource,
|
|
197
|
+
});
|
|
198
|
+
} else if (specifier.local?.name) {
|
|
199
|
+
namespaceImports.set(specifier.local.name, {
|
|
200
|
+
sourceFile: resolvedSource,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function recordRequireDeclarator(node, filePath, repositoryRoot, directImports, defaultImports, namespaceImports) {
|
|
207
|
+
if (
|
|
208
|
+
node.type !== 'VariableDeclarator'
|
|
209
|
+
|| node.init?.type !== 'CallExpression'
|
|
210
|
+
|| node.init.callee?.type !== 'Identifier'
|
|
211
|
+
|| node.init.callee.name !== 'require'
|
|
212
|
+
|| node.init.arguments?.[0]?.type !== 'StringLiteral'
|
|
213
|
+
) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const resolvedSource = resolveImportSource(
|
|
218
|
+
filePath,
|
|
219
|
+
node.init.arguments[0].value,
|
|
220
|
+
repositoryRoot,
|
|
221
|
+
);
|
|
222
|
+
if (!resolvedSource) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (node.id.type === 'ObjectPattern') {
|
|
227
|
+
for (const property of node.id.properties ?? []) {
|
|
228
|
+
if (property.type !== 'ObjectProperty' || property.value?.type !== 'Identifier') {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const importedName = property.key?.name ?? property.key?.value;
|
|
233
|
+
if (!importedName) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
directImports.set(property.value.name, {
|
|
238
|
+
sourceFile: resolvedSource,
|
|
239
|
+
importedName,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (node.id.type === 'Identifier') {
|
|
246
|
+
defaultImports.set(node.id.name, {
|
|
247
|
+
sourceFile: resolvedSource,
|
|
248
|
+
});
|
|
249
|
+
namespaceImports.set(node.id.name, {
|
|
250
|
+
sourceFile: resolvedSource,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function recordCallExpression(node, directCalls, memberCalls) {
|
|
256
|
+
if (node.type !== 'CallExpression') {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (node.callee?.type === 'Identifier') {
|
|
261
|
+
directCalls.add(node.callee.name);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (
|
|
266
|
+
node.callee?.type === 'MemberExpression'
|
|
267
|
+
&& node.callee.object?.type === 'Identifier'
|
|
268
|
+
&& !node.callee.computed
|
|
269
|
+
&& node.callee.property?.type === 'Identifier'
|
|
270
|
+
) {
|
|
271
|
+
memberCalls.push({
|
|
272
|
+
objectName: node.callee.object.name,
|
|
273
|
+
propertyName: node.callee.property.name,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function recordDefaultExport(node, defaultExportSymbols) {
|
|
279
|
+
if (node.type === 'ExportDefaultDeclaration') {
|
|
280
|
+
if (node.declaration?.type === 'Identifier') {
|
|
281
|
+
defaultExportSymbols.add(node.declaration.name);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (
|
|
286
|
+
(node.declaration?.type === 'FunctionDeclaration' || node.declaration?.type === 'ClassDeclaration')
|
|
287
|
+
&& node.declaration.id?.name
|
|
288
|
+
) {
|
|
289
|
+
defaultExportSymbols.add(node.declaration.id.name);
|
|
290
|
+
}
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (
|
|
295
|
+
node.type === 'AssignmentExpression'
|
|
296
|
+
&& node.operator === '='
|
|
297
|
+
&& node.left?.type === 'MemberExpression'
|
|
298
|
+
&& node.left.object?.type === 'Identifier'
|
|
299
|
+
&& node.left.object.name === 'module'
|
|
300
|
+
&& !node.left.computed
|
|
301
|
+
&& node.left.property?.type === 'Identifier'
|
|
302
|
+
&& node.left.property.name === 'exports'
|
|
303
|
+
) {
|
|
304
|
+
if (node.right?.type === 'Identifier') {
|
|
305
|
+
defaultExportSymbols.add(node.right.name);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (
|
|
310
|
+
(node.right?.type === 'FunctionExpression' || node.right?.type === 'ClassExpression')
|
|
311
|
+
&& node.right.id?.name
|
|
312
|
+
) {
|
|
313
|
+
defaultExportSymbols.add(node.right.id.name);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function issueTouchesFile(issue, filePath) {
|
|
319
|
+
if (issue.files.includes(filePath)) {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return issue.contracts.some((contract) => typeof contract === 'string' && contract.startsWith(`${filePath}:`));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function mergeEvidence(evidence) {
|
|
327
|
+
const seen = new Set();
|
|
328
|
+
return evidence.filter((item) => {
|
|
329
|
+
const key = `${item.type}:${item.consumerFile}:${item.targetFile}:${item.symbol}`;
|
|
330
|
+
if (seen.has(key)) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
seen.add(key);
|
|
334
|
+
return true;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function collectDirectImportEvidence(analysis, targetFiles, targetSymbols) {
|
|
339
|
+
const evidence = [];
|
|
340
|
+
for (const [localName, importMeta] of analysis.directImports.entries()) {
|
|
341
|
+
if (!targetFiles.has(importMeta.sourceFile) || !targetSymbols.has(importMeta.importedName)) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
evidence.push({
|
|
346
|
+
type: 'import',
|
|
347
|
+
consumerFile: analysis.file,
|
|
348
|
+
sourceFile: analysis.file,
|
|
349
|
+
scoreContribution: 1,
|
|
350
|
+
targetFile: importMeta.sourceFile,
|
|
351
|
+
symbol: importMeta.importedName,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
if (analysis.directCalls.has(localName)) {
|
|
355
|
+
evidence.push({
|
|
356
|
+
type: 'call',
|
|
357
|
+
consumerFile: analysis.file,
|
|
358
|
+
sourceFile: analysis.file,
|
|
359
|
+
scoreContribution: 1,
|
|
360
|
+
targetFile: importMeta.sourceFile,
|
|
361
|
+
symbol: importMeta.importedName,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return evidence;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function collectDefaultImportEvidence(analysis, targetFiles, targetSymbols, defaultExportSymbolsByFile) {
|
|
369
|
+
const evidence = [];
|
|
370
|
+
for (const [localName, importMeta] of analysis.defaultImports.entries()) {
|
|
371
|
+
if (!targetFiles.has(importMeta.sourceFile)) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const defaultExportSymbols = defaultExportSymbolsByFile.get(importMeta.sourceFile) ?? new Set();
|
|
376
|
+
const matchedSymbol = targetSymbols.has(localName)
|
|
377
|
+
? localName
|
|
378
|
+
: Array.from(defaultExportSymbols).find((symbol) => targetSymbols.has(symbol));
|
|
379
|
+
|
|
380
|
+
if (!matchedSymbol) {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
evidence.push({
|
|
385
|
+
type: 'import',
|
|
386
|
+
consumerFile: analysis.file,
|
|
387
|
+
sourceFile: analysis.file,
|
|
388
|
+
scoreContribution: 1,
|
|
389
|
+
targetFile: importMeta.sourceFile,
|
|
390
|
+
symbol: matchedSymbol,
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
if (analysis.directCalls.has(localName)) {
|
|
394
|
+
evidence.push({
|
|
395
|
+
type: 'call',
|
|
396
|
+
consumerFile: analysis.file,
|
|
397
|
+
sourceFile: analysis.file,
|
|
398
|
+
scoreContribution: 1,
|
|
399
|
+
targetFile: importMeta.sourceFile,
|
|
400
|
+
symbol: matchedSymbol,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return evidence;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function collectMemberCallEvidence(analysis, targetFiles, targetSymbols) {
|
|
408
|
+
const evidence = [];
|
|
409
|
+
for (const memberCall of analysis.memberCalls) {
|
|
410
|
+
const namespaceImport = analysis.namespaceImports.get(memberCall.objectName);
|
|
411
|
+
if (!namespaceImport) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (!targetFiles.has(namespaceImport.sourceFile) || !targetSymbols.has(memberCall.propertyName)) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
evidence.push({
|
|
420
|
+
type: 'call',
|
|
421
|
+
consumerFile: analysis.file,
|
|
422
|
+
sourceFile: analysis.file,
|
|
423
|
+
scoreContribution: 1,
|
|
424
|
+
targetFile: namespaceImport.sourceFile,
|
|
425
|
+
symbol: memberCall.propertyName,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return evidence;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function scoreImportDependencies(normalizedInput) {
|
|
432
|
+
const targetSymbols = extractTargetSymbols(normalizedInput.taskContext);
|
|
433
|
+
const targetFiles = extractTargetFiles(normalizedInput.taskContext);
|
|
434
|
+
|
|
435
|
+
if (targetSymbols.size === 0 || targetFiles.size === 0) {
|
|
436
|
+
return {
|
|
437
|
+
score: 0,
|
|
438
|
+
findings: [],
|
|
439
|
+
evidence: [],
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const findings = [];
|
|
444
|
+
const evidence = [];
|
|
445
|
+
const analyses = [];
|
|
446
|
+
|
|
447
|
+
for (const absoluteFile of listSourceFiles(normalizedInput.repositoryRoot)) {
|
|
448
|
+
let analysis;
|
|
449
|
+
try {
|
|
450
|
+
analysis = collectFileAnalysis(absoluteFile, normalizedInput.repositoryRoot);
|
|
451
|
+
} catch (_error) {
|
|
452
|
+
// Unparseable file (binary, syntax error) — skip silently
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
analyses.push(analysis);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const defaultExportSymbolsByFile = new Map(
|
|
459
|
+
analyses.map((analysis) => [analysis.file, analysis.defaultExportSymbols]),
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
for (const analysis of analyses) {
|
|
463
|
+
const fileEvidence = [
|
|
464
|
+
...collectDirectImportEvidence(analysis, targetFiles, targetSymbols),
|
|
465
|
+
...collectDefaultImportEvidence(analysis, targetFiles, targetSymbols, defaultExportSymbolsByFile),
|
|
466
|
+
...collectMemberCallEvidence(analysis, targetFiles, targetSymbols),
|
|
467
|
+
];
|
|
468
|
+
|
|
469
|
+
if (fileEvidence.length === 0) {
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const touchedIssues = normalizedInput.openIssues.filter((issue) => issueTouchesFile(issue, analysis.file));
|
|
474
|
+
for (const issue of touchedIssues) {
|
|
475
|
+
const issueEvidence = mergeEvidence(fileEvidence);
|
|
476
|
+
const score = issueEvidence.length;
|
|
477
|
+
|
|
478
|
+
findings.push({
|
|
479
|
+
sourceIssueId: normalizedInput.currentIssue.id,
|
|
480
|
+
targetIssueId: issue.id,
|
|
481
|
+
score,
|
|
482
|
+
evidence: issueEvidence,
|
|
483
|
+
});
|
|
484
|
+
evidence.push(...issueEvidence);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return {
|
|
489
|
+
score: findings.reduce((total, finding) => total + finding.score, 0),
|
|
490
|
+
findings,
|
|
491
|
+
evidence: mergeEvidence(evidence),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
module.exports = {
|
|
496
|
+
normalizeRepoPath,
|
|
497
|
+
scoreImportDependencies,
|
|
498
|
+
};
|