edsger 0.51.0 → 0.53.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/.claude/settings.local.json +23 -3
- package/.env.local +12 -0
- package/dist/commands/find-smells/index.d.ts +21 -0
- package/dist/commands/find-smells/index.js +65 -0
- package/dist/index.js +29 -0
- package/dist/phases/find-bugs/index.js +7 -92
- package/dist/phases/find-bugs/state.d.ts +10 -35
- package/dist/phases/find-bugs/state.js +12 -120
- package/dist/phases/find-features/index.js +16 -83
- package/dist/phases/find-features/prompts.d.ts +7 -1
- package/dist/phases/find-features/prompts.js +31 -11
- package/dist/phases/find-features/state.d.ts +15 -19
- package/dist/phases/find-features/state.js +17 -89
- package/dist/phases/find-features/types.d.ts +1 -1
- package/dist/phases/find-shared/git.d.ts +24 -0
- package/dist/phases/find-shared/git.js +60 -0
- package/dist/phases/find-shared/mcp.d.ts +33 -0
- package/dist/phases/find-shared/mcp.js +69 -0
- package/dist/phases/find-shared/scan-state.d.ts +33 -0
- package/dist/phases/find-shared/scan-state.js +112 -0
- package/dist/phases/find-smells/index.d.ts +47 -0
- package/dist/phases/find-smells/index.js +278 -0
- package/dist/phases/find-smells/prompts.d.ts +30 -0
- package/dist/phases/find-smells/prompts.js +129 -0
- package/dist/phases/find-smells/state.d.ts +21 -0
- package/dist/phases/find-smells/state.js +17 -0
- package/dist/phases/find-smells/types.d.ts +51 -0
- package/dist/phases/find-smells/types.js +64 -0
- package/dist/phases/pr-execution/context.js +40 -32
- package/dist/phases/pr-splitting/context.js +18 -13
- package/dist/utils/github-repo-info.d.ts +13 -1
- package/dist/utils/github-repo-info.js +32 -6
- package/package.json +1 -1
- package/vitest.config.ts +2 -0
- package/dist/api/__tests__/app-store.test.d.ts +0 -7
- package/dist/api/__tests__/app-store.test.js +0 -60
- package/dist/api/__tests__/intelligence.test.d.ts +0 -11
- package/dist/api/__tests__/intelligence.test.js +0 -315
- package/dist/api/features/__tests__/feature-utils.test.d.ts +0 -4
- package/dist/api/features/__tests__/feature-utils.test.js +0 -370
- package/dist/api/features/__tests__/status-updater.test.d.ts +0 -4
- package/dist/api/features/__tests__/status-updater.test.js +0 -88
- package/dist/api/features/approval-checker.d.ts +0 -20
- package/dist/api/features/approval-checker.js +0 -152
- package/dist/api/features/batch-operations.d.ts +0 -17
- package/dist/api/features/batch-operations.js +0 -100
- package/dist/api/features/feature-utils.d.ts +0 -23
- package/dist/api/features/feature-utils.js +0 -80
- package/dist/api/features/get-feature.d.ts +0 -5
- package/dist/api/features/get-feature.js +0 -21
- package/dist/api/features/index.d.ts +0 -8
- package/dist/api/features/index.js +0 -10
- package/dist/api/features/status-updater.d.ts +0 -41
- package/dist/api/features/status-updater.js +0 -122
- package/dist/api/features/test-cases.d.ts +0 -29
- package/dist/api/features/test-cases.js +0 -110
- package/dist/api/features/update-feature.d.ts +0 -20
- package/dist/api/features/update-feature.js +0 -83
- package/dist/api/features/user-stories.d.ts +0 -21
- package/dist/api/features/user-stories.js +0 -88
- package/dist/commands/agent-workflow/feature-worker.d.ts +0 -14
- package/dist/commands/agent-workflow/feature-worker.js +0 -65
- package/dist/commands/build/__tests__/build.test.d.ts +0 -5
- package/dist/commands/build/__tests__/build.test.js +0 -206
- package/dist/commands/build/__tests__/detect-project.test.d.ts +0 -6
- package/dist/commands/build/__tests__/detect-project.test.js +0 -160
- package/dist/commands/build/__tests__/run-build.test.d.ts +0 -6
- package/dist/commands/build/__tests__/run-build.test.js +0 -433
- package/dist/commands/intelligence/__tests__/command.test.d.ts +0 -4
- package/dist/commands/intelligence/__tests__/command.test.js +0 -48
- package/dist/commands/workflow/core/__tests__/feature-filter.test.d.ts +0 -5
- package/dist/commands/workflow/core/__tests__/feature-filter.test.js +0 -316
- package/dist/commands/workflow/core/__tests__/pipeline-evaluator.test.d.ts +0 -4
- package/dist/commands/workflow/core/__tests__/pipeline-evaluator.test.js +0 -397
- package/dist/commands/workflow/core/__tests__/state-manager.test.d.ts +0 -4
- package/dist/commands/workflow/core/__tests__/state-manager.test.js +0 -384
- package/dist/commands/workflow/core/feature-filter.d.ts +0 -16
- package/dist/commands/workflow/core/feature-filter.js +0 -47
- package/dist/commands/workflow/feature-coordinator.d.ts +0 -18
- package/dist/commands/workflow/feature-coordinator.js +0 -161
- package/dist/config/__tests__/config.test.d.ts +0 -4
- package/dist/config/__tests__/config.test.js +0 -286
- package/dist/config/__tests__/feature-status.test.d.ts +0 -4
- package/dist/config/__tests__/feature-status.test.js +0 -111
- package/dist/config/feature-status.d.ts +0 -56
- package/dist/config/feature-status.js +0 -130
- package/dist/errors/__tests__/index.test.d.ts +0 -4
- package/dist/errors/__tests__/index.test.js +0 -349
- package/dist/phases/app-store-generation/__tests__/agent.test.d.ts +0 -5
- package/dist/phases/app-store-generation/__tests__/agent.test.js +0 -142
- package/dist/phases/app-store-generation/__tests__/context.test.d.ts +0 -4
- package/dist/phases/app-store-generation/__tests__/context.test.js +0 -284
- package/dist/phases/app-store-generation/__tests__/prompts.test.d.ts +0 -4
- package/dist/phases/app-store-generation/__tests__/prompts.test.js +0 -122
- package/dist/phases/app-store-generation/__tests__/screenshot-composer.test.d.ts +0 -5
- package/dist/phases/app-store-generation/__tests__/screenshot-composer.test.js +0 -826
- package/dist/phases/code-review/__tests__/diff-utils.test.d.ts +0 -1
- package/dist/phases/code-review/__tests__/diff-utils.test.js +0 -101
- package/dist/phases/feature-analysis/agent.d.ts +0 -13
- package/dist/phases/feature-analysis/agent.js +0 -112
- package/dist/phases/feature-analysis/context.d.ts +0 -24
- package/dist/phases/feature-analysis/context.js +0 -138
- package/dist/phases/feature-analysis/index.d.ts +0 -8
- package/dist/phases/feature-analysis/index.js +0 -199
- package/dist/phases/feature-analysis/outcome.d.ts +0 -40
- package/dist/phases/feature-analysis/outcome.js +0 -280
- package/dist/phases/feature-analysis/prompts.d.ts +0 -10
- package/dist/phases/feature-analysis/prompts.js +0 -212
- package/dist/phases/feature-analysis-verification/agent.d.ts +0 -33
- package/dist/phases/feature-analysis-verification/agent.js +0 -124
- package/dist/phases/feature-analysis-verification/index.d.ts +0 -25
- package/dist/phases/feature-analysis-verification/index.js +0 -92
- package/dist/phases/feature-analysis-verification/prompts.d.ts +0 -10
- package/dist/phases/feature-analysis-verification/prompts.js +0 -100
- package/dist/phases/intelligence-analysis/__tests__/context.test.d.ts +0 -4
- package/dist/phases/intelligence-analysis/__tests__/context.test.js +0 -192
- package/dist/phases/intelligence-analysis/__tests__/matching.test.d.ts +0 -13
- package/dist/phases/intelligence-analysis/__tests__/matching.test.js +0 -154
- package/dist/phases/intelligence-analysis/__tests__/orchestration.test.d.ts +0 -5
- package/dist/phases/intelligence-analysis/__tests__/orchestration.test.js +0 -378
- package/dist/phases/intelligence-analysis/__tests__/prompts.test.d.ts +0 -4
- package/dist/phases/intelligence-analysis/__tests__/prompts.test.js +0 -33
- package/dist/phases/pr-execution/__tests__/file-assigner.test.d.ts +0 -1
- package/dist/phases/pr-execution/__tests__/file-assigner.test.js +0 -303
- package/dist/phases/pr-resolve/__tests__/checklist-learner.test.d.ts +0 -1
- package/dist/phases/pr-resolve/__tests__/checklist-learner.test.js +0 -157
- package/dist/phases/pr-resolve/__tests__/prompts.test.d.ts +0 -1
- package/dist/phases/pr-resolve/__tests__/prompts.test.js +0 -116
- package/dist/phases/pr-resolve/__tests__/resolve-mapping.test.d.ts +0 -1
- package/dist/phases/pr-resolve/__tests__/resolve-mapping.test.js +0 -138
- package/dist/phases/pr-resolve/__tests__/types.test.d.ts +0 -1
- package/dist/phases/pr-resolve/__tests__/types.test.js +0 -43
- package/dist/phases/pr-resolve/__tests__/workspace.test.d.ts +0 -1
- package/dist/phases/pr-resolve/__tests__/workspace.test.js +0 -111
- package/dist/phases/pr-review/__tests__/prompts.test.d.ts +0 -1
- package/dist/phases/pr-review/__tests__/prompts.test.js +0 -49
- package/dist/phases/pr-review/__tests__/review-comments.test.d.ts +0 -1
- package/dist/phases/pr-review/__tests__/review-comments.test.js +0 -110
- package/dist/phases/pr-shared/__tests__/agent-utils.test.d.ts +0 -1
- package/dist/phases/pr-shared/__tests__/agent-utils.test.js +0 -91
- package/dist/phases/pr-shared/__tests__/context.test.d.ts +0 -1
- package/dist/phases/pr-shared/__tests__/context.test.js +0 -94
- package/dist/phases/pr-splitting/__tests__/import-dep-validator.test.d.ts +0 -1
- package/dist/phases/pr-splitting/__tests__/import-dep-validator.test.js +0 -331
- package/dist/phases/run-sheet/render.d.ts +0 -60
- package/dist/phases/run-sheet/render.js +0 -297
- package/dist/phases/smoke-test/__tests__/agent.test.d.ts +0 -4
- package/dist/phases/smoke-test/__tests__/agent.test.js +0 -84
- package/dist/phases/smoke-test/__tests__/github.test.d.ts +0 -9
- package/dist/phases/smoke-test/__tests__/github.test.js +0 -120
- package/dist/phases/smoke-test/__tests__/snapshot.test.d.ts +0 -8
- package/dist/phases/smoke-test/__tests__/snapshot.test.js +0 -93
- package/dist/phases/smoke-test/github.d.ts +0 -54
- package/dist/phases/smoke-test/github.js +0 -101
- package/dist/phases/smoke-test/snapshot.d.ts +0 -27
- package/dist/phases/smoke-test/snapshot.js +0 -157
- package/dist/services/coaching/__tests__/coaching-agent.test.d.ts +0 -1
- package/dist/services/coaching/__tests__/coaching-agent.test.js +0 -74
- package/dist/services/coaching/__tests__/coaching-loop.test.d.ts +0 -1
- package/dist/services/coaching/__tests__/coaching-loop.test.js +0 -59
- package/dist/services/coaching/__tests__/self-rating.test.d.ts +0 -1
- package/dist/services/coaching/__tests__/self-rating.test.js +0 -188
- package/dist/services/lifecycle-agent/__tests__/phase-criteria.test.d.ts +0 -4
- package/dist/services/lifecycle-agent/__tests__/phase-criteria.test.js +0 -133
- package/dist/services/lifecycle-agent/__tests__/transition-rules.test.d.ts +0 -4
- package/dist/services/lifecycle-agent/__tests__/transition-rules.test.js +0 -336
- package/dist/services/lifecycle-agent/index.d.ts +0 -24
- package/dist/services/lifecycle-agent/index.js +0 -25
- package/dist/services/lifecycle-agent/phase-criteria.d.ts +0 -57
- package/dist/services/lifecycle-agent/phase-criteria.js +0 -335
- package/dist/services/lifecycle-agent/transition-rules.d.ts +0 -60
- package/dist/services/lifecycle-agent/transition-rules.js +0 -184
- package/dist/services/lifecycle-agent/types.d.ts +0 -190
- package/dist/services/lifecycle-agent/types.js +0 -12
- package/dist/services/phase-hooks/__tests__/bindings-fetcher.test.d.ts +0 -1
- package/dist/services/phase-hooks/__tests__/bindings-fetcher.test.js +0 -122
- package/dist/services/phase-hooks/__tests__/hook-executor.test.d.ts +0 -1
- package/dist/services/phase-hooks/__tests__/hook-executor.test.js +0 -321
- package/dist/services/phase-hooks/__tests__/hook-runner.test.d.ts +0 -1
- package/dist/services/phase-hooks/__tests__/hook-runner.test.js +0 -261
- package/dist/services/phase-hooks/__tests__/plugin-loader.test.d.ts +0 -1
- package/dist/services/phase-hooks/__tests__/plugin-loader.test.js +0 -158
- package/dist/services/video/__tests__/video-pipeline.test.d.ts +0 -6
- package/dist/services/video/__tests__/video-pipeline.test.js +0 -249
- package/dist/types/features.d.ts +0 -35
- package/dist/types/features.js +0 -1
- package/dist/workspace/__tests__/workspace-manager.test.d.ts +0 -7
- package/dist/workspace/__tests__/workspace-manager.test.js +0 -52
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find-smells phase: clone the product's repo, ask Claude to audit code for
|
|
3
|
+
* code smells (refactor candidates, perf cliffs, dead code, etc.), and file
|
|
4
|
+
* each new finding as an issue. Subsequent runs are incremental, scoped to
|
|
5
|
+
* commits since the previous successful scan.
|
|
6
|
+
*
|
|
7
|
+
* Companion to find-bugs (real defects) and find-features (missing user
|
|
8
|
+
* capability). The three phases share the same workspace + state pattern.
|
|
9
|
+
*/
|
|
10
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
11
|
+
import { DEFAULT_MODEL } from '../../constants.js';
|
|
12
|
+
import { logError, logInfo, logSuccess, logWarning, } from '../../utils/logger.js';
|
|
13
|
+
import { cloneIssueRepo, ensureWorkspaceDir, syncRepoToRef, } from '../../workspace/workspace-manager.js';
|
|
14
|
+
import { detectDefaultBranch, gitRevParse, isAncestor, listChangedPaths, } from '../find-shared/git.js';
|
|
15
|
+
import { createIssue, fetchOpenIssues, fetchProductBasics, } from '../find-shared/mcp.js';
|
|
16
|
+
import { createPromptGenerator, extractTextFromContent, tryExtractResult, } from '../pr-shared/agent-utils.js';
|
|
17
|
+
import { createFindSmellsSystemPrompt, createFindSmellsUserPrompt, } from './prompts.js';
|
|
18
|
+
import { acquireFindSmellsLock, loadFindSmellsState, updateFindSmellsState, } from './state.js';
|
|
19
|
+
import { isScanResult, isSmellCategory, } from './types.js';
|
|
20
|
+
const WORKSPACE_KEY = 'find-smells';
|
|
21
|
+
/** Single source of truth — referenced by the CLI help string too. */
|
|
22
|
+
export const DEFAULT_MAX_FILES = 200;
|
|
23
|
+
/**
|
|
24
|
+
* Upper bound on turns for the in-CLI Claude session. Same rationale as
|
|
25
|
+
* find-bugs: read-only but open-scope audit needs headroom for repo-wide
|
|
26
|
+
* Glob/Read/Grep without runaway exploration.
|
|
27
|
+
*/
|
|
28
|
+
const MAX_TURNS = 200;
|
|
29
|
+
/**
|
|
30
|
+
* Scan a product's repository for code smells and file each new finding as an issue.
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line complexity
|
|
33
|
+
export async function scanForSmells(options) {
|
|
34
|
+
const { productId, githubToken, owner, repo, full, maxFiles, categories, verbose, } = options;
|
|
35
|
+
logInfo(`Starting smell scan for product ${productId} (${owner}/${repo})`);
|
|
36
|
+
const lock = acquireFindSmellsLock(productId);
|
|
37
|
+
if (!lock) {
|
|
38
|
+
logWarning(`Another smell scan is already in progress for product ${productId}; skipping.`);
|
|
39
|
+
return {
|
|
40
|
+
status: 'error',
|
|
41
|
+
message: 'Another smell scan is already in progress for this product',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
updateFindSmellsState(productId, {
|
|
46
|
+
lastAttemptedAt: new Date().toISOString(),
|
|
47
|
+
});
|
|
48
|
+
const workspaceRoot = ensureWorkspaceDir();
|
|
49
|
+
const repoKey = `${WORKSPACE_KEY}-${productId}`;
|
|
50
|
+
const cloned = cloneIssueRepo(workspaceRoot, repoKey, owner, repo, githubToken);
|
|
51
|
+
const { repoPath } = cloned;
|
|
52
|
+
const branch = options.branch ?? detectDefaultBranch(repoPath);
|
|
53
|
+
logInfo(`Syncing ${owner}/${repo} to branch ${branch}`);
|
|
54
|
+
syncRepoToRef(repoPath, { branch }, githubToken);
|
|
55
|
+
const headSha = gitRevParse(repoPath, 'HEAD');
|
|
56
|
+
const state = loadFindSmellsState(productId);
|
|
57
|
+
const baseSha = full ? undefined : state.lastScannedCommitSha;
|
|
58
|
+
let scope = 'full';
|
|
59
|
+
let changedPaths;
|
|
60
|
+
if (baseSha && baseSha !== headSha) {
|
|
61
|
+
const sameTree = isAncestor(repoPath, baseSha, headSha);
|
|
62
|
+
if (sameTree) {
|
|
63
|
+
scope = 'incremental';
|
|
64
|
+
changedPaths = listChangedPaths(repoPath, baseSha, headSha);
|
|
65
|
+
logInfo(`Incremental scan: ${changedPaths.length} files changed since ${baseSha.slice(0, 8)}`);
|
|
66
|
+
if (changedPaths.length === 0) {
|
|
67
|
+
logSuccess('No code changes since last scan; nothing to do.');
|
|
68
|
+
updateFindSmellsState(productId, {
|
|
69
|
+
lastScannedCommitSha: headSha,
|
|
70
|
+
lastScannedAt: new Date().toISOString(),
|
|
71
|
+
lastError: undefined,
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
status: 'success',
|
|
75
|
+
message: 'No changes since last scan',
|
|
76
|
+
scannedCommitSha: headSha,
|
|
77
|
+
smellsFound: 0,
|
|
78
|
+
issuesCreated: 0,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
logWarning(`Last scanned sha ${baseSha.slice(0, 8)} not reachable from HEAD; falling back to full scan.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (baseSha === headSha) {
|
|
87
|
+
// Symmetric with the "no changed files" early return above: even though
|
|
88
|
+
// the sha didn't move, advance lastScannedAt + clear lastError so the
|
|
89
|
+
// state file accurately reflects when we last verified the repo.
|
|
90
|
+
logSuccess('HEAD unchanged since last scan; nothing to do.');
|
|
91
|
+
updateFindSmellsState(productId, {
|
|
92
|
+
lastScannedAt: new Date().toISOString(),
|
|
93
|
+
lastError: undefined,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
status: 'success',
|
|
97
|
+
message: 'HEAD unchanged since last scan',
|
|
98
|
+
scannedCommitSha: headSha,
|
|
99
|
+
smellsFound: 0,
|
|
100
|
+
issuesCreated: 0,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const product = await fetchProductBasics(productId);
|
|
104
|
+
const existingIssues = await fetchOpenIssues(productId);
|
|
105
|
+
logInfo(`Loaded ${existingIssues.length} existing issues for dedup context`);
|
|
106
|
+
const systemPrompt = createFindSmellsSystemPrompt();
|
|
107
|
+
const userPrompt = createFindSmellsUserPrompt({
|
|
108
|
+
productName: product.name,
|
|
109
|
+
productDescription: product.description,
|
|
110
|
+
scope,
|
|
111
|
+
baseSha,
|
|
112
|
+
headSha,
|
|
113
|
+
changedPaths,
|
|
114
|
+
maxFiles: maxFiles ?? DEFAULT_MAX_FILES,
|
|
115
|
+
categories,
|
|
116
|
+
existingIssues: existingIssues.map((i) => ({
|
|
117
|
+
id: i.id,
|
|
118
|
+
name: i.name,
|
|
119
|
+
description: i.description,
|
|
120
|
+
})),
|
|
121
|
+
});
|
|
122
|
+
let lastAssistantResponse = '';
|
|
123
|
+
let scanResult = null;
|
|
124
|
+
logInfo('Running Claude code-smell audit...');
|
|
125
|
+
for await (const message of query({
|
|
126
|
+
prompt: createPromptGenerator(userPrompt),
|
|
127
|
+
options: {
|
|
128
|
+
systemPrompt: {
|
|
129
|
+
type: 'preset',
|
|
130
|
+
preset: 'claude_code',
|
|
131
|
+
append: systemPrompt,
|
|
132
|
+
},
|
|
133
|
+
model: DEFAULT_MODEL,
|
|
134
|
+
maxTurns: MAX_TURNS,
|
|
135
|
+
permissionMode: 'bypassPermissions',
|
|
136
|
+
cwd: repoPath,
|
|
137
|
+
},
|
|
138
|
+
})) {
|
|
139
|
+
if (message.type === 'assistant') {
|
|
140
|
+
lastAssistantResponse += extractTextFromContent(message.message?.content ?? [], verbose);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (message.type !== 'result') {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const responseText = message.subtype === 'success'
|
|
147
|
+
? message.result || lastAssistantResponse
|
|
148
|
+
: lastAssistantResponse;
|
|
149
|
+
const parsed = tryExtractResult(responseText, 'scan_result');
|
|
150
|
+
if (isScanResult(parsed)) {
|
|
151
|
+
scanResult = parsed;
|
|
152
|
+
}
|
|
153
|
+
else if (message.subtype !== 'success') {
|
|
154
|
+
logError(`Audit incomplete: ${message.subtype}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!scanResult) {
|
|
158
|
+
const msg = 'Audit failed: could not parse a scan_result from the agent';
|
|
159
|
+
updateFindSmellsState(productId, { lastError: msg });
|
|
160
|
+
return {
|
|
161
|
+
status: 'error',
|
|
162
|
+
message: msg,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const { summary, smells } = scanResult;
|
|
166
|
+
logInfo(`Audit produced ${smells.length} candidate smells. ${summary}`);
|
|
167
|
+
const deferredBugs = scanResult.deferred_to_bugs ?? [];
|
|
168
|
+
const deferredFeatures = scanResult.deferred_to_features ?? [];
|
|
169
|
+
if (deferredBugs.length > 0) {
|
|
170
|
+
logInfo(`${deferredBugs.length} finding(s) deferred to find-bugs — run \`edsger find-bugs ${productId}\` to pick them up:`);
|
|
171
|
+
for (const d of deferredBugs) {
|
|
172
|
+
const loc = d.file ? ` (${d.file}${d.line ? `:${d.line}` : ''})` : '';
|
|
173
|
+
logInfo(` • ${d.title}${loc} — ${d.reason}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (deferredFeatures.length > 0) {
|
|
177
|
+
logInfo(`${deferredFeatures.length} finding(s) deferred to find-features — run \`edsger find-features ${productId}\` to pick them up:`);
|
|
178
|
+
for (const d of deferredFeatures) {
|
|
179
|
+
const loc = d.file ? ` (${d.file}${d.line ? `:${d.line}` : ''})` : '';
|
|
180
|
+
logInfo(` • ${d.title}${loc} — ${d.reason}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const { kept: filteredSmells, droppedCategories } = filterByCategories(smells, categories);
|
|
184
|
+
if (droppedCategories.length > 0) {
|
|
185
|
+
const summaryLine = droppedCategories
|
|
186
|
+
.map(({ category, count }) => `${category}×${count}`)
|
|
187
|
+
.join(', ');
|
|
188
|
+
logWarning(`Dropped findings outside the requested categories or with unknown category: ${summaryLine}.`);
|
|
189
|
+
}
|
|
190
|
+
let created = 0;
|
|
191
|
+
for (const smell of filteredSmells) {
|
|
192
|
+
const issueId = await createIssueForSmell(productId, smell);
|
|
193
|
+
if (issueId) {
|
|
194
|
+
created++;
|
|
195
|
+
logSuccess(`Filed issue ${issueId}: ${smell.title}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
updateFindSmellsState(productId, {
|
|
199
|
+
lastScannedCommitSha: headSha,
|
|
200
|
+
lastScannedAt: new Date().toISOString(),
|
|
201
|
+
lastError: undefined,
|
|
202
|
+
});
|
|
203
|
+
const droppedCount = droppedCategories.reduce((acc, d) => acc + d.count, 0);
|
|
204
|
+
return {
|
|
205
|
+
status: 'success',
|
|
206
|
+
message: `Filed ${created} of ${filteredSmells.length} candidate smells (${droppedCount} dropped by category filter; ${deferredBugs.length} deferred to bugs, ${deferredFeatures.length} to features)`,
|
|
207
|
+
scannedCommitSha: headSha,
|
|
208
|
+
smellsFound: filteredSmells.length,
|
|
209
|
+
issuesCreated: created,
|
|
210
|
+
deferredToBugs: deferredBugs.length,
|
|
211
|
+
deferredToFeatures: deferredFeatures.length,
|
|
212
|
+
summary,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
217
|
+
logError(`Smell scan failed: ${errorMessage}`);
|
|
218
|
+
updateFindSmellsState(productId, { lastError: errorMessage });
|
|
219
|
+
return {
|
|
220
|
+
status: 'error',
|
|
221
|
+
message: `Smell scan failed: ${errorMessage}`,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
lock.release();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async function createIssueForSmell(productId, smell) {
|
|
229
|
+
return createIssue({
|
|
230
|
+
productId,
|
|
231
|
+
title: smell.title,
|
|
232
|
+
description: formatIssueDescription(smell),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Filter the agent's findings down to the requested categories. The system
|
|
237
|
+
* prompt asks the agent to honour the filter, but trusting the prompt alone
|
|
238
|
+
* lets bad output through; we re-check here. Items with an unknown category
|
|
239
|
+
* are also dropped — the type system can't enforce that across the JSON
|
|
240
|
+
* boundary.
|
|
241
|
+
*
|
|
242
|
+
* Returns per-category drop counts so the user-facing warning can name the
|
|
243
|
+
* specific categories that were filtered out (more actionable than a bare
|
|
244
|
+
* total).
|
|
245
|
+
*/
|
|
246
|
+
function filterByCategories(smells, categories) {
|
|
247
|
+
const allow = categories?.length ? new Set(categories) : null;
|
|
248
|
+
const kept = [];
|
|
249
|
+
const droppedTally = new Map();
|
|
250
|
+
for (const s of smells) {
|
|
251
|
+
const known = isSmellCategory(s.category);
|
|
252
|
+
const inAllow = !allow || (known && allow.has(s.category));
|
|
253
|
+
if (known && inAllow) {
|
|
254
|
+
kept.push(s);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const key = known ? s.category : '<unknown>';
|
|
258
|
+
droppedTally.set(key, (droppedTally.get(key) ?? 0) + 1);
|
|
259
|
+
}
|
|
260
|
+
const droppedCategories = Array.from(droppedTally.entries())
|
|
261
|
+
.map(([category, count]) => ({ category, count }))
|
|
262
|
+
.sort((a, b) => b.count - a.count);
|
|
263
|
+
return { kept, droppedCategories };
|
|
264
|
+
}
|
|
265
|
+
function formatIssueDescription(smell) {
|
|
266
|
+
const location = smell.line ? `${smell.file}:${smell.line}` : smell.file;
|
|
267
|
+
const lines = [
|
|
268
|
+
`**Severity**: ${smell.severity}`,
|
|
269
|
+
`**Category**: ${smell.category}`,
|
|
270
|
+
`**Location**: \`${location}\``,
|
|
271
|
+
'',
|
|
272
|
+
smell.description,
|
|
273
|
+
'',
|
|
274
|
+
'---',
|
|
275
|
+
'_Filed automatically by `edsger find-smells`._',
|
|
276
|
+
];
|
|
277
|
+
return lines.join('\n');
|
|
278
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts for the find-smells phase. The agent runs with cwd=repo checkout
|
|
3
|
+
* and has Read/Grep/Glob/Bash available — it explores the code itself
|
|
4
|
+
* rather than receiving a pre-baked diff.
|
|
5
|
+
*
|
|
6
|
+
* Boundary against neighbouring phases:
|
|
7
|
+
* - find-bugs handles real defects (security, correctness, races, etc.)
|
|
8
|
+
* - find-features handles missing user-facing capability
|
|
9
|
+
* - find-smells (this phase) handles "the code would be better if changed":
|
|
10
|
+
* refactor candidates, dead code, perf cliffs, type-safety gaps, etc.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFindSmellsSystemPrompt(): string;
|
|
13
|
+
export interface FindSmellsUserPromptParams {
|
|
14
|
+
productName: string;
|
|
15
|
+
productDescription?: string;
|
|
16
|
+
scope: 'full' | 'incremental';
|
|
17
|
+
baseSha?: string;
|
|
18
|
+
headSha: string;
|
|
19
|
+
changedPaths?: string[];
|
|
20
|
+
existingIssues: {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
}[];
|
|
25
|
+
/** Upper bound on files the auditor may Read. Keeps token cost predictable. */
|
|
26
|
+
maxFiles?: number;
|
|
27
|
+
/** Optional comma-separated category filter from the CLI. */
|
|
28
|
+
categories?: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare function createFindSmellsUserPrompt(params: FindSmellsUserPromptParams): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts for the find-smells phase. The agent runs with cwd=repo checkout
|
|
3
|
+
* and has Read/Grep/Glob/Bash available — it explores the code itself
|
|
4
|
+
* rather than receiving a pre-baked diff.
|
|
5
|
+
*
|
|
6
|
+
* Boundary against neighbouring phases:
|
|
7
|
+
* - find-bugs handles real defects (security, correctness, races, etc.)
|
|
8
|
+
* - find-features handles missing user-facing capability
|
|
9
|
+
* - find-smells (this phase) handles "the code would be better if changed":
|
|
10
|
+
* refactor candidates, dead code, perf cliffs, type-safety gaps, etc.
|
|
11
|
+
*/
|
|
12
|
+
export function createFindSmellsSystemPrompt() {
|
|
13
|
+
return `You are a senior engineer auditing a codebase for **code smells** — concrete improvements the codebase would benefit from. You have read-only access via Read/Grep/Glob and may run shallow Bash queries (e.g. \`git log\`, \`wc -l\`) to navigate.
|
|
14
|
+
|
|
15
|
+
**What counts as a smell worth filing**:
|
|
16
|
+
1. **Refactor**: duplicated logic across files, tangled module boundaries, leaky abstractions, primitive obsession
|
|
17
|
+
2. **Performance**: clearly-suboptimal patterns (N+1 queries, unbounded loops on growing data, repeated work that could be cached, sync I/O in hot paths) that are not yet causing user-visible bugs
|
|
18
|
+
3. **Duplication**: copy-pasted blocks that should be a single helper
|
|
19
|
+
4. **Complexity**: functions / files that are too long or too deeply nested to reason about, cyclomatic-complexity hotspots
|
|
20
|
+
5. **Dead code**: unreferenced exports, unreachable branches, abandoned feature flags, commented-out blocks
|
|
21
|
+
6. **Type safety**: \`any\` / \`unknown\` casts, \`@ts-ignore\` / \`@ts-expect-error\`, missing null checks at trust boundaries, loose interfaces that should be tightened
|
|
22
|
+
7. **Readability**: misleading names, missing or wrong comments, magic numbers that should be named constants
|
|
23
|
+
8. **Architecture**: cyclic deps, layering violations, modules that have grown into multiple responsibilities
|
|
24
|
+
|
|
25
|
+
**What does NOT count** (skip these — wrong tool):
|
|
26
|
+
- Real bugs (security holes, logic errors, races, data corruption) — those belong in \`edsger find-bugs\`. **Don't drop them silently — list them in \`deferred_to_bugs\` so the user knows to run that command.**
|
|
27
|
+
- Missing user-facing features or workflows — those belong in \`edsger find-features\`. **List them in \`deferred_to_features\` instead of dropping them.**
|
|
28
|
+
- Pure style / formatting / lint issues a formatter would catch
|
|
29
|
+
- "Could be more idiomatic" rewrites with no concrete benefit
|
|
30
|
+
- Hypothetical future-scaling concerns with no current evidence
|
|
31
|
+
- Missing tests (track those separately, not here)
|
|
32
|
+
|
|
33
|
+
**Discipline**:
|
|
34
|
+
- Be concrete: cite the exact file and line. Quote the offending snippet in the description, and propose the specific change.
|
|
35
|
+
- Be conservative: if you can't articulate the *benefit* of changing it (clarity, perf number, removed coupling), skip it.
|
|
36
|
+
- Severity rubric:
|
|
37
|
+
- high = pays back quickly (e.g. removes a hot-path N+1, deletes a large dead module, unblocks future work the team is clearly trying to do)
|
|
38
|
+
- medium = clear improvement but not urgent (typical refactor candidate)
|
|
39
|
+
- low = nice-to-have polish; only file if the change is small and obvious
|
|
40
|
+
- **Deduplication**: you will be given the list of existing open issues. Skip any finding that overlaps. Better to under-report than spam duplicates.
|
|
41
|
+
|
|
42
|
+
**CRITICAL — Output Format**:
|
|
43
|
+
End your response with a single JSON code block in this exact shape:
|
|
44
|
+
|
|
45
|
+
\`\`\`json
|
|
46
|
+
{
|
|
47
|
+
"scan_result": {
|
|
48
|
+
"summary": "Reviewed N files in <scope>; found X smells (Y high, Z medium).",
|
|
49
|
+
"scanned_commit_sha": "<the HEAD sha you scanned>",
|
|
50
|
+
"smells": [
|
|
51
|
+
{
|
|
52
|
+
"title": "Short, action-oriented title (under 80 chars)",
|
|
53
|
+
"description": "## What\\nWhat the smell is, with the offending snippet quoted.\\n\\n## Why it matters\\nConcrete benefit of changing it (clarity, perf, decoupling).\\n\\n## Suggested change\\nA specific refactor or replacement.",
|
|
54
|
+
"file": "relative/path/from/repo/root.ts",
|
|
55
|
+
"line": 42,
|
|
56
|
+
"severity": "medium",
|
|
57
|
+
"category": "refactor",
|
|
58
|
+
"dedup_signature": "auth-service-duplicated-token-parser"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"deferred_to_bugs": [
|
|
62
|
+
{
|
|
63
|
+
"title": "Short title of the suspected bug",
|
|
64
|
+
"reason": "One-line note of why this looks like a real defect, not a smell",
|
|
65
|
+
"file": "relative/path.ts",
|
|
66
|
+
"line": 100
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"deferred_to_features": [
|
|
70
|
+
{
|
|
71
|
+
"title": "Short title of the missing capability",
|
|
72
|
+
"reason": "One-line note of the user need this would address",
|
|
73
|
+
"file": "relative/path.ts"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
\`\`\`
|
|
79
|
+
|
|
80
|
+
If you find nothing worth filing, still emit the JSON with an empty \`smells\` array. The \`deferred_to_*\` arrays are optional — omit them or send \`[]\` if there's nothing to hand off.`;
|
|
81
|
+
}
|
|
82
|
+
export function createFindSmellsUserPrompt(params) {
|
|
83
|
+
const { productName, productDescription, scope, baseSha, headSha, changedPaths, existingIssues, maxFiles, categories, } = params;
|
|
84
|
+
const productBlock = productDescription
|
|
85
|
+
? `**Product**: ${productName}\n${productDescription}`
|
|
86
|
+
: `**Product**: ${productName}`;
|
|
87
|
+
const scopeBlock = scope === 'incremental' && baseSha
|
|
88
|
+
? `**Scope**: incremental scan of changes between ${baseSha} and ${headSha}.\nUse \`git diff --name-only ${baseSha}..${headSha}\` to enumerate changed files, then Read/Grep them. Do NOT scan files outside the diff.`
|
|
89
|
+
: `**Scope**: full repository scan at ${headSha}. Use Glob to enumerate source files. Skip vendored code, build output, generated files, lockfiles, and \`node_modules\`.`;
|
|
90
|
+
const filesHint = changedPaths && changedPaths.length > 0
|
|
91
|
+
? `\n**Changed files in this range** (${changedPaths.length}):\n${changedPaths
|
|
92
|
+
.slice(0, 200)
|
|
93
|
+
.map((p) => `- ${p}`)
|
|
94
|
+
.join('\n')}${changedPaths.length > 200 ? `\n…and ${changedPaths.length - 200} more.` : ''}`
|
|
95
|
+
: '';
|
|
96
|
+
const issuesBlock = existingIssues.length === 0
|
|
97
|
+
? 'No existing open issues for this product — every finding is new.'
|
|
98
|
+
: `**Existing open issues** (${existingIssues.length}) — skip findings that overlap with any of these:\n${existingIssues
|
|
99
|
+
.map((i) => `- [${i.id}] ${i.name}${i.description ? `\n ${truncate(i.description, 200)}` : ''}`)
|
|
100
|
+
.join('\n')}`;
|
|
101
|
+
const budgetBlock = typeof maxFiles === 'number' && maxFiles > 0
|
|
102
|
+
? `\n**Budget**: Read at most ${maxFiles} files. Prioritise files most likely to harbour smells (large modules, frequently-edited code per \`git log\`, files with \`any\`/\`@ts-ignore\`, hot data-access paths) over test fixtures and generated code. If the scope is larger than the budget, stop when you hit it and report truncation in \`summary\`.`
|
|
103
|
+
: '';
|
|
104
|
+
const categoryBlock = categories && categories.length > 0
|
|
105
|
+
? `\n**Category filter**: only file findings whose \`category\` is one of: ${categories.join(', ')}. Drop everything else.`
|
|
106
|
+
: '';
|
|
107
|
+
return `${productBlock}
|
|
108
|
+
|
|
109
|
+
${scopeBlock}${filesHint}${budgetBlock}${categoryBlock}
|
|
110
|
+
|
|
111
|
+
${issuesBlock}
|
|
112
|
+
|
|
113
|
+
## How to work
|
|
114
|
+
|
|
115
|
+
1. Identify the files in scope (per the scope block above).
|
|
116
|
+
2. For each file, Read it and look for the smell categories listed in the system prompt.
|
|
117
|
+
3. When you suspect a smell, re-read the surrounding context to confirm the *benefit* of changing it. If you can't name the benefit, drop it.
|
|
118
|
+
4. If something looks like a real bug (not a smell), drop it — \`edsger find-bugs\` covers that.
|
|
119
|
+
5. Cross-check every candidate against the existing issues list. Drop overlaps.
|
|
120
|
+
6. Produce the final JSON described in the system prompt.
|
|
121
|
+
|
|
122
|
+
Begin.`;
|
|
123
|
+
}
|
|
124
|
+
function truncate(s, n) {
|
|
125
|
+
if (s.length <= n) {
|
|
126
|
+
return s;
|
|
127
|
+
}
|
|
128
|
+
return `${s.slice(0, n)}…`;
|
|
129
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-product scan state for find-smells. Storage at
|
|
3
|
+
* `~/.edsger/find-smells-state/<productId>.json`.
|
|
4
|
+
*
|
|
5
|
+
* Same schema shape as find-bugs (incremental sha tracking) — file/lock
|
|
6
|
+
* machinery shared via createScanStateModule. Kept as a sibling state file
|
|
7
|
+
* (not merged with find-bugs) so a smell scan and a bug scan can run
|
|
8
|
+
* concurrently without contending on the same lock.
|
|
9
|
+
*/
|
|
10
|
+
import { type LockHandle } from '../find-shared/scan-state.js';
|
|
11
|
+
export type { LockHandle };
|
|
12
|
+
export interface FindSmellsState {
|
|
13
|
+
lastScannedCommitSha?: string;
|
|
14
|
+
lastScannedAt?: string;
|
|
15
|
+
lastAttemptedAt?: string;
|
|
16
|
+
lastError?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const loadFindSmellsState: (productId: string) => FindSmellsState;
|
|
19
|
+
export declare const saveFindSmellsState: (productId: string, state: FindSmellsState) => void;
|
|
20
|
+
export declare const updateFindSmellsState: (productId: string, patch: Partial<FindSmellsState>) => FindSmellsState;
|
|
21
|
+
export declare const acquireFindSmellsLock: (productId: string, staleAfterMs?: number) => LockHandle | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-product scan state for find-smells. Storage at
|
|
3
|
+
* `~/.edsger/find-smells-state/<productId>.json`.
|
|
4
|
+
*
|
|
5
|
+
* Same schema shape as find-bugs (incremental sha tracking) — file/lock
|
|
6
|
+
* machinery shared via createScanStateModule. Kept as a sibling state file
|
|
7
|
+
* (not merged with find-bugs) so a smell scan and a bug scan can run
|
|
8
|
+
* concurrently without contending on the same lock.
|
|
9
|
+
*/
|
|
10
|
+
import { createScanStateModule, } from '../find-shared/scan-state.js';
|
|
11
|
+
const m = createScanStateModule({
|
|
12
|
+
dirName: 'find-smells-state',
|
|
13
|
+
});
|
|
14
|
+
export const loadFindSmellsState = m.load;
|
|
15
|
+
export const saveFindSmellsState = m.save;
|
|
16
|
+
export const updateFindSmellsState = m.update;
|
|
17
|
+
export const acquireFindSmellsLock = m.acquireLock;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the find-smells phase.
|
|
3
|
+
*
|
|
4
|
+
* A "smell" here is anything the codebase would benefit from changing but that
|
|
5
|
+
* is **not** a real bug (find-bugs handles those) and **not** a missing feature
|
|
6
|
+
* (find-features handles those). Refactor candidates, dead code, performance
|
|
7
|
+
* cliffs, type-safety gaps, and over-complex modules all live here.
|
|
8
|
+
*/
|
|
9
|
+
export type SmellSeverity = 'high' | 'medium' | 'low';
|
|
10
|
+
/**
|
|
11
|
+
* Authoritative list of allowed categories. Kept as a `const` array so the
|
|
12
|
+
* type and the runtime whitelist can never drift apart — `SmellCategory` is
|
|
13
|
+
* derived from it, and `isSmellCategory` checks against it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const SMELL_CATEGORIES: readonly ["refactor", "performance", "duplication", "complexity", "dead_code", "type_safety", "readability", "architecture", "other"];
|
|
16
|
+
export type SmellCategory = (typeof SMELL_CATEGORIES)[number];
|
|
17
|
+
export declare function isSmellCategory(value: unknown): value is SmellCategory;
|
|
18
|
+
export interface SmellFinding {
|
|
19
|
+
title: string;
|
|
20
|
+
description: string;
|
|
21
|
+
file: string;
|
|
22
|
+
line?: number;
|
|
23
|
+
severity: SmellSeverity;
|
|
24
|
+
category: SmellCategory;
|
|
25
|
+
/** Stable signature for log/audit; not used for storage dedup. */
|
|
26
|
+
dedup_signature?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A finding the agent saw but is handing off to a sibling phase rather than
|
|
30
|
+
* filing as a smell. Surfaced in the run log so the user knows the work
|
|
31
|
+
* wasn't silently lost — they can run `edsger find-bugs` / `find-features`
|
|
32
|
+
* to pick it up.
|
|
33
|
+
*/
|
|
34
|
+
export interface DeferredFinding {
|
|
35
|
+
title: string;
|
|
36
|
+
/** One-line reason the agent thinks the sibling phase owns this. */
|
|
37
|
+
reason: string;
|
|
38
|
+
file?: string;
|
|
39
|
+
line?: number;
|
|
40
|
+
}
|
|
41
|
+
export declare function isDeferredFinding(value: unknown): value is DeferredFinding;
|
|
42
|
+
export interface ScanResult {
|
|
43
|
+
summary: string;
|
|
44
|
+
scanned_commit_sha?: string;
|
|
45
|
+
smells: SmellFinding[];
|
|
46
|
+
/** Findings the agent thinks belong in `edsger find-bugs`. */
|
|
47
|
+
deferred_to_bugs?: DeferredFinding[];
|
|
48
|
+
/** Findings the agent thinks belong in `edsger find-features`. */
|
|
49
|
+
deferred_to_features?: DeferredFinding[];
|
|
50
|
+
}
|
|
51
|
+
export declare function isScanResult(value: unknown): value is ScanResult;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the find-smells phase.
|
|
3
|
+
*
|
|
4
|
+
* A "smell" here is anything the codebase would benefit from changing but that
|
|
5
|
+
* is **not** a real bug (find-bugs handles those) and **not** a missing feature
|
|
6
|
+
* (find-features handles those). Refactor candidates, dead code, performance
|
|
7
|
+
* cliffs, type-safety gaps, and over-complex modules all live here.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Authoritative list of allowed categories. Kept as a `const` array so the
|
|
11
|
+
* type and the runtime whitelist can never drift apart — `SmellCategory` is
|
|
12
|
+
* derived from it, and `isSmellCategory` checks against it.
|
|
13
|
+
*/
|
|
14
|
+
export const SMELL_CATEGORIES = [
|
|
15
|
+
'refactor',
|
|
16
|
+
'performance',
|
|
17
|
+
'duplication',
|
|
18
|
+
'complexity',
|
|
19
|
+
'dead_code',
|
|
20
|
+
'type_safety',
|
|
21
|
+
'readability',
|
|
22
|
+
'architecture',
|
|
23
|
+
'other',
|
|
24
|
+
];
|
|
25
|
+
export function isSmellCategory(value) {
|
|
26
|
+
return (typeof value === 'string' &&
|
|
27
|
+
SMELL_CATEGORIES.includes(value));
|
|
28
|
+
}
|
|
29
|
+
export function isDeferredFinding(value) {
|
|
30
|
+
if (!value || typeof value !== 'object') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const v = value;
|
|
34
|
+
return typeof v.title === 'string' && typeof v.reason === 'string';
|
|
35
|
+
}
|
|
36
|
+
export function isScanResult(value) {
|
|
37
|
+
if (!value || typeof value !== 'object') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const v = value;
|
|
41
|
+
if (typeof v.summary !== 'string' || !Array.isArray(v.smells)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const smellsOk = v.smells.every((s) => s &&
|
|
45
|
+
typeof s === 'object' &&
|
|
46
|
+
typeof s.title === 'string' &&
|
|
47
|
+
typeof s.description === 'string' &&
|
|
48
|
+
typeof s.file === 'string');
|
|
49
|
+
if (!smellsOk) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// Deferred arrays are optional but, if present, must be well-formed —
|
|
53
|
+
// otherwise we'd silently drop hand-offs the agent intended us to log.
|
|
54
|
+
for (const key of ['deferred_to_bugs', 'deferred_to_features']) {
|
|
55
|
+
const arr = v[key];
|
|
56
|
+
if (arr === undefined) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (!Array.isArray(arr) || !arr.every(isDeferredFinding)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|