edsger 0.54.0 → 0.55.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.
Files changed (142) hide show
  1. package/README.md +20 -0
  2. package/dist/api/financing.d.ts +47 -0
  3. package/dist/api/financing.js +37 -0
  4. package/dist/api/issues/approval-checker.d.ts +11 -9
  5. package/dist/api/issues/approval-checker.js +30 -41
  6. package/dist/api/issues/status-updater.d.ts +47 -20
  7. package/dist/api/issues/status-updater.js +114 -46
  8. package/dist/api/issues/update-issue.d.ts +5 -0
  9. package/dist/api/issues/update-issue.js +6 -0
  10. package/dist/commands/agent-workflow/processor.js +5 -1
  11. package/dist/commands/checklists/index.d.ts +5 -2
  12. package/dist/commands/checklists/index.js +73 -12
  13. package/dist/commands/checklists/tools.d.ts +14 -7
  14. package/dist/commands/checklists/tools.js +15 -208
  15. package/dist/commands/financing-deck/index.d.ts +8 -0
  16. package/dist/commands/financing-deck/index.js +66 -0
  17. package/dist/commands/find-architecture/index.d.ts +13 -0
  18. package/dist/commands/find-architecture/index.js +41 -0
  19. package/dist/commands/issue-analysis/index.d.ts +5 -0
  20. package/dist/commands/issue-analysis/index.js +9 -0
  21. package/dist/commands/sync-github-issues/index.d.ts +11 -0
  22. package/dist/commands/sync-github-issues/index.js +42 -0
  23. package/dist/commands/sync-sentry-issues/index.d.ts +14 -0
  24. package/dist/commands/sync-sentry-issues/index.js +73 -0
  25. package/dist/commands/technical-design/index.d.ts +5 -0
  26. package/dist/commands/technical-design/index.js +9 -0
  27. package/dist/commands/test-cases-analysis/index.d.ts +5 -0
  28. package/dist/commands/test-cases-analysis/index.js +9 -0
  29. package/dist/commands/user-stories-analysis/index.d.ts +5 -0
  30. package/dist/commands/user-stories-analysis/index.js +9 -0
  31. package/dist/commands/workflow/executors/phase-executor.js +6 -4
  32. package/dist/commands/workflow/phase-orchestrator.js +0 -1
  33. package/dist/config/issue-status.d.ts +18 -45
  34. package/dist/config/issue-status.js +21 -107
  35. package/dist/index.js +176 -4
  36. package/dist/phases/app-store-generation/agent.js +2 -1
  37. package/dist/phases/app-store-generation/index.js +11 -3
  38. package/dist/phases/branch-planning/index.js +0 -1
  39. package/dist/phases/bug-fixing/analyzer.js +0 -1
  40. package/dist/phases/bug-fixing/mcp-server.d.ts +18 -1
  41. package/dist/phases/bug-fixing/mcp-server.js +19 -76
  42. package/dist/phases/chat-processor/product-tools.d.ts +5 -8
  43. package/dist/phases/chat-processor/product-tools.js +6 -512
  44. package/dist/phases/chat-processor/tools.d.ts +5 -9
  45. package/dist/phases/chat-processor/tools.js +6 -704
  46. package/dist/phases/code-implementation/index.js +0 -1
  47. package/dist/phases/code-implementation-verification/agent.js +6 -1
  48. package/dist/phases/code-refine/index.js +0 -1
  49. package/dist/phases/code-refine/refine-iteration.js +2 -1
  50. package/dist/phases/code-review/index.js +0 -1
  51. package/dist/phases/code-testing/analyzer.js +0 -1
  52. package/dist/phases/financing-deck/agent.d.ts +1 -0
  53. package/dist/phases/financing-deck/agent.js +96 -0
  54. package/dist/phases/financing-deck/context.d.ts +13 -0
  55. package/dist/phases/financing-deck/context.js +69 -0
  56. package/dist/phases/financing-deck/index.d.ts +15 -0
  57. package/dist/phases/financing-deck/index.js +89 -0
  58. package/dist/phases/financing-deck/prompts.d.ts +2 -0
  59. package/dist/phases/financing-deck/prompts.js +94 -0
  60. package/dist/phases/find-architecture/index.d.ts +44 -0
  61. package/dist/phases/find-architecture/index.js +248 -0
  62. package/dist/phases/find-architecture/prompts.d.ts +31 -0
  63. package/dist/phases/find-architecture/prompts.js +128 -0
  64. package/dist/phases/find-architecture/state.d.ts +21 -0
  65. package/dist/phases/find-architecture/state.js +17 -0
  66. package/dist/phases/find-architecture/types.d.ts +55 -0
  67. package/dist/phases/find-architecture/types.js +69 -0
  68. package/dist/phases/find-bugs/index.js +13 -4
  69. package/dist/phases/find-features/index.js +10 -5
  70. package/dist/phases/find-smells/index.js +10 -3
  71. package/dist/phases/functional-testing/analyzer.js +27 -17
  72. package/dist/phases/functional-testing/http-fallback.d.ts +1 -1
  73. package/dist/phases/functional-testing/http-fallback.js +32 -16
  74. package/dist/phases/functional-testing/mcp-server.d.ts +9 -1
  75. package/dist/phases/functional-testing/mcp-server.js +13 -132
  76. package/dist/phases/growth-analysis/agent.js +2 -2
  77. package/dist/phases/growth-analysis/index.js +9 -3
  78. package/dist/phases/intelligence-analysis/agent.js +2 -2
  79. package/dist/phases/intelligence-analysis/index.js +9 -2
  80. package/dist/phases/issue-analysis/agent.d.ts +9 -1
  81. package/dist/phases/issue-analysis/agent.js +68 -27
  82. package/dist/phases/issue-analysis/context.d.ts +5 -9
  83. package/dist/phases/issue-analysis/context.js +31 -76
  84. package/dist/phases/issue-analysis/index.js +32 -84
  85. package/dist/phases/issue-analysis/outcome.d.ts +3 -33
  86. package/dist/phases/issue-analysis/outcome.js +15 -253
  87. package/dist/phases/issue-analysis/prompts.d.ts +3 -5
  88. package/dist/phases/issue-analysis/prompts.js +45 -158
  89. package/dist/phases/issue-analysis-verification/agent.d.ts +4 -4
  90. package/dist/phases/issue-analysis-verification/agent.js +5 -5
  91. package/dist/phases/issue-analysis-verification/index.d.ts +4 -2
  92. package/dist/phases/issue-analysis-verification/index.js +9 -22
  93. package/dist/phases/issue-analysis-verification/prompts.d.ts +1 -2
  94. package/dist/phases/issue-analysis-verification/prompts.js +21 -46
  95. package/dist/phases/output-contracts.js +66 -78
  96. package/dist/phases/pr-execution/index.js +2 -2
  97. package/dist/phases/pr-resolve/index.js +2 -8
  98. package/dist/phases/pr-splitting/index.js +2 -2
  99. package/dist/phases/release-sync/index.js +52 -43
  100. package/dist/phases/run-sheet/index.js +2 -1
  101. package/dist/phases/smoke-test/agent.js +2 -1
  102. package/dist/phases/smoke-test/index.js +4 -1
  103. package/dist/phases/sync-github-issues/index.d.ts +41 -0
  104. package/dist/phases/sync-github-issues/index.js +187 -0
  105. package/dist/phases/sync-github-issues/state.d.ts +26 -0
  106. package/dist/phases/sync-github-issues/state.js +18 -0
  107. package/dist/phases/sync-github-issues/types.d.ts +35 -0
  108. package/dist/phases/sync-github-issues/types.js +6 -0
  109. package/dist/phases/sync-sentry-issues/index.d.ts +29 -0
  110. package/dist/phases/sync-sentry-issues/index.js +153 -0
  111. package/dist/phases/sync-sentry-issues/sentry-client.d.ts +66 -0
  112. package/dist/phases/sync-sentry-issues/sentry-client.js +221 -0
  113. package/dist/phases/sync-sentry-issues/state.d.ts +23 -0
  114. package/dist/phases/sync-sentry-issues/state.js +18 -0
  115. package/dist/phases/sync-sentry-issues/types.d.ts +46 -0
  116. package/dist/phases/sync-sentry-issues/types.js +6 -0
  117. package/dist/phases/sync-shared/mcp.d.ts +81 -0
  118. package/dist/phases/sync-shared/mcp.js +111 -0
  119. package/dist/phases/technical-design/index.js +0 -1
  120. package/dist/phases/test-cases-analysis/agent.js +2 -1
  121. package/dist/phases/test-cases-analysis/index.js +0 -1
  122. package/dist/phases/user-stories-analysis/agent.js +2 -1
  123. package/dist/phases/user-stories-analysis/index.js +0 -1
  124. package/dist/services/coaching/coaching-agent.js +29 -4
  125. package/dist/services/feedbacks.d.ts +1 -1
  126. package/dist/skills/phase/issue-analysis/SKILL.md +48 -92
  127. package/dist/skills/phase/issue-analysis-verification/SKILL.md +46 -31
  128. package/dist/tools/bootstrap.d.ts +45 -0
  129. package/dist/tools/bootstrap.js +50 -0
  130. package/dist/types/external-sources.d.ts +22 -0
  131. package/dist/types/external-sources.js +23 -0
  132. package/dist/types/index.d.ts +5 -10
  133. package/dist/types/issues.d.ts +2 -0
  134. package/dist/types/llm-responses.d.ts +1 -14
  135. package/dist/utils/formatters.js +1 -7
  136. package/dist/utils/issue-phase-cli.d.ts +26 -0
  137. package/dist/utils/issue-phase-cli.js +44 -0
  138. package/dist/workspace/workspace-manager.d.ts +10 -0
  139. package/dist/workspace/workspace-manager.js +22 -1
  140. package/package.json +6 -2
  141. package/vitest.config.ts +4 -0
  142. package/.env.local +0 -12
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Find-architecture phase: clone the product's repo, ask Claude to audit the
3
+ * codebase for architectural problems and improvement opportunities, 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), find-features (missing user
8
+ * capability), and find-smells (local code-level improvements). All four
9
+ * phases share the same workspace + state pattern.
10
+ */
11
+ import { query } from '@anthropic-ai/claude-agent-sdk';
12
+ import { DEFAULT_MODEL } from '../../constants.js';
13
+ import { logError, logInfo, logSuccess, logWarning, } from '../../utils/logger.js';
14
+ import { cleanupIssueRepo, cloneIssueRepo, ensureWorkspaceDir, syncRepoToRef, } from '../../workspace/workspace-manager.js';
15
+ import { detectDefaultBranch, gitRevParse, isAncestor, listChangedPaths, } from '../find-shared/git.js';
16
+ import { createIssue, fetchOpenIssues, fetchProductBasics, } from '../find-shared/mcp.js';
17
+ import { createPromptGenerator, extractTextFromContent, tryExtractResult, } from '../pr-shared/agent-utils.js';
18
+ import { createFindArchitectureSystemPrompt, createFindArchitectureUserPrompt, } from './prompts.js';
19
+ import { acquireFindArchitectureLock, loadFindArchitectureState, updateFindArchitectureState, } from './state.js';
20
+ import { isScanResult, } from './types.js';
21
+ const WORKSPACE_KEY = 'find-architecture';
22
+ /** Single source of truth — referenced by the CLI help string too. */
23
+ export const DEFAULT_MAX_FILES = 200;
24
+ /**
25
+ * Upper bound on turns for the in-CLI Claude session. Architectural audits
26
+ * traverse imports and follow boundaries across the repo, so they need at
27
+ * least as much headroom as find-bugs / find-smells.
28
+ */
29
+ const MAX_TURNS = 200;
30
+ /**
31
+ * Scan a product's repository for architectural concerns and file each new
32
+ * finding as an issue.
33
+ */
34
+ // eslint-disable-next-line complexity
35
+ export async function scanForArchitecture(options) {
36
+ const { productId, githubToken, owner, repo, full, maxFiles, verbose } = options;
37
+ logInfo(`Starting architecture scan for product ${productId} (${owner}/${repo})`);
38
+ const lock = acquireFindArchitectureLock(productId);
39
+ if (!lock) {
40
+ logWarning(`Another architecture scan is already in progress for product ${productId}; skipping.`);
41
+ return {
42
+ status: 'error',
43
+ message: 'Another architecture scan is already in progress for this product',
44
+ };
45
+ }
46
+ let repoPath;
47
+ let scanSucceeded = false;
48
+ try {
49
+ updateFindArchitectureState(productId, {
50
+ lastAttemptedAt: new Date().toISOString(),
51
+ });
52
+ const workspaceRoot = ensureWorkspaceDir();
53
+ const repoKey = `${WORKSPACE_KEY}-${productId}`;
54
+ ({ repoPath } = cloneIssueRepo(workspaceRoot, repoKey, owner, repo, githubToken));
55
+ const branch = options.branch ?? detectDefaultBranch(repoPath);
56
+ logInfo(`Syncing ${owner}/${repo} to branch ${branch}`);
57
+ syncRepoToRef(repoPath, { branch }, githubToken);
58
+ const headSha = gitRevParse(repoPath, 'HEAD');
59
+ const state = loadFindArchitectureState(productId);
60
+ const baseSha = full ? undefined : state.lastScannedCommitSha;
61
+ let scope = 'full';
62
+ let changedPaths;
63
+ if (baseSha && baseSha !== headSha) {
64
+ const sameTree = isAncestor(repoPath, baseSha, headSha);
65
+ if (sameTree) {
66
+ scope = 'incremental';
67
+ changedPaths = listChangedPaths(repoPath, baseSha, headSha);
68
+ logInfo(`Incremental scan: ${changedPaths.length} files changed since ${baseSha.slice(0, 8)}`);
69
+ if (changedPaths.length === 0) {
70
+ logSuccess('No code changes since last scan; nothing to do.');
71
+ updateFindArchitectureState(productId, {
72
+ lastScannedCommitSha: headSha,
73
+ lastScannedAt: new Date().toISOString(),
74
+ lastError: undefined,
75
+ });
76
+ scanSucceeded = true;
77
+ return {
78
+ status: 'success',
79
+ message: 'No changes since last scan',
80
+ scannedCommitSha: headSha,
81
+ findingsFound: 0,
82
+ issuesCreated: 0,
83
+ };
84
+ }
85
+ }
86
+ else {
87
+ logWarning(`Last scanned sha ${baseSha.slice(0, 8)} not reachable from HEAD; falling back to full scan.`);
88
+ }
89
+ }
90
+ else if (baseSha === headSha) {
91
+ logSuccess('HEAD unchanged since last scan; nothing to do.');
92
+ updateFindArchitectureState(productId, {
93
+ lastScannedAt: new Date().toISOString(),
94
+ lastError: undefined,
95
+ });
96
+ scanSucceeded = true;
97
+ return {
98
+ status: 'success',
99
+ message: 'HEAD unchanged since last scan',
100
+ scannedCommitSha: headSha,
101
+ findingsFound: 0,
102
+ issuesCreated: 0,
103
+ };
104
+ }
105
+ const product = await fetchProductBasics(productId);
106
+ const existingIssues = await fetchOpenIssues(productId);
107
+ logInfo(`Loaded ${existingIssues.length} existing issues for dedup context`);
108
+ const systemPrompt = createFindArchitectureSystemPrompt();
109
+ const userPrompt = createFindArchitectureUserPrompt({
110
+ productName: product.name,
111
+ productDescription: product.description,
112
+ scope,
113
+ baseSha,
114
+ headSha,
115
+ changedPaths,
116
+ maxFiles: maxFiles ?? DEFAULT_MAX_FILES,
117
+ existingIssues: existingIssues.map((i) => ({
118
+ id: i.id,
119
+ name: i.name,
120
+ description: i.description,
121
+ })),
122
+ });
123
+ let lastAssistantResponse = '';
124
+ let scanResult = null;
125
+ logInfo('Running Claude architecture audit...');
126
+ for await (const message of query({
127
+ prompt: createPromptGenerator(userPrompt),
128
+ options: {
129
+ systemPrompt: {
130
+ type: 'preset',
131
+ preset: 'claude_code',
132
+ append: systemPrompt,
133
+ },
134
+ model: DEFAULT_MODEL,
135
+ maxTurns: MAX_TURNS,
136
+ permissionMode: 'bypassPermissions',
137
+ cwd: repoPath,
138
+ },
139
+ })) {
140
+ if (message.type === 'assistant') {
141
+ lastAssistantResponse += extractTextFromContent(message.message?.content ?? [], verbose);
142
+ continue;
143
+ }
144
+ if (message.type !== 'result') {
145
+ continue;
146
+ }
147
+ const responseText = message.subtype === 'success'
148
+ ? message.result || lastAssistantResponse
149
+ : lastAssistantResponse;
150
+ const parsed = tryExtractResult(responseText, 'scan_result');
151
+ if (isScanResult(parsed)) {
152
+ scanResult = parsed;
153
+ }
154
+ else if (message.subtype !== 'success') {
155
+ logError(`Audit incomplete: ${message.subtype}`);
156
+ }
157
+ }
158
+ if (!scanResult) {
159
+ const msg = 'Audit failed: could not parse a scan_result from the agent';
160
+ updateFindArchitectureState(productId, { lastError: msg });
161
+ return {
162
+ status: 'error',
163
+ message: msg,
164
+ };
165
+ }
166
+ const { summary, findings } = scanResult;
167
+ logInfo(`Audit produced ${findings.length} candidate findings. ${summary}`);
168
+ const deferredBugs = scanResult.deferred_to_bugs ?? [];
169
+ const deferredFeatures = scanResult.deferred_to_features ?? [];
170
+ const deferredSmells = scanResult.deferred_to_smells ?? [];
171
+ logDeferred(deferredBugs, 'find-bugs', productId);
172
+ logDeferred(deferredFeatures, 'find-features', productId);
173
+ logDeferred(deferredSmells, 'find-smells', productId);
174
+ let created = 0;
175
+ for (const finding of findings) {
176
+ const issueId = await createIssueForFinding(productId, finding);
177
+ if (issueId) {
178
+ created++;
179
+ logSuccess(`Filed issue ${issueId}: ${finding.title}`);
180
+ }
181
+ }
182
+ updateFindArchitectureState(productId, {
183
+ lastScannedCommitSha: headSha,
184
+ lastScannedAt: new Date().toISOString(),
185
+ lastError: undefined,
186
+ });
187
+ scanSucceeded = true;
188
+ return {
189
+ status: 'success',
190
+ message: `Filed ${created} of ${findings.length} candidate architecture findings (${deferredBugs.length} deferred to bugs, ${deferredFeatures.length} to features, ${deferredSmells.length} to smells)`,
191
+ scannedCommitSha: headSha,
192
+ findingsFound: findings.length,
193
+ issuesCreated: created,
194
+ deferredToBugs: deferredBugs.length,
195
+ deferredToFeatures: deferredFeatures.length,
196
+ deferredToSmells: deferredSmells.length,
197
+ summary,
198
+ };
199
+ }
200
+ catch (error) {
201
+ const errorMessage = error instanceof Error ? error.message : String(error);
202
+ logError(`Architecture scan failed: ${errorMessage}`);
203
+ updateFindArchitectureState(productId, { lastError: errorMessage });
204
+ return {
205
+ status: 'error',
206
+ message: `Architecture scan failed: ${errorMessage}`,
207
+ };
208
+ }
209
+ finally {
210
+ if (scanSucceeded) {
211
+ cleanupIssueRepo(repoPath);
212
+ }
213
+ lock.release();
214
+ }
215
+ }
216
+ function logDeferred(deferred, siblingPhase, productId) {
217
+ if (deferred.length === 0) {
218
+ return;
219
+ }
220
+ logInfo(`${deferred.length} finding(s) deferred to ${siblingPhase} — run \`edsger ${siblingPhase} ${productId}\` to pick them up:`);
221
+ for (const d of deferred) {
222
+ const loc = d.file ? ` (${d.file}${d.line ? `:${d.line}` : ''})` : '';
223
+ logInfo(` • ${d.title}${loc} — ${d.reason}`);
224
+ }
225
+ }
226
+ async function createIssueForFinding(productId, finding) {
227
+ return createIssue({
228
+ productId,
229
+ title: finding.title,
230
+ description: formatIssueDescription(finding),
231
+ });
232
+ }
233
+ function formatIssueDescription(finding) {
234
+ const location = finding.line
235
+ ? `${finding.file}:${finding.line}`
236
+ : finding.file;
237
+ const lines = [
238
+ `**Severity**: ${finding.severity}`,
239
+ `**Concern**: ${finding.concern}`,
240
+ `**Location**: \`${location}\``,
241
+ ];
242
+ if (finding.related_files && finding.related_files.length > 0) {
243
+ lines.push(`**Related**: ${finding.related_files.map((f) => `\`${f}\``).join(', ')}`);
244
+ }
245
+ lines.push('', finding.description, '', '---');
246
+ lines.push('_Filed automatically by `edsger find-architecture`._');
247
+ return lines.join('\n');
248
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Prompts for the find-architecture phase. The agent runs with cwd=repo
3
+ * checkout and has Read/Grep/Glob/Bash available — it explores the code
4
+ * itself 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 handles local code-level improvements (refactor, dead code,
10
+ * readability, perf cliffs, type-safety gaps in a single function/file)
11
+ * - find-architecture (this phase) handles structural problems that span
12
+ * multiple files: module boundaries, layering, coupling, cycles, missing
13
+ * or duplicated abstractions, responsibility creep, cross-cutting concerns.
14
+ */
15
+ export declare function createFindArchitectureSystemPrompt(): string;
16
+ export interface FindArchitectureUserPromptParams {
17
+ productName: string;
18
+ productDescription?: string;
19
+ scope: 'full' | 'incremental';
20
+ baseSha?: string;
21
+ headSha: string;
22
+ changedPaths?: string[];
23
+ existingIssues: {
24
+ id: string;
25
+ name: string;
26
+ description?: string;
27
+ }[];
28
+ /** Upper bound on files the auditor may Read. Keeps token cost predictable. */
29
+ maxFiles?: number;
30
+ }
31
+ export declare function createFindArchitectureUserPrompt(params: FindArchitectureUserPromptParams): string;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Prompts for the find-architecture phase. The agent runs with cwd=repo
3
+ * checkout and has Read/Grep/Glob/Bash available — it explores the code
4
+ * itself 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 handles local code-level improvements (refactor, dead code,
10
+ * readability, perf cliffs, type-safety gaps in a single function/file)
11
+ * - find-architecture (this phase) handles structural problems that span
12
+ * multiple files: module boundaries, layering, coupling, cycles, missing
13
+ * or duplicated abstractions, responsibility creep, cross-cutting concerns.
14
+ */
15
+ export function createFindArchitectureSystemPrompt() {
16
+ return `You are a senior staff engineer auditing a codebase for **architectural problems and improvement opportunities**. You have read-only access via Read/Grep/Glob and may run shallow Bash queries (e.g. \`git log\`, \`wc -l\`, \`grep\`) to navigate.
17
+
18
+ **What counts as an architectural finding worth filing**:
19
+ 1. **Layering violations**: lower layers reaching into upper layers, UI directly hitting persistence, infrastructure leaking into domain
20
+ 2. **Coupling**: modules that know too much about each other's internals, leaky abstractions, pervasive shared mutable state
21
+ 3. **Cohesion**: modules that mix unrelated responsibilities; "god" files/services that have grown into multiple things
22
+ 4. **Cyclic dependencies**: import cycles between modules / packages
23
+ 5. **Boundary problems**: unclear public API surfaces, internal-only types exported, missing seams that make testing hard
24
+ 6. **Duplicated abstractions**: two parallel implementations of the same concept (two HTTP clients, two auth flows, two cache layers)
25
+ 7. **Missing abstraction**: same orchestration pattern hand-rolled in N call sites, no shared helper / interface
26
+ 8. **Responsibility creep**: a service / component that started focused and now does five things
27
+ 9. **Cross-cutting concerns**: logging, auth, retries, error handling implemented inconsistently across modules
28
+ 10. **Inconsistency**: same problem solved different ways in different parts of the codebase, drifting conventions
29
+ 11. **Scalability shape**: data-flow / control-flow patterns that won't survive the next obvious axis of growth
30
+
31
+ **What does NOT count** (skip these — wrong tool):
32
+ - 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\`.**
33
+ - Missing user-facing features or workflows — those belong in \`edsger find-features\`. **List them in \`deferred_to_features\`.**
34
+ - Local code smells confined to a single function/file (refactor candidates, dead code, type-safety gaps, readability issues) — those belong in \`edsger find-smells\`. **List them in \`deferred_to_smells\`.**
35
+ - Pure style / formatting / lint issues
36
+ - Hypothetical future-scaling concerns with no current evidence
37
+ - "Could be more idiomatic" rewrites with no concrete benefit
38
+
39
+ **Discipline**:
40
+ - Be concrete: cite the exact files, modules, or import paths involved. If you flag a cycle, name every file in the cycle. If you flag a layering violation, quote the offending import line.
41
+ - Architectural findings span multiple files almost by definition — use \`related_files\` to enumerate them. The \`file\` field should be the most useful single anchor for a reader.
42
+ - Be conservative: if you can't articulate the *concrete cost* of the current shape (testability blocked, change-amplification, repeated bugs in the same area, slow onboarding), skip it.
43
+ - Severity rubric:
44
+ - high = actively blocking work (cycles preventing builds, coupling causing repeated regressions, missing seams blocking testing the team is clearly trying to do)
45
+ - medium = clear structural improvement that pays back across many future changes
46
+ - low = directional nudge; only file if the fix is small and obvious
47
+ - **Deduplication**: you will be given the list of existing open issues. Skip any finding that overlaps. Better to under-report than spam duplicates.
48
+
49
+ **CRITICAL — Output Format**:
50
+ End your response with a single JSON code block in this exact shape:
51
+
52
+ \`\`\`json
53
+ {
54
+ "scan_result": {
55
+ "summary": "Reviewed N files / M modules in <scope>; found X architectural findings (Y high, Z medium).",
56
+ "scanned_commit_sha": "<the HEAD sha you scanned>",
57
+ "findings": [
58
+ {
59
+ "title": "Short, action-oriented title (under 80 chars)",
60
+ "description": "## What\\nWhat the architectural problem is, with the offending imports/snippets quoted.\\n\\n## Why it matters\\nConcrete cost of the current shape (testability, change-amplification, regression history, onboarding friction).\\n\\n## Suggested change\\nA specific structural change — extracted module, inverted dependency, new boundary, etc.",
61
+ "file": "relative/path/from/repo/root.ts",
62
+ "line": 42,
63
+ "related_files": ["other/file/in/the/cycle.ts", "another/layer/violator.ts"],
64
+ "severity": "medium",
65
+ "concern": "layering",
66
+ "dedup_signature": "ui-layer-imports-db-client"
67
+ }
68
+ ],
69
+ "deferred_to_bugs": [
70
+ { "title": "...", "reason": "...", "file": "...", "line": 100 }
71
+ ],
72
+ "deferred_to_features": [
73
+ { "title": "...", "reason": "...", "file": "..." }
74
+ ],
75
+ "deferred_to_smells": [
76
+ { "title": "...", "reason": "...", "file": "..." }
77
+ ]
78
+ }
79
+ }
80
+ \`\`\`
81
+
82
+ If you find nothing worth filing, still emit the JSON with an empty \`findings\` array. The \`deferred_to_*\` arrays are optional — omit them or send \`[]\` if there's nothing to hand off.`;
83
+ }
84
+ export function createFindArchitectureUserPrompt(params) {
85
+ const { productName, productDescription, scope, baseSha, headSha, changedPaths, existingIssues, maxFiles, } = params;
86
+ const productBlock = productDescription
87
+ ? `**Product**: ${productName}\n${productDescription}`
88
+ : `**Product**: ${productName}`;
89
+ const scopeBlock = scope === 'incremental' && baseSha
90
+ ? `**Scope**: incremental scan focused on changes between ${baseSha} and ${headSha}, but architectural findings are inherently structural — feel free to follow imports out of the diff to confirm boundaries / cycles. Use \`git diff --name-only ${baseSha}..${headSha}\` to enumerate the entry points.`
91
+ : `**Scope**: full repository scan at ${headSha}. Use Glob to enumerate source modules. Skip vendored code, build output, generated files, lockfiles, and \`node_modules\`. Map out the top-level module structure first, then drill into suspected hotspots.`;
92
+ const filesHint = changedPaths && changedPaths.length > 0
93
+ ? `\n**Changed files in this range** (${changedPaths.length}):\n${changedPaths
94
+ .slice(0, 200)
95
+ .map((p) => `- ${p}`)
96
+ .join('\n')}${changedPaths.length > 200 ? `\n…and ${changedPaths.length - 200} more.` : ''}`
97
+ : '';
98
+ const issuesBlock = existingIssues.length === 0
99
+ ? 'No existing open issues for this product — every finding is new.'
100
+ : `**Existing open issues** (${existingIssues.length}) — skip findings that overlap with any of these:\n${existingIssues
101
+ .map((i) => `- [${i.id}] ${i.name}${i.description ? `\n ${truncate(i.description, 200)}` : ''}`)
102
+ .join('\n')}`;
103
+ const budgetBlock = typeof maxFiles === 'number' && maxFiles > 0
104
+ ? `\n**Budget**: Read at most ${maxFiles} files. Prioritise top-level module entry points, package boundaries, shared infrastructure (clients, services, framework glue), and files most-imported by the rest of the repo. If the scope is larger than the budget, stop when you hit it and report truncation in \`summary\`.`
105
+ : '';
106
+ return `${productBlock}
107
+
108
+ ${scopeBlock}${filesHint}${budgetBlock}
109
+
110
+ ${issuesBlock}
111
+
112
+ ## How to work
113
+
114
+ 1. Map the top-level module structure first (\`ls\`, \`Glob\` on top-level dirs). Identify the natural layers / boundaries the codebase is trying to maintain.
115
+ 2. For each suspected concern (layering violation, cycle, coupling hotspot, duplicated abstraction, responsibility creep), follow imports / call sites with Grep + Read to confirm before filing.
116
+ 3. When you suspect a structural issue, articulate the *concrete cost* of the current shape. If you can't name the cost, drop it.
117
+ 4. If something looks like a real bug, a missing user feature, or a local code smell — drop it from this scan and route it via the appropriate \`deferred_to_*\` array.
118
+ 5. Cross-check every candidate against the existing issues list. Drop overlaps.
119
+ 6. Produce the final JSON described in the system prompt.
120
+
121
+ Begin.`;
122
+ }
123
+ function truncate(s, n) {
124
+ if (s.length <= n) {
125
+ return s;
126
+ }
127
+ return `${s.slice(0, n)}…`;
128
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Per-product scan state for find-architecture. Storage at
3
+ * `~/.edsger/find-architecture-state/<productId>.json`.
4
+ *
5
+ * Same schema shape as find-smells / find-bugs (incremental sha tracking) —
6
+ * file/lock machinery shared via createScanStateModule. Kept as a sibling
7
+ * state file so an architecture scan can run alongside other find-* scans
8
+ * without contending on the same lock.
9
+ */
10
+ import { type LockHandle } from '../find-shared/scan-state.js';
11
+ export type { LockHandle };
12
+ export interface FindArchitectureState {
13
+ lastScannedCommitSha?: string;
14
+ lastScannedAt?: string;
15
+ lastAttemptedAt?: string;
16
+ lastError?: string;
17
+ }
18
+ export declare const loadFindArchitectureState: (productId: string) => FindArchitectureState;
19
+ export declare const saveFindArchitectureState: (productId: string, state: FindArchitectureState) => void;
20
+ export declare const updateFindArchitectureState: (productId: string, patch: Partial<FindArchitectureState>) => FindArchitectureState;
21
+ export declare const acquireFindArchitectureLock: (productId: string, staleAfterMs?: number) => LockHandle | null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Per-product scan state for find-architecture. Storage at
3
+ * `~/.edsger/find-architecture-state/<productId>.json`.
4
+ *
5
+ * Same schema shape as find-smells / find-bugs (incremental sha tracking) —
6
+ * file/lock machinery shared via createScanStateModule. Kept as a sibling
7
+ * state file so an architecture scan can run alongside other find-* scans
8
+ * without contending on the same lock.
9
+ */
10
+ import { createScanStateModule, } from '../find-shared/scan-state.js';
11
+ const m = createScanStateModule({
12
+ dirName: 'find-architecture-state',
13
+ });
14
+ export const loadFindArchitectureState = m.load;
15
+ export const saveFindArchitectureState = m.save;
16
+ export const updateFindArchitectureState = m.update;
17
+ export const acquireFindArchitectureLock = m.acquireLock;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Types for the find-architecture phase.
3
+ *
4
+ * Where find-smells covers local "the code would be better if changed" findings
5
+ * (refactor candidates, dead code, perf cliffs, etc.), this phase zooms out to
6
+ * **architectural** problems and improvements — module boundaries, layering,
7
+ * coupling, dependency direction, responsibility creep, missing or duplicated
8
+ * abstractions, cross-cutting concerns. Findings span multiple files by nature.
9
+ */
10
+ export type ArchitectureSeverity = 'high' | 'medium' | 'low';
11
+ /**
12
+ * Authoritative list of allowed concern types. Kept as a `const` array so the
13
+ * type and the runtime whitelist can never drift apart.
14
+ */
15
+ export declare const ARCHITECTURE_CONCERNS: readonly ["layering", "coupling", "cohesion", "cyclic_dependency", "boundary", "duplication", "missing_abstraction", "responsibility_creep", "cross_cutting", "inconsistency", "scalability", "other"];
16
+ export type ArchitectureConcern = (typeof ARCHITECTURE_CONCERNS)[number];
17
+ export declare function isArchitectureConcern(value: unknown): value is ArchitectureConcern;
18
+ export interface ArchitectureFinding {
19
+ title: string;
20
+ description: string;
21
+ /** Primary anchor file or module path. */
22
+ file: string;
23
+ /** Optional line in the primary file. */
24
+ line?: number;
25
+ /** Other files involved in the finding (cycle members, layer crossers, etc.). */
26
+ related_files?: string[];
27
+ severity: ArchitectureSeverity;
28
+ concern: ArchitectureConcern;
29
+ /** Stable signature for log/audit; not used for storage dedup. */
30
+ dedup_signature?: string;
31
+ }
32
+ /**
33
+ * A finding the agent saw but is handing off to a sibling phase rather than
34
+ * filing as an architecture issue. Surfaced in the run log so the user knows
35
+ * the work wasn't silently lost.
36
+ */
37
+ export interface DeferredFinding {
38
+ title: string;
39
+ reason: string;
40
+ file?: string;
41
+ line?: number;
42
+ }
43
+ export declare function isDeferredFinding(value: unknown): value is DeferredFinding;
44
+ export interface ScanResult {
45
+ summary: string;
46
+ scanned_commit_sha?: string;
47
+ findings: ArchitectureFinding[];
48
+ /** Findings the agent thinks belong in `edsger find-bugs`. */
49
+ deferred_to_bugs?: DeferredFinding[];
50
+ /** Findings the agent thinks belong in `edsger find-features`. */
51
+ deferred_to_features?: DeferredFinding[];
52
+ /** Findings the agent thinks belong in `edsger find-smells`. */
53
+ deferred_to_smells?: DeferredFinding[];
54
+ }
55
+ export declare function isScanResult(value: unknown): value is ScanResult;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Types for the find-architecture phase.
3
+ *
4
+ * Where find-smells covers local "the code would be better if changed" findings
5
+ * (refactor candidates, dead code, perf cliffs, etc.), this phase zooms out to
6
+ * **architectural** problems and improvements — module boundaries, layering,
7
+ * coupling, dependency direction, responsibility creep, missing or duplicated
8
+ * abstractions, cross-cutting concerns. Findings span multiple files by nature.
9
+ */
10
+ /**
11
+ * Authoritative list of allowed concern types. Kept as a `const` array so the
12
+ * type and the runtime whitelist can never drift apart.
13
+ */
14
+ export const ARCHITECTURE_CONCERNS = [
15
+ 'layering',
16
+ 'coupling',
17
+ 'cohesion',
18
+ 'cyclic_dependency',
19
+ 'boundary',
20
+ 'duplication',
21
+ 'missing_abstraction',
22
+ 'responsibility_creep',
23
+ 'cross_cutting',
24
+ 'inconsistency',
25
+ 'scalability',
26
+ 'other',
27
+ ];
28
+ export function isArchitectureConcern(value) {
29
+ return (typeof value === 'string' &&
30
+ ARCHITECTURE_CONCERNS.includes(value));
31
+ }
32
+ export function isDeferredFinding(value) {
33
+ if (!value || typeof value !== 'object') {
34
+ return false;
35
+ }
36
+ const v = value;
37
+ return typeof v.title === 'string' && typeof v.reason === 'string';
38
+ }
39
+ export function isScanResult(value) {
40
+ if (!value || typeof value !== 'object') {
41
+ return false;
42
+ }
43
+ const v = value;
44
+ if (typeof v.summary !== 'string' || !Array.isArray(v.findings)) {
45
+ return false;
46
+ }
47
+ const findingsOk = v.findings.every((f) => f &&
48
+ typeof f === 'object' &&
49
+ typeof f.title === 'string' &&
50
+ typeof f.description === 'string' &&
51
+ typeof f.file === 'string');
52
+ if (!findingsOk) {
53
+ return false;
54
+ }
55
+ for (const key of [
56
+ 'deferred_to_bugs',
57
+ 'deferred_to_features',
58
+ 'deferred_to_smells',
59
+ ]) {
60
+ const arr = v[key];
61
+ if (arr === undefined) {
62
+ continue;
63
+ }
64
+ if (!Array.isArray(arr) || !arr.every(isDeferredFinding)) {
65
+ return false;
66
+ }
67
+ }
68
+ return true;
69
+ }
@@ -6,7 +6,7 @@
6
6
  import { query } from '@anthropic-ai/claude-agent-sdk';
7
7
  import { DEFAULT_MODEL } from '../../constants.js';
8
8
  import { logError, logInfo, logSuccess, logWarning, } from '../../utils/logger.js';
9
- import { cloneIssueRepo, ensureWorkspaceDir, syncRepoToRef, } from '../../workspace/workspace-manager.js';
9
+ import { cleanupIssueRepo, cloneIssueRepo, ensureWorkspaceDir, syncRepoToRef, } from '../../workspace/workspace-manager.js';
10
10
  import { detectDefaultBranch, gitRevParse, isAncestor, listChangedPaths, } from '../find-shared/git.js';
11
11
  import { createIssue, fetchOpenIssues, fetchProductBasics, } from '../find-shared/mcp.js';
12
12
  import { createPromptGenerator, extractTextFromContent, tryExtractResult, } from '../pr-shared/agent-utils.js';
@@ -42,15 +42,18 @@ export async function scanForBugs(options) {
42
42
  message: 'Another bug scan is already in progress for this product',
43
43
  };
44
44
  }
45
+ let repoPath;
46
+ let scanSucceeded = false;
45
47
  try {
46
48
  updateFindBugsState(productId, {
47
49
  lastAttemptedAt: new Date().toISOString(),
48
50
  });
49
51
  const workspaceRoot = ensureWorkspaceDir();
50
- // Reuse a single workspace per product so incremental scans don't re-clone.
52
+ // Each run re-clones into a per-product directory and removes it on
53
+ // success. Incremental scope is recovered from the persisted state file
54
+ // (~/.edsger/find-bugs-state/<productId>.json), not from the workspace.
51
55
  const repoKey = `${WORKSPACE_KEY}-${productId}`;
52
- const cloned = cloneIssueRepo(workspaceRoot, repoKey, owner, repo, githubToken);
53
- const { repoPath } = cloned;
56
+ ({ repoPath } = cloneIssueRepo(workspaceRoot, repoKey, owner, repo, githubToken));
54
57
  const branch = options.branch ?? detectDefaultBranch(repoPath);
55
58
  logInfo(`Syncing ${owner}/${repo} to branch ${branch}`);
56
59
  syncRepoToRef(repoPath, { branch }, githubToken);
@@ -72,6 +75,7 @@ export async function scanForBugs(options) {
72
75
  lastScannedAt: new Date().toISOString(),
73
76
  lastError: undefined,
74
77
  });
78
+ scanSucceeded = true;
75
79
  return {
76
80
  status: 'success',
77
81
  message: 'No changes since last scan',
@@ -87,6 +91,7 @@ export async function scanForBugs(options) {
87
91
  }
88
92
  else if (baseSha === headSha) {
89
93
  logSuccess('HEAD unchanged since last scan; nothing to do.');
94
+ scanSucceeded = true;
90
95
  return {
91
96
  status: 'success',
92
97
  message: 'HEAD unchanged since last scan',
@@ -171,6 +176,7 @@ export async function scanForBugs(options) {
171
176
  lastScannedAt: new Date().toISOString(),
172
177
  lastError: undefined,
173
178
  });
179
+ scanSucceeded = true;
174
180
  return {
175
181
  status: 'success',
176
182
  message: `Filed ${created} of ${bugs.length} candidate bugs`,
@@ -190,6 +196,9 @@ export async function scanForBugs(options) {
190
196
  };
191
197
  }
192
198
  finally {
199
+ if (scanSucceeded) {
200
+ cleanupIssueRepo(repoPath);
201
+ }
193
202
  lock.release();
194
203
  }
195
204
  }