edsger 0.76.0 → 0.77.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 (43) hide show
  1. package/dist/commands/api-docs/index.d.ts +18 -0
  2. package/dist/commands/api-docs/index.js +41 -0
  3. package/dist/commands/quality-benchmark/index.d.ts +5 -0
  4. package/dist/commands/quality-benchmark/index.js +28 -0
  5. package/dist/index.js +29 -0
  6. package/dist/phases/api-docs/index.d.ts +47 -0
  7. package/dist/phases/api-docs/index.js +254 -0
  8. package/dist/phases/api-docs/mcp-server.d.ts +25 -0
  9. package/dist/phases/api-docs/mcp-server.js +82 -0
  10. package/dist/phases/api-docs/prompts.d.ts +16 -0
  11. package/dist/phases/api-docs/prompts.js +65 -0
  12. package/dist/phases/api-docs/types.d.ts +22 -0
  13. package/dist/phases/api-docs/types.js +10 -0
  14. package/dist/phases/find-architecture/index.js +13 -6
  15. package/dist/phases/find-architecture/prompts.d.ts +2 -1
  16. package/dist/phases/find-architecture/prompts.js +3 -2
  17. package/dist/phases/find-bugs/index.js +3 -1
  18. package/dist/phases/find-shared/baseline.d.ts +45 -0
  19. package/dist/phases/find-shared/baseline.js +56 -0
  20. package/dist/phases/find-shared/custom-rules.d.ts +39 -0
  21. package/dist/phases/find-shared/custom-rules.js +75 -0
  22. package/dist/phases/find-shared/detect-context.d.ts +40 -0
  23. package/dist/phases/find-shared/detect-context.js +247 -0
  24. package/dist/phases/find-shared/mcp.d.ts +6 -0
  25. package/dist/phases/find-shared/mcp.js +2 -0
  26. package/dist/phases/find-shared/rule-config.d.ts +37 -0
  27. package/dist/phases/find-shared/rule-config.js +67 -0
  28. package/dist/phases/find-shared/rule-packs.d.ts +65 -0
  29. package/dist/phases/find-shared/rule-packs.js +124 -0
  30. package/dist/phases/find-shared/scoped-read.d.ts +12 -0
  31. package/dist/phases/find-shared/scoped-read.js +33 -0
  32. package/dist/phases/find-smells/index.js +12 -5
  33. package/dist/phases/find-smells/prompts.d.ts +2 -1
  34. package/dist/phases/find-smells/prompts.js +4 -3
  35. package/dist/phases/quality-benchmark/gate.d.ts +50 -0
  36. package/dist/phases/quality-benchmark/gate.js +91 -0
  37. package/dist/phases/quality-benchmark/index.js +15 -1
  38. package/dist/phases/quality-benchmark/parsers.d.ts +23 -0
  39. package/dist/phases/quality-benchmark/parsers.js +210 -0
  40. package/dist/phases/quality-benchmark/rubric.md +37 -0
  41. package/dist/phases/quality-benchmark/tool-catalog.js +58 -1
  42. package/dist/phases/quality-benchmark/types.d.ts +8 -1
  43. package/package.json +1 -1
@@ -98,6 +98,7 @@ export async function createIssue(input) {
98
98
  repository_id: repositoryId,
99
99
  name: input.title,
100
100
  description: input.description,
101
+ ...(input.source ? { source: input.source } : {}),
101
102
  })
102
103
  .select('id')
103
104
  .single();
@@ -115,6 +116,7 @@ export async function createIssue(input) {
115
116
  ...(repositoryId ? { repository_id: repositoryId } : {}),
116
117
  name: input.title,
117
118
  description: input.description,
119
+ ...(input.source ? { source: input.source } : {}),
118
120
  }));
119
121
  return result.issue?.id || result.id || null;
120
122
  }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Per-scope rule-pack configuration, shared across the find-* phases.
3
+ *
4
+ * Lets a team tune which stack-aware rule packs the scanners apply via a preset
5
+ * plus explicit per-pack toggles — the configurable-rules capability DCM-style
6
+ * tools expose. Read here from the user's supabase session; edited from the
7
+ * desktop app (services/db/quality-rule-configs.ts). Stored in
8
+ * `quality_rule_configs`.
9
+ */
10
+ import type { ScanScope } from './baseline.js';
11
+ import { type RulePack } from './rule-packs.js';
12
+ export type RulePreset = 'minimal' | 'recommended' | 'strict';
13
+ export interface RuleConfig {
14
+ preset: RulePreset;
15
+ disabledPacks: string[];
16
+ }
17
+ /**
18
+ * Apply a rule config to the packs detection selected. Pure + exported for
19
+ * testing.
20
+ *
21
+ * - no config → unchanged (default is 'recommended' = all detected packs).
22
+ * - 'minimal' → no packs (generic categories only).
23
+ * - otherwise → detected packs minus the explicitly disabled ones.
24
+ */
25
+ export declare function applyRuleConfig(packs: RulePack[], config: RuleConfig | null): RulePack[];
26
+ /**
27
+ * Fetch the rule config for a scope, or null if none is set / no session is
28
+ * available. Never throws — a read failure must not abort a scan (it just
29
+ * degrades to the default 'recommended' behaviour).
30
+ */
31
+ export declare function getRuleConfig(scope: ScanScope): Promise<RuleConfig | null>;
32
+ /**
33
+ * Detect the repo's stack, apply the scope's rule config, and return the rule
34
+ * packs to inject — logging the detected stack and chosen packs. Shared by the
35
+ * pack-consuming phases (find-smells, find-architecture).
36
+ */
37
+ export declare function resolveStackRulePacks(repoRoot: string, scope: ScanScope): Promise<RulePack[]>;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Per-scope rule-pack configuration, shared across the find-* phases.
3
+ *
4
+ * Lets a team tune which stack-aware rule packs the scanners apply via a preset
5
+ * plus explicit per-pack toggles — the configurable-rules capability DCM-style
6
+ * tools expose. Read here from the user's supabase session; edited from the
7
+ * desktop app (services/db/quality-rule-configs.ts). Stored in
8
+ * `quality_rule_configs`.
9
+ */
10
+ import { logInfo } from '../../utils/logger.js';
11
+ import { detectProjectContext } from './detect-context.js';
12
+ import { selectRulePacks } from './rule-packs.js';
13
+ import { readScopedRow } from './scoped-read.js';
14
+ /**
15
+ * Apply a rule config to the packs detection selected. Pure + exported for
16
+ * testing.
17
+ *
18
+ * - no config → unchanged (default is 'recommended' = all detected packs).
19
+ * - 'minimal' → no packs (generic categories only).
20
+ * - otherwise → detected packs minus the explicitly disabled ones.
21
+ */
22
+ export function applyRuleConfig(packs, config) {
23
+ if (!config) {
24
+ return packs;
25
+ }
26
+ if (config.preset === 'minimal') {
27
+ return [];
28
+ }
29
+ return packs.filter((p) => !config.disabledPacks.includes(p.id));
30
+ }
31
+ /**
32
+ * Fetch the rule config for a scope, or null if none is set / no session is
33
+ * available. Never throws — a read failure must not abort a scan (it just
34
+ * degrades to the default 'recommended' behaviour).
35
+ */
36
+ export async function getRuleConfig(scope) {
37
+ const row = await readScopedRow('quality_rule_configs', 'preset, disabled_packs', scope);
38
+ if (!row) {
39
+ return null;
40
+ }
41
+ return {
42
+ preset: row.preset ?? 'recommended',
43
+ disabledPacks: row.disabled_packs ?? [],
44
+ };
45
+ }
46
+ /**
47
+ * Detect the repo's stack, apply the scope's rule config, and return the rule
48
+ * packs to inject — logging the detected stack and chosen packs. Shared by the
49
+ * pack-consuming phases (find-smells, find-architecture).
50
+ */
51
+ export async function resolveStackRulePacks(repoRoot, scope) {
52
+ const projectContext = detectProjectContext(repoRoot);
53
+ const ruleConfig = await getRuleConfig(scope);
54
+ const rulePacks = applyRuleConfig(selectRulePacks(projectContext), ruleConfig);
55
+ const detectedStack = [
56
+ ...projectContext.languages,
57
+ ...projectContext.frameworks,
58
+ ];
59
+ const stackLabel = detectedStack.length
60
+ ? detectedStack.join(', ')
61
+ : 'unknown';
62
+ const packLabel = rulePacks.length
63
+ ? `; applying rule packs: ${rulePacks.map((p) => p.id).join(', ')}`
64
+ : '; no stack-specific rule packs matched';
65
+ logInfo(`Detected stack: ${stackLabel}${packLabel}`);
66
+ return rulePacks;
67
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Stack-specific rule packs for the find-* phases.
3
+ *
4
+ * The generic smell/bug/architecture categories in the base system prompts are
5
+ * language-neutral and always apply. A *rule pack* adds targeted, stack-aware
6
+ * guidance — e.g. Flutter widget anti-patterns, TypeScript type-safety escapes
7
+ * — that should only fire when the relevant language/framework is actually
8
+ * present in the repository.
9
+ *
10
+ * The design intentionally mirrors the quality-benchmark tool catalog:
11
+ * - tools gate on `applies_to: [<LanguageTag>]`, selected by
12
+ * `selectToolsForContext(languages)`.
13
+ * - rule packs gate on `applies_to: { languages?, frameworks?, files_present? }`,
14
+ * selected by `selectRulePacks(context)`.
15
+ *
16
+ * Adding support for a new language/framework is therefore a pure data change:
17
+ * append one `RulePack` here (and, eventually, more of them) — no phase code
18
+ * branches on a specific language anywhere.
19
+ */
20
+ import type { ProjectContext } from './detect-context.js';
21
+ /**
22
+ * Which find-* phase a guidance block is written for. A pack only contributes
23
+ * to a phase it has guidance for, so the same pack can sharpen find-smells with
24
+ * local anti-patterns and find-architecture with structural ones without
25
+ * leaking smell guidance into the architecture audit (or vice versa).
26
+ */
27
+ export type FindPhaseKind = 'smells' | 'architecture' | 'bugs';
28
+ export interface RulePack {
29
+ /** Stable id, shown in logs and used in tests. */
30
+ id: string;
31
+ /** Human-readable label. */
32
+ label: string;
33
+ /**
34
+ * Gate conditions. A pack is selected when EVERY specified gate matches
35
+ * (AND across gates), where a gate matches if ANY of its values is present
36
+ * in the detected context (OR within a gate). At least one gate must be set.
37
+ */
38
+ applies_to: {
39
+ languages?: string[];
40
+ frameworks?: string[];
41
+ files_present?: string[];
42
+ };
43
+ /**
44
+ * Per-phase markdown guidance injected into the find-* system prompt when the
45
+ * pack is selected. Each block should enumerate concrete, file:line-citable
46
+ * anti-patterns that map onto that phase's existing categories (no new
47
+ * categories introduced). A pack may cover only some phases.
48
+ */
49
+ guidance: Partial<Record<FindPhaseKind, string>>;
50
+ }
51
+ export declare const RULE_PACKS: readonly RulePack[];
52
+ /**
53
+ * Select the rule packs whose gates are satisfied by the detected context.
54
+ * Same AND-across-gates / OR-within-gate semantics as the quality-benchmark
55
+ * `selectToolsForContext`. Membership checks are case-insensitive.
56
+ */
57
+ export declare function selectRulePacks(ctx: ProjectContext): RulePack[];
58
+ /**
59
+ * Render the guidance the selected packs provide *for a given phase* into a
60
+ * single markdown block for appending to that phase's system prompt. Packs
61
+ * without guidance for `kind` are skipped, so e.g. the TypeScript pack (smells
62
+ * only) contributes nothing to the architecture audit. Returns '' when nothing
63
+ * applies, so callers can concatenate unconditionally.
64
+ */
65
+ export declare function renderRulePacks(packs: RulePack[], kind: FindPhaseKind): string;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Stack-specific rule packs for the find-* phases.
3
+ *
4
+ * The generic smell/bug/architecture categories in the base system prompts are
5
+ * language-neutral and always apply. A *rule pack* adds targeted, stack-aware
6
+ * guidance — e.g. Flutter widget anti-patterns, TypeScript type-safety escapes
7
+ * — that should only fire when the relevant language/framework is actually
8
+ * present in the repository.
9
+ *
10
+ * The design intentionally mirrors the quality-benchmark tool catalog:
11
+ * - tools gate on `applies_to: [<LanguageTag>]`, selected by
12
+ * `selectToolsForContext(languages)`.
13
+ * - rule packs gate on `applies_to: { languages?, frameworks?, files_present? }`,
14
+ * selected by `selectRulePacks(context)`.
15
+ *
16
+ * Adding support for a new language/framework is therefore a pure data change:
17
+ * append one `RulePack` here (and, eventually, more of them) — no phase code
18
+ * branches on a specific language anywhere.
19
+ */
20
+ // ---------------------------------------------------------------------------
21
+ // Packs
22
+ // ---------------------------------------------------------------------------
23
+ const flutter = {
24
+ id: 'flutter',
25
+ label: 'Flutter / Dart',
26
+ applies_to: { frameworks: ['flutter'] },
27
+ guidance: {
28
+ smells: `Flutter/Dart widget and performance smells (in addition to the generic categories):
29
+ - **Giant \`build()\` methods**: a build method spanning dozens of lines or many nested widgets — extract subtrees into named \`Widget\` classes or helper methods. (category: complexity)
30
+ - **Missing \`const\`**: widgets with compile-time-constant configuration that are not \`const\`, forcing needless rebuilds. (category: performance)
31
+ - **Deep widget nesting**: trees nested well beyond ~5 levels that should be decomposed into smaller widgets. (category: complexity)
32
+ - **Unbounded list rendering**: \`Column\`/\`ListView(children: [...])\` over a growing or large collection instead of \`ListView.builder\`/\`SliverList\`. (category: performance)
33
+ - **Work inside \`build()\`**: constructing controllers, futures, or expensive objects in \`build()\` instead of \`initState\`/memoization — they get recreated every rebuild. (category: performance)
34
+ - **Over-broad \`setState\`**: calling \`setState\` on a large widget where a smaller \`StatefulWidget\`, \`ValueListenableBuilder\`, or \`Selector\` would localise the rebuild. (category: performance)
35
+ - **Unkeyed dynamic lists**: reorderable/dynamic children without \`Key\`s, risking state mismatches. (category: readability)`,
36
+ architecture: `Flutter/Dart structural concerns (in addition to the generic categories):
37
+ - **Business logic in widgets**: data fetching, persistence, or domain rules embedded directly in \`Widget\`/\`State\` classes instead of a dedicated layer (controller/bloc/cubit/service). (concern: layering)
38
+ - **God widgets**: a single screen widget that builds UI, holds state, talks to the network, and formats data — split by responsibility. (concern: cohesion)
39
+ - **Cross-feature \`BuildContext\` reach-through**: features reaching into each other's widget state instead of going through a shared layer. (concern: coupling)`,
40
+ },
41
+ };
42
+ const typescript = {
43
+ id: 'typescript',
44
+ label: 'TypeScript',
45
+ applies_to: { languages: ['ts'] },
46
+ guidance: {
47
+ smells: `TypeScript type-safety smells (in addition to the generic categories):
48
+ - **Type escapes**: \`any\`/\`unknown\` casts that erase checking; prefer precise types or generics. (category: type_safety)
49
+ - **Suppressed errors**: \`@ts-ignore\`/\`@ts-expect-error\` hiding real type errors rather than fixing them. (category: type_safety)
50
+ - **Unsafe assertions**: \`as\` casts and non-null assertions (\`!\`) at trust boundaries instead of real narrowing/null checks. (category: type_safety)
51
+ - **Loose contracts**: \`object\`, open index signatures, or wide unions where a tighter interface/literal type is intended. (category: type_safety)
52
+ - **Derivable duplication**: enums/unions hand-maintained in parallel instead of derived (\`as const\` + \`keyof\`/\`typeof\`). (category: refactor)`,
53
+ },
54
+ };
55
+ const csharp = {
56
+ id: 'csharp',
57
+ label: 'C# / .NET',
58
+ applies_to: { languages: ['cs'] },
59
+ guidance: {
60
+ smells: `C#/.NET smells (in addition to the generic categories):
61
+ - **Async anti-patterns**: \`.Result\`/\`.Wait()\`/\`.GetAwaiter().GetResult()\` on tasks (sync-over-async deadlock risk); \`async void\` outside event handlers. (category: performance)
62
+ - **Multiple enumeration**: enumerating the same \`IEnumerable\` more than once (re-runs the query/LINQ); materialize with \`ToList()\`/\`ToArray()\` once. (category: performance)
63
+ - **Disposal**: \`IDisposable\` created without \`using\`/\`await using\` or an explicit \`Dispose\`. (category: type_safety)
64
+ - **Swallowed exceptions**: empty \`catch {}\` or \`catch (Exception)\` that hides failures. (category: refactor)
65
+ - **Nullable ignored**: suppressing nullable warnings with \`!\` (null-forgiving) at trust boundaries instead of real checks. (category: type_safety)
66
+ - **String building in loops**: \`+=\` string concatenation inside loops instead of \`StringBuilder\`. (category: performance)
67
+ - **Public mutable fields**: public fields where a property is intended. (category: readability)`,
68
+ architecture: `C#/.NET structural concerns (in addition to the generic categories):
69
+ - **Fat controllers**: business/data logic in ASP.NET controllers instead of a service/handler layer. (concern: layering)
70
+ - **Leaky persistence**: \`DbContext\`/EF queries used directly across layers instead of behind a repository/service boundary. (concern: layering)
71
+ - **Mutable static/singleton state**: static fields or singletons holding mutable shared state, complicating testing and concurrency. (concern: coupling)
72
+ - **Project reference cycles**: circular references between projects/assemblies. (concern: cyclic dependencies)`,
73
+ },
74
+ };
75
+ // ---------------------------------------------------------------------------
76
+ // Registry + selection
77
+ // ---------------------------------------------------------------------------
78
+ export const RULE_PACKS = [
79
+ flutter,
80
+ typescript,
81
+ csharp,
82
+ ];
83
+ /**
84
+ * Select the rule packs whose gates are satisfied by the detected context.
85
+ * Same AND-across-gates / OR-within-gate semantics as the quality-benchmark
86
+ * `selectToolsForContext`. Membership checks are case-insensitive.
87
+ */
88
+ export function selectRulePacks(ctx) {
89
+ const langSet = new Set(ctx.languages.map((l) => l.toLowerCase()));
90
+ const fwSet = new Set(ctx.frameworks.map((f) => f.toLowerCase()));
91
+ const fileSet = new Set(ctx.files_present);
92
+ return RULE_PACKS.filter((pack) => {
93
+ const { languages, frameworks, files_present } = pack.applies_to;
94
+ const gates = [];
95
+ if (languages?.length) {
96
+ gates.push(languages.some((l) => langSet.has(l.toLowerCase())));
97
+ }
98
+ if (frameworks?.length) {
99
+ gates.push(frameworks.some((f) => fwSet.has(f.toLowerCase())));
100
+ }
101
+ if (files_present?.length) {
102
+ gates.push(files_present.some((f) => fileSet.has(f)));
103
+ }
104
+ // A pack with no gates is a misconfiguration — never auto-select it.
105
+ return gates.length > 0 && gates.every(Boolean);
106
+ });
107
+ }
108
+ /**
109
+ * Render the guidance the selected packs provide *for a given phase* into a
110
+ * single markdown block for appending to that phase's system prompt. Packs
111
+ * without guidance for `kind` are skipped, so e.g. the TypeScript pack (smells
112
+ * only) contributes nothing to the architecture audit. Returns '' when nothing
113
+ * applies, so callers can concatenate unconditionally.
114
+ */
115
+ export function renderRulePacks(packs, kind) {
116
+ const sections = packs
117
+ .map((p) => ({ label: p.label, text: p.guidance[kind] }))
118
+ .filter((s) => Boolean(s.text))
119
+ .map((s) => `### ${s.label}\n${s.text}`);
120
+ if (sections.length === 0) {
121
+ return '';
122
+ }
123
+ return `\n\n**Stack-specific checks** — the repository's detected stack triggers the following targeted checks. Apply them *in addition to* the generic categories above, using the same severity rubric and output format:\n\n${sections.join('\n\n')}`;
124
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared helper for reading a single scope-keyed row (product XOR repo) via the
3
+ * user's supabase session. Used by the find-* scan-config readers
4
+ * (getScanBaseline, getRuleConfig) so they don't each re-implement the
5
+ * session-guard + scoped query + never-throw error handling.
6
+ */
7
+ import type { ScanScope } from './baseline.js';
8
+ /**
9
+ * Fetch one scope-keyed row, or null when there's no session / no row / a read
10
+ * error. Never throws — a read failure must not abort a scan.
11
+ */
12
+ export declare function readScopedRow<T>(table: string, columns: string, scope: ScanScope): Promise<T | null>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Shared helper for reading a single scope-keyed row (product XOR repo) via the
3
+ * user's supabase session. Used by the find-* scan-config readers
4
+ * (getScanBaseline, getRuleConfig) so they don't each re-implement the
5
+ * session-guard + scoped query + never-throw error handling.
6
+ */
7
+ import { getSupabase, hasSupabaseSession } from '../../supabase/client.js';
8
+ import { logWarning } from '../../utils/logger.js';
9
+ /**
10
+ * Fetch one scope-keyed row, or null when there's no session / no row / a read
11
+ * error. Never throws — a read failure must not abort a scan.
12
+ */
13
+ export async function readScopedRow(table, columns, scope) {
14
+ if (!hasSupabaseSession()) {
15
+ return null;
16
+ }
17
+ try {
18
+ const query = getSupabase().from(table).select(columns);
19
+ const scoped = scope.productId
20
+ ? query.eq('product_id', scope.productId)
21
+ : query.eq('repository_id', scope.repoId);
22
+ const { data, error } = await scoped.maybeSingle();
23
+ if (error) {
24
+ logWarning(`Could not read ${table}: ${error.message}`);
25
+ return null;
26
+ }
27
+ return data ?? null;
28
+ }
29
+ catch (err) {
30
+ logWarning(`Could not read ${table}: ${err instanceof Error ? err.message : String(err)}`);
31
+ return null;
32
+ }
33
+ }
@@ -11,8 +11,11 @@ import { query } from '@anthropic-ai/claude-agent-sdk';
11
11
  import { DEFAULT_MODEL } from '../../constants.js';
12
12
  import { logError, logInfo, logSuccess, logWarning, } from '../../utils/logger.js';
13
13
  import { cleanupIssueRepo, cloneIssueRepo, ensureWorkspaceDir, syncRepoToRef, } from '../../workspace/workspace-manager.js';
14
+ import { resolveScanBase } from '../find-shared/baseline.js';
15
+ import { resolveCustomRules } from '../find-shared/custom-rules.js';
14
16
  import { detectDefaultBranch, gitRevParse, isAncestor, listChangedPaths, } from '../find-shared/git.js';
15
17
  import { createIssue, fetchOpenIssues, fetchOpenIssuesByRepo, fetchProductBasics, fetchRepositoryBasics, } from '../find-shared/mcp.js';
18
+ import { resolveStackRulePacks } from '../find-shared/rule-config.js';
16
19
  import { createPromptGenerator, extractTextFromContent, tryExtractResult, } from '../pr-shared/agent-utils.js';
17
20
  import { createFindSmellsSystemPrompt, createFindSmellsUserPrompt, } from './prompts.js';
18
21
  import { acquireFindSmellsLock, loadFindSmellsState, updateFindSmellsState, } from './state.js';
@@ -35,9 +38,7 @@ export async function scanForSmells(options) {
35
38
  // State/lock/workspace are keyed by an opaque scope id so product and repo
36
39
  // scans never collide; repo keys are prefixed to namespace them clearly.
37
40
  const scopeId = productId ?? `repo-${repoId}`;
38
- const scopeLabel = productId
39
- ? `product ${productId}`
40
- : `repository ${repoId}`;
41
+ const scopeLabel = productId ? `product ${productId}` : `repository ${repoId}`;
41
42
  logInfo(`Starting smell scan for ${scopeLabel} (${owner}/${repo})`);
42
43
  const lock = acquireFindSmellsLock(scopeId);
43
44
  if (!lock) {
@@ -61,7 +62,7 @@ export async function scanForSmells(options) {
61
62
  syncRepoToRef(repoPath, { branch }, githubToken);
62
63
  const headSha = gitRevParse(repoPath, 'HEAD');
63
64
  const state = loadFindSmellsState(scopeId);
64
- const baseSha = full ? undefined : state.lastScannedCommitSha;
65
+ const baseSha = await resolveScanBase({ productId, repoId }, { full, lastScannedSha: state.lastScannedCommitSha });
65
66
  let scope = 'full';
66
67
  let changedPaths;
67
68
  if (baseSha && baseSha !== headSha) {
@@ -116,7 +117,12 @@ export async function scanForSmells(options) {
116
117
  ? await fetchOpenIssues(productId)
117
118
  : await fetchOpenIssuesByRepo(repoId);
118
119
  logInfo(`Loaded ${existingIssues.length} existing issues for dedup context`);
119
- const systemPrompt = createFindSmellsSystemPrompt();
120
+ const rulePacks = await resolveStackRulePacks(repoPath, {
121
+ productId,
122
+ repoId,
123
+ });
124
+ const customRules = await resolveCustomRules({ productId, repoId }, 'smells');
125
+ const systemPrompt = createFindSmellsSystemPrompt(rulePacks, customRules);
120
126
  const userPrompt = createFindSmellsUserPrompt({
121
127
  productName: product.name,
122
128
  productDescription: product.description,
@@ -250,6 +256,7 @@ async function createIssueForSmell(scope, smell) {
250
256
  repoId: scope.repoId,
251
257
  title: smell.title,
252
258
  description: formatIssueDescription(smell),
259
+ source: 'quality',
253
260
  });
254
261
  }
255
262
  /**
@@ -9,7 +9,8 @@
9
9
  * - find-smells (this phase) handles "the code would be better if changed":
10
10
  * refactor candidates, dead code, perf cliffs, type-safety gaps, etc.
11
11
  */
12
- export declare function createFindSmellsSystemPrompt(): string;
12
+ import { type RulePack } from '../find-shared/rule-packs.js';
13
+ export declare function createFindSmellsSystemPrompt(packs?: RulePack[], customRules?: string): string;
13
14
  export interface FindSmellsUserPromptParams {
14
15
  productName: string;
15
16
  productDescription?: string;
@@ -9,7 +9,8 @@
9
9
  * - find-smells (this phase) handles "the code would be better if changed":
10
10
  * refactor candidates, dead code, perf cliffs, type-safety gaps, etc.
11
11
  */
12
- export function createFindSmellsSystemPrompt() {
12
+ import { renderRulePacks } from '../find-shared/rule-packs.js';
13
+ export function createFindSmellsSystemPrompt(packs = [], customRules = '') {
13
14
  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
 
15
16
  **What counts as a smell worth filing**:
@@ -18,9 +19,9 @@ export function createFindSmellsSystemPrompt() {
18
19
  3. **Duplication**: copy-pasted blocks that should be a single helper
19
20
  4. **Complexity**: functions / files that are too long or too deeply nested to reason about, cyclomatic-complexity hotspots
20
21
  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
+ 6. **Type safety**: defeated or bypassed type checks — unsafe casts, suppressed type errors, missing null/undefined checks at trust boundaries, loose types that should be tightened (language-specific instances are listed under "Stack-specific checks" when applicable)
22
23
  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
+ 8. **Architecture**: cyclic deps, layering violations, modules that have grown into multiple responsibilities${renderRulePacks(packs, 'smells')}${customRules}
24
25
 
25
26
  **What does NOT count** (skip these — wrong tool):
26
27
  - 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.**
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Quality gate evaluation for the CLI.
3
+ *
4
+ * Lets `edsger quality-benchmark --gate` enforce a per-scope pass/fail
5
+ * threshold against the report it just produced — the "fail the build" gate
6
+ * NDepend/DCM-style tools expose, usable directly in a user's own CI without
7
+ * any webhook. The gate (overall-score floor, critical-finding cap, per-
8
+ * dimension minimums) is stored in `quality_gates`, mirroring the desktop
9
+ * evaluator in desktop-app/.../services/db/quality-gate.ts.
10
+ *
11
+ * The evaluator is pure + exported for testing; the read is RLS-scoped via the
12
+ * user's supabase session and never throws (a missing gate = nothing to
13
+ * enforce).
14
+ */
15
+ import type { ScanScope } from '../find-shared/baseline.js';
16
+ import type { Dimension, QualityReportPayload } from './types.js';
17
+ export interface QualityGate {
18
+ enabled: boolean;
19
+ /** Minimum overall score (0–100); null = unconstrained. */
20
+ min_overall_score: number | null;
21
+ /** Maximum critical-severity findings allowed; null = unconstrained. */
22
+ max_critical_findings: number | null;
23
+ /** Per-dimension minimum scores; absent dimensions are unconstrained. */
24
+ min_dimension_scores: Partial<Record<Dimension, number>>;
25
+ }
26
+ export interface GateViolation {
27
+ /** Axis that failed, e.g. "Overall score" or "security". */
28
+ label: string;
29
+ /** The threshold that was required. */
30
+ required: string;
31
+ /** The actual value from the report. */
32
+ actual: string;
33
+ }
34
+ export interface GateResult {
35
+ passed: boolean;
36
+ violations: GateViolation[];
37
+ }
38
+ /** Count critical-severity findings across every dimension's evidence. */
39
+ export declare function countCriticalFindings(report: QualityReportPayload): number;
40
+ /**
41
+ * Evaluate a report against a gate, returning every violated axis. A disabled
42
+ * gate passes vacuously. A report with no overall score is not failed on the
43
+ * overall-score axis (there is nothing to compare). Pure + exported for tests.
44
+ */
45
+ export declare function evaluateGate(report: QualityReportPayload, gate: QualityGate): GateResult;
46
+ /**
47
+ * Fetch the gate configured for a scope, or null if none is set / no session.
48
+ * Never throws — a read failure degrades to "no gate" (nothing enforced).
49
+ */
50
+ export declare function getQualityGate(scope: ScanScope): Promise<QualityGate | null>;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Quality gate evaluation for the CLI.
3
+ *
4
+ * Lets `edsger quality-benchmark --gate` enforce a per-scope pass/fail
5
+ * threshold against the report it just produced — the "fail the build" gate
6
+ * NDepend/DCM-style tools expose, usable directly in a user's own CI without
7
+ * any webhook. The gate (overall-score floor, critical-finding cap, per-
8
+ * dimension minimums) is stored in `quality_gates`, mirroring the desktop
9
+ * evaluator in desktop-app/.../services/db/quality-gate.ts.
10
+ *
11
+ * The evaluator is pure + exported for testing; the read is RLS-scoped via the
12
+ * user's supabase session and never throws (a missing gate = nothing to
13
+ * enforce).
14
+ */
15
+ import { readScopedRow } from '../find-shared/scoped-read.js';
16
+ /** Count critical-severity findings across every dimension's evidence. */
17
+ export function countCriticalFindings(report) {
18
+ let count = 0;
19
+ for (const dim of Object.values(report.dimension_scores ?? {})) {
20
+ for (const ev of dim?.evidence ?? []) {
21
+ if (ev.severity === 'critical') {
22
+ count++;
23
+ }
24
+ }
25
+ }
26
+ return count;
27
+ }
28
+ /**
29
+ * Evaluate a report against a gate, returning every violated axis. A disabled
30
+ * gate passes vacuously. A report with no overall score is not failed on the
31
+ * overall-score axis (there is nothing to compare). Pure + exported for tests.
32
+ */
33
+ export function evaluateGate(report, gate) {
34
+ const violations = [];
35
+ if (!gate.enabled) {
36
+ return { passed: true, violations };
37
+ }
38
+ if (gate.min_overall_score !== null &&
39
+ report.overall_score !== null &&
40
+ report.overall_score < gate.min_overall_score) {
41
+ violations.push({
42
+ label: 'Overall score',
43
+ required: `>= ${gate.min_overall_score}`,
44
+ actual: report.overall_score.toFixed(1),
45
+ });
46
+ }
47
+ if (gate.max_critical_findings !== null) {
48
+ const critical = countCriticalFindings(report);
49
+ if (critical > gate.max_critical_findings) {
50
+ violations.push({
51
+ label: 'Critical findings',
52
+ required: `<= ${gate.max_critical_findings}`,
53
+ actual: String(critical),
54
+ });
55
+ }
56
+ }
57
+ for (const [dim, min] of Object.entries(gate.min_dimension_scores)) {
58
+ if (min === null || min === undefined) {
59
+ continue;
60
+ }
61
+ const entry = report.dimension_scores?.[dim];
62
+ // A null/N-A dimension score isn't measurable against a floor — skip it.
63
+ if (entry?.score === null || entry?.score === undefined) {
64
+ continue;
65
+ }
66
+ if (entry.score < min) {
67
+ violations.push({
68
+ label: dim,
69
+ required: `>= ${min}`,
70
+ actual: entry.score.toFixed(0),
71
+ });
72
+ }
73
+ }
74
+ return { passed: violations.length === 0, violations };
75
+ }
76
+ /**
77
+ * Fetch the gate configured for a scope, or null if none is set / no session.
78
+ * Never throws — a read failure degrades to "no gate" (nothing enforced).
79
+ */
80
+ export async function getQualityGate(scope) {
81
+ const row = await readScopedRow('quality_gates', 'enabled, min_overall_score, max_critical_findings, min_dimension_scores', scope);
82
+ if (!row) {
83
+ return null;
84
+ }
85
+ return {
86
+ enabled: row.enabled ?? true,
87
+ min_overall_score: row.min_overall_score ?? null,
88
+ max_critical_findings: row.max_critical_findings ?? null,
89
+ min_dimension_scores: row.min_dimension_scores ?? {},
90
+ };
91
+ }
@@ -151,7 +151,7 @@ export async function runQualityBenchmark(opts) {
151
151
  ...state.unavailable_tools,
152
152
  ...(report.unavailable_tools ?? []),
153
153
  ]),
154
- tool_outputs: { ...state.tool_outputs, ...(report.tool_outputs ?? {}) },
154
+ tool_outputs: enrichToolOutputsWithMetrics({ ...state.tool_outputs, ...(report.tool_outputs ?? {}) }, state.parsed_summaries),
155
155
  dropped_findings: Math.max(state.dropped_findings, report.dropped_findings ?? 0),
156
156
  };
157
157
  const completedAt = new Date().toISOString();
@@ -180,6 +180,20 @@ function readGitHead(repoRoot) {
180
180
  }
181
181
  return res.stdout.trim() || null;
182
182
  }
183
+ /**
184
+ * Fold tier-3 (`metrics`) parser output into the persisted tool_outputs so
185
+ * trend charts can read numeric values (duplication %, complexity, …) without
186
+ * re-parsing oneliners. Count/finding tools carry no metrics and are untouched.
187
+ */
188
+ function enrichToolOutputsWithMetrics(toolOutputs, parsedSummaries) {
189
+ const out = { ...toolOutputs };
190
+ for (const [id, parsed] of Object.entries(parsedSummaries)) {
191
+ if (parsed.summary.tier === 'metrics' && out[id]) {
192
+ out[id] = { ...out[id], metrics: parsed.summary.metrics };
193
+ }
194
+ }
195
+ return out;
196
+ }
183
197
  function dedupUnavailable(list) {
184
198
  const seen = new Set();
185
199
  const out = [];
@@ -17,6 +17,29 @@
17
17
  * - Stable: same input → same output (no randomness, no clocks).
18
18
  */
19
19
  import type { ParsedToolOutput, ParserContext, ParserFn } from './types.js';
20
+ interface DepGraphNode {
21
+ id: string;
22
+ label: string;
23
+ fan_in: number;
24
+ fan_out: number;
25
+ in_cycle: boolean;
26
+ }
27
+ interface DepGraph {
28
+ nodes: DepGraphNode[];
29
+ edges: {
30
+ from: string;
31
+ to: string;
32
+ }[];
33
+ total_modules: number;
34
+ truncated: boolean;
35
+ }
36
+ /**
37
+ * Build a bounded dependency graph from madge's adjacency map. Cycle nodes are
38
+ * always kept; the remaining slots go to the highest-degree modules. Edges are
39
+ * restricted to kept nodes.
40
+ */
41
+ export declare function buildDependencyGraph(adjObj: Record<string, string[]>): DepGraph;
20
42
  export declare const PARSERS: Record<string, ParserFn>;
21
43
  /** Run the parser for a tool, defensively swallowing errors. */
22
44
  export declare function parseToolOutput(toolId: string, stdout: string, stderr: string, ctx: ParserContext): ParsedToolOutput;
45
+ export {};