@boyingliu01/xp-gate 0.8.8 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/xp-gate.js +18 -0
- package/hooks/pre-commit +565 -120
- package/lib/arch.js +49 -0
- package/lib/check.js +50 -0
- package/lib/init.js +36 -0
- package/lib/principles.js +48 -0
- package/mock-policy/AGENTS.md +94 -0
- package/mock-policy/__tests__/config.test.ts +292 -0
- package/mock-policy/__tests__/integration.test.ts +600 -0
- package/mock-policy/__tests__/mock-decision-engine.test.ts +231 -0
- package/mock-policy/__tests__/scope-scanner.test.ts +535 -0
- package/mock-policy/config.ts +106 -0
- package/mock-policy/gate-m3.ts +233 -0
- package/mock-policy/mock-decision-engine.ts +155 -0
- package/mock-policy/schema.ts +22 -0
- package/mock-policy/scope-scanner.ts +288 -0
- package/mock-policy/types.ts +65 -0
- package/mutation/AGENTS.md +73 -0
- package/mutation/__tests__/detect-ai-test.test.ts +152 -0
- package/mutation/__tests__/gate-m.test.ts +194 -0
- package/mutation/detect-ai-test.ts +128 -0
- package/mutation/gate-m.ts +619 -0
- package/mutation/init-baseline.ts +192 -0
- package/mutation/stryker-types.ts +14 -0
- package/mutation/types.ts +70 -0
- package/mutation/update-baseline.ts +160 -0
- package/package.json +5 -2
- package/plugins/claude-code/.claude-plugin/plugin.json +2 -2
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +7 -7
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +1 -1
- package/plugins/claude-code/skills/delphi-review/SKILL.md +12 -12
- package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +83 -36
- package/plugins/claude-code/skills/sprint-flow/SKILL.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/force-levels.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/references/phase-3-review.md +2 -2
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +3 -3
- package/plugins/opencode/README.md +23 -7
- package/plugins/opencode/index.ts +36 -21
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +7 -7
- package/plugins/opencode/skills/delphi-review/INSTALL.md +1 -1
- package/plugins/opencode/skills/delphi-review/SKILL.md +12 -12
- package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +83 -36
- package/plugins/opencode/skills/sprint-flow/SKILL.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/force-levels.md +1 -1
- package/plugins/opencode/skills/sprint-flow/references/phase-3-review.md +2 -2
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +3 -3
- package/plugins/qoder/plugin.json +20 -0
- package/plugins/qoder/skills/delphi-review/AGENTS.md +7 -7
- package/plugins/qoder/skills/delphi-review/INSTALL.md +1 -1
- package/plugins/qoder/skills/delphi-review/SKILL.md +12 -12
- package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +83 -36
- package/plugins/qoder/skills/sprint-flow/SKILL.md +51 -1
- package/plugins/qoder/skills/sprint-flow/references/force-levels.md +1 -1
- package/plugins/qoder/skills/sprint-flow/references/phase-3-review.md +2 -2
- package/plugins/qoder/skills/test-driven-development/SKILL.md +371 -0
- package/plugins/qoder/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +3 -3
- package/principles/AGENTS.md +111 -0
- package/principles/__tests__/analyzer.test.ts +343 -0
- package/principles/__tests__/baseline-storage.test.ts +187 -0
- package/principles/__tests__/baseline.test.ts +328 -0
- package/principles/__tests__/boy-scout-integration.test.ts +264 -0
- package/principles/__tests__/boy-scout.test.ts +646 -0
- package/principles/__tests__/config.test.ts +78 -0
- package/principles/__tests__/index.test.ts +81 -0
- package/principles/__tests__/lint-baseline.test.ts +314 -0
- package/principles/__tests__/reporter.test.ts +832 -0
- package/principles/__tests__/types.test.ts +101 -0
- package/principles/adapters/__tests__/base.test.ts +95 -0
- package/principles/adapters/__tests__/cpp.test.ts +290 -0
- package/principles/adapters/__tests__/dart.test.ts +84 -0
- package/principles/adapters/__tests__/go.test.ts +68 -0
- package/principles/adapters/__tests__/java.test.ts +68 -0
- package/principles/adapters/__tests__/kotlin.test.ts +76 -0
- package/principles/adapters/__tests__/objectivec.test.ts +453 -0
- package/principles/adapters/__tests__/python.test.ts +84 -0
- package/principles/adapters/__tests__/swift.test.ts +68 -0
- package/principles/adapters/__tests__/typescript.test.ts +116 -0
- package/principles/adapters/base.ts +124 -0
- package/principles/adapters/cpp.ts +115 -0
- package/principles/adapters/dart.ts +44 -0
- package/principles/adapters/go.ts +55 -0
- package/principles/adapters/java.ts +56 -0
- package/principles/adapters/kotlin.ts +54 -0
- package/principles/adapters/objectivec.ts +82 -0
- package/principles/adapters/python.ts +83 -0
- package/principles/adapters/swift.ts +40 -0
- package/principles/adapters/typescript.ts +66 -0
- package/principles/analyzer.ts +190 -0
- package/principles/baseline.ts +273 -0
- package/principles/boy-scout.ts +416 -0
- package/principles/config.ts +118 -0
- package/principles/index.ts +87 -0
- package/principles/lint-baseline.ts +385 -0
- package/principles/reporter.ts +188 -0
- package/principles/rules/__tests__/clean-code/code-duplication.test.ts +84 -0
- package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +74 -0
- package/principles/rules/__tests__/clean-code/god-class.test.ts +111 -0
- package/principles/rules/__tests__/clean-code/large-file.test.ts +73 -0
- package/principles/rules/__tests__/clean-code/long-function.test.ts +83 -0
- package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +68 -0
- package/principles/rules/__tests__/clean-code/many-exports.test.ts +118 -0
- package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +173 -0
- package/principles/rules/__tests__/clean-code/too-many-params.test.ts +60 -0
- package/principles/rules/__tests__/clean-code/unused-imports.test.ts +107 -0
- package/principles/rules/__tests__/index.test.ts +49 -0
- package/principles/rules/__tests__/solid/dip.test.ts +121 -0
- package/principles/rules/__tests__/solid/isp.test.ts +60 -0
- package/principles/rules/__tests__/solid/lsp.test.ts +184 -0
- package/principles/rules/__tests__/solid/ocp.test.ts +69 -0
- package/principles/rules/__tests__/solid/srp.test.ts +89 -0
- package/principles/rules/clean-code/code-duplication.ts +31 -0
- package/principles/rules/clean-code/deep-nesting.ts +38 -0
- package/principles/rules/clean-code/god-class.ts +54 -0
- package/principles/rules/clean-code/large-file.ts +34 -0
- package/principles/rules/clean-code/long-function.ts +47 -0
- package/principles/rules/clean-code/magic-numbers.ts +59 -0
- package/principles/rules/clean-code/many-exports.ts +40 -0
- package/principles/rules/clean-code/missing-error-handling.ts +33 -0
- package/principles/rules/clean-code/too-many-params.ts +35 -0
- package/principles/rules/clean-code/unused-imports.ts +33 -0
- package/principles/rules/index.ts +61 -0
- package/principles/rules/solid/dip.ts +47 -0
- package/principles/rules/solid/isp.ts +37 -0
- package/principles/rules/solid/lsp.ts +79 -0
- package/principles/rules/solid/ocp.ts +40 -0
- package/principles/rules/solid/srp.ts +44 -0
- package/principles/types.ts +27 -0
- package/skills/delphi-review/AGENTS.md +7 -7
- package/skills/delphi-review/INSTALL.md +1 -1
- package/skills/delphi-review/SKILL.md +12 -12
- package/skills/delphi-review/references/code-walkthrough.md +1 -1
- package/skills/sprint-flow/AGENTS.md +83 -36
- package/skills/sprint-flow/SKILL.md +1 -1
- package/skills/sprint-flow/references/force-levels.md +1 -1
- package/skills/sprint-flow/references/phase-3-review.md +2 -2
- package/skills/test-specification-alignment/AGENTS.md +3 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Rule, Violation, Severity } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
|
|
6
|
+
export const tooManyParamsRule: Rule = {
|
|
7
|
+
id: 'clean-code.too-many-params',
|
|
8
|
+
name: 'Too Many Parameters Rule',
|
|
9
|
+
threshold: config.rules['clean-code']['too-many-params'].threshold ?? 7,
|
|
10
|
+
severity: config.rules['clean-code']['too-many-params'].severity as Severity,
|
|
11
|
+
check: (file: string, adapter: unknown): Violation[] => {
|
|
12
|
+
const violations: Violation[] = [];
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const typedAdapter = adapter as { extractFunctions?: () => Array<{name?: string; startLine?: number; line?: number; paramCount?: number;}> | undefined };
|
|
16
|
+
const functions = typedAdapter.extractFunctions?.() || [];
|
|
17
|
+
|
|
18
|
+
for (const func of functions) {
|
|
19
|
+
if (func.paramCount && func.paramCount > (config.rules['clean-code']['too-many-params'].threshold as number)) {
|
|
20
|
+
violations.push({
|
|
21
|
+
file,
|
|
22
|
+
line: func.startLine ?? func.line ?? 1,
|
|
23
|
+
ruleId: 'clean-code.too-many-params',
|
|
24
|
+
message: `Function "${func.name}" has too many parameters: ${func.paramCount} (maximum: ${
|
|
25
|
+
config.rules['clean-code']['too-many-params'].threshold
|
|
26
|
+
})`,
|
|
27
|
+
severity: config.rules['clean-code']['too-many-params'].severity as Severity
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} catch { }
|
|
32
|
+
|
|
33
|
+
return violations;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Rule, Violation, Severity } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
|
|
6
|
+
export const unusedImportsRule: Rule = {
|
|
7
|
+
id: 'clean-code.unused-imports',
|
|
8
|
+
name: 'Unused Imports Rule',
|
|
9
|
+
threshold: 1,
|
|
10
|
+
severity: config.rules['clean-code']['unused-imports'].severity as Severity,
|
|
11
|
+
check: (file: string, adapter: unknown): Violation[] => {
|
|
12
|
+
const violations: Violation[] = [];
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const typedAdapter = adapter as { imports?: Array<{name?: string; line?: number; used?: boolean; type?: string;}> | undefined };
|
|
16
|
+
const imports = typedAdapter.imports || [];
|
|
17
|
+
|
|
18
|
+
for (const imp of imports) {
|
|
19
|
+
if (!imp.used && imp.type !== 'type') {
|
|
20
|
+
violations.push({
|
|
21
|
+
file,
|
|
22
|
+
line: imp.line ?? 1,
|
|
23
|
+
ruleId: 'clean-code.unused-imports',
|
|
24
|
+
message: `Unused import "${imp.name}" - consider removing`,
|
|
25
|
+
severity: config.rules['clean-code']['unused-imports'].severity as Severity
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch { }
|
|
30
|
+
|
|
31
|
+
return violations;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Rule } from '../types';
|
|
2
|
+
import { longFunctionRule } from './clean-code/long-function';
|
|
3
|
+
import { largeFileRule } from './clean-code/large-file';
|
|
4
|
+
import { magicNumbersRule } from './clean-code/magic-numbers';
|
|
5
|
+
import { godClassRule } from './clean-code/god-class';
|
|
6
|
+
import { deepNestingRule } from './clean-code/deep-nesting';
|
|
7
|
+
import { tooManyParamsRule } from './clean-code/too-many-params';
|
|
8
|
+
import { missingErrorHandlingRule } from './clean-code/missing-error-handling';
|
|
9
|
+
import { unusedImportsRule } from './clean-code/unused-imports';
|
|
10
|
+
import { codeDuplicationRule } from './clean-code/code-duplication';
|
|
11
|
+
import { manyExportsRule } from './clean-code/many-exports';
|
|
12
|
+
import { srpRule } from './solid/srp';
|
|
13
|
+
import { ocpRule } from './solid/ocp';
|
|
14
|
+
import { lspRule } from './solid/lsp';
|
|
15
|
+
import { ispRule } from './solid/isp';
|
|
16
|
+
import { dipRule } from './solid/dip';
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
longFunctionRule,
|
|
20
|
+
largeFileRule,
|
|
21
|
+
magicNumbersRule,
|
|
22
|
+
godClassRule,
|
|
23
|
+
deepNestingRule,
|
|
24
|
+
tooManyParamsRule,
|
|
25
|
+
missingErrorHandlingRule,
|
|
26
|
+
unusedImportsRule,
|
|
27
|
+
codeDuplicationRule,
|
|
28
|
+
manyExportsRule,
|
|
29
|
+
srpRule,
|
|
30
|
+
ocpRule,
|
|
31
|
+
lspRule,
|
|
32
|
+
ispRule,
|
|
33
|
+
dipRule,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const CLEAN_CODE_RULES: Rule[] = [
|
|
37
|
+
longFunctionRule,
|
|
38
|
+
largeFileRule,
|
|
39
|
+
magicNumbersRule,
|
|
40
|
+
godClassRule,
|
|
41
|
+
deepNestingRule,
|
|
42
|
+
tooManyParamsRule,
|
|
43
|
+
missingErrorHandlingRule,
|
|
44
|
+
unusedImportsRule,
|
|
45
|
+
codeDuplicationRule,
|
|
46
|
+
manyExportsRule,
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const SOLID_RULES: Rule[] = [srpRule, ocpRule, lspRule, ispRule, dipRule];
|
|
50
|
+
|
|
51
|
+
export function getAllPrincipleRules(): Rule[] {
|
|
52
|
+
return [...CLEAN_CODE_RULES, ...SOLID_RULES];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getCleanCodeRules(): Rule[] {
|
|
56
|
+
return [...CLEAN_CODE_RULES];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getSolidRules(): Rule[] {
|
|
60
|
+
return [...SOLID_RULES];
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Rule, Violation } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
const { severity } = config.rules['solid']['dip'];
|
|
6
|
+
const EXCLUDED_CLASSES = config.rules['solid']['dip'].exclude || [
|
|
7
|
+
'Date', 'Map', 'Set', 'Error', 'Array', 'Object', 'Promise'
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
function shouldSkipInstantiation(className: string): boolean {
|
|
11
|
+
if (EXCLUDED_CLASSES.includes(className)) return true;
|
|
12
|
+
if (className.endsWith('Factory') || className.endsWith('Builder')) return true;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const dipRule: Rule = {
|
|
17
|
+
id: 'solid.dip',
|
|
18
|
+
name: 'Dependency Inversion Principle Rule',
|
|
19
|
+
threshold: 0,
|
|
20
|
+
severity: severity as 'error' | 'warning' | 'info',
|
|
21
|
+
check: (file: string, adapter: import('../../types').Adapter): Violation[] => {
|
|
22
|
+
const violations: Violation[] = [];
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
for (const cls_any of adapter.extractClasses() || []) {
|
|
26
|
+
const cls = cls_any as {code?: string; line?: number};
|
|
27
|
+
const code = cls.code;
|
|
28
|
+
if (!code) continue;
|
|
29
|
+
|
|
30
|
+
const newMatches = code.match(/new\s+(\w+)\s*\(/g) || [];
|
|
31
|
+
for (const match of newMatches) {
|
|
32
|
+
const className = match.replace(/new\s+/, '').replace(/\s*\(/, '');
|
|
33
|
+
if (shouldSkipInstantiation(className)) continue;
|
|
34
|
+
|
|
35
|
+
violations.push({
|
|
36
|
+
file,
|
|
37
|
+
line: cls.line || 0,
|
|
38
|
+
ruleId: 'solid.dip',
|
|
39
|
+
severity: severity as 'error' | 'warning' | 'info',
|
|
40
|
+
message: `Direct instantiation detected: new ${className}(). Prefer dependency injection for flexibility.`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch { }
|
|
45
|
+
return violations;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Rule, Violation } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
|
|
6
|
+
export const ispRule: Rule = {
|
|
7
|
+
id: 'solid.isp',
|
|
8
|
+
name: 'Interface Segregation Principle Rule',
|
|
9
|
+
threshold: config.rules['solid']['isp'].methodThreshold ?? 10,
|
|
10
|
+
severity: config.rules['solid']['isp'].severity as 'error' | 'warning' | 'info',
|
|
11
|
+
check: (file: string, adapter: import('../../types').Adapter): Violation[] => {
|
|
12
|
+
const violations: Violation[] = [];
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const typedAdapter = adapter as { extractInterfaces?: () => Array<{name?: string; line?: number; methodCount?: number;}> | undefined };
|
|
16
|
+
const interfaces = typedAdapter.extractInterfaces?.() || [];
|
|
17
|
+
|
|
18
|
+
for (const iface of interfaces) {
|
|
19
|
+
const methodCount = iface.methodCount || 0;
|
|
20
|
+
|
|
21
|
+
if (methodCount > (config.rules['solid']['isp'].methodThreshold as number)) {
|
|
22
|
+
violations.push({
|
|
23
|
+
file,
|
|
24
|
+
line: iface.line ?? 1,
|
|
25
|
+
ruleId: 'solid.isp',
|
|
26
|
+
message: `Interface "${iface.name}" has too many methods: ${methodCount} (maximum: ${
|
|
27
|
+
config.rules['solid']['isp'].methodThreshold
|
|
28
|
+
}). Consider splitting into focused interfaces.`,
|
|
29
|
+
severity: config.rules['solid']['isp'].severity as "error" | "warning" | "info"
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch { }
|
|
34
|
+
|
|
35
|
+
return violations;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Rule, Violation, Adapter } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
const severity = config.rules['solid']['lsp'].severity as 'error' | 'warning' | 'info';
|
|
6
|
+
const PRIMITIVE_TYPES = new Set([
|
|
7
|
+
'string', 'number', 'boolean', 'any', 'void', 'null', 'undefined', 'Object', 'Array',
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
interface ClassInfo {
|
|
11
|
+
code?: string;
|
|
12
|
+
line?: number;
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function extractParamType(param: string): string | null {
|
|
17
|
+
if (!param.includes(':')) return null;
|
|
18
|
+
const typeMatch = param.match(/:\s*(\w+)/);
|
|
19
|
+
return typeMatch ? typeMatch[1] : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isCompatibleParamType(paramType: string, className: string | undefined): boolean {
|
|
23
|
+
if (PRIMITIVE_TYPES.has(paramType)) return true;
|
|
24
|
+
if (className && paramType.startsWith(className)) return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function collectMethodParamTypes(methodSignature: string): string[] {
|
|
29
|
+
const paramsMatch = methodSignature.match(/\(([^)]+)\)/);
|
|
30
|
+
if (!paramsMatch) return [];
|
|
31
|
+
const types: string[] = [];
|
|
32
|
+
for (const param of paramsMatch[1].split(',').map((p) => p.trim())) {
|
|
33
|
+
const paramType = extractParamType(param);
|
|
34
|
+
if (paramType) types.push(paramType);
|
|
35
|
+
}
|
|
36
|
+
return types;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function buildViolation(file: string, cls: ClassInfo, paramType: string): Violation {
|
|
40
|
+
return {
|
|
41
|
+
file,
|
|
42
|
+
line: cls.line ?? 0,
|
|
43
|
+
ruleId: 'solid.lsp',
|
|
44
|
+
message: `Possible LSP violation in "${cls.name}". Parameter type "${paramType}" may not be compatible with base class contract.`,
|
|
45
|
+
severity,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function checkClass(file: string, cls: ClassInfo): Violation[] {
|
|
50
|
+
if (!cls.code || !cls.code.includes('extends')) return [];
|
|
51
|
+
|
|
52
|
+
const violations: Violation[] = [];
|
|
53
|
+
const methodSignatures = cls.code.match(/\w+\s*\(([^)]+)\)/g) || [];
|
|
54
|
+
|
|
55
|
+
for (const methodSignature of methodSignatures) {
|
|
56
|
+
for (const paramType of collectMethodParamTypes(methodSignature)) {
|
|
57
|
+
if (!isCompatibleParamType(paramType, cls.name)) {
|
|
58
|
+
violations.push(buildViolation(file, cls, paramType));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return violations;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const lspRule: Rule = {
|
|
67
|
+
id: 'solid.lsp',
|
|
68
|
+
name: 'Liskov Substitution Principle Rule',
|
|
69
|
+
threshold: 0,
|
|
70
|
+
severity,
|
|
71
|
+
check: (file: string, adapter: Adapter): Violation[] => {
|
|
72
|
+
try {
|
|
73
|
+
const classes = (adapter.extractClasses() || []) as ClassInfo[];
|
|
74
|
+
return classes.flatMap((cls) => checkClass(file, cls));
|
|
75
|
+
} catch {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Rule, Violation } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
|
|
6
|
+
export const ocpRule: Rule = {
|
|
7
|
+
id: 'solid.ocp',
|
|
8
|
+
name: 'Open/Closed Principle Rule',
|
|
9
|
+
threshold: 0,
|
|
10
|
+
severity: config.rules['solid']['ocp'].severity as "error" | "warning" | "info",
|
|
11
|
+
check: (file: string, adapter: import('../../types').Adapter): Violation[] => {
|
|
12
|
+
const violations: Violation[] = [];
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const classes = adapter.extractClasses() || [];
|
|
16
|
+
|
|
17
|
+
for (const raw of classes) {
|
|
18
|
+
const cls = raw as { code?: string; line?: number; name?: string };
|
|
19
|
+
if (!cls.code) continue;
|
|
20
|
+
|
|
21
|
+
const extendsMatch = cls.code.match(/extends\s+(\w+)/);
|
|
22
|
+
if (extendsMatch) {
|
|
23
|
+
const baseClass = extendsMatch[1];
|
|
24
|
+
|
|
25
|
+
if (cls.code.includes(`class ${baseClass}`)) {
|
|
26
|
+
violations.push({
|
|
27
|
+
file,
|
|
28
|
+
line: cls.line ?? 1,
|
|
29
|
+
ruleId: 'solid.ocp',
|
|
30
|
+
message: `Possible modification of base class "${baseClass}" while extending. Extension should not require modifying the base.`,
|
|
31
|
+
severity: config.rules['solid']['ocp'].severity as "error" | "warning" | "info"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch { }
|
|
37
|
+
|
|
38
|
+
return violations;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Rule, Violation } from '../../types';
|
|
2
|
+
import { getDefaultConfig } from '../../config';
|
|
3
|
+
|
|
4
|
+
const config = getDefaultConfig();
|
|
5
|
+
const { methodThreshold, severity } = config.rules['solid']['srp'];
|
|
6
|
+
|
|
7
|
+
export const srpRule: Rule = {
|
|
8
|
+
id: 'solid.srp',
|
|
9
|
+
name: 'Single Responsibility Principle Rule',
|
|
10
|
+
threshold: methodThreshold as number,
|
|
11
|
+
severity: severity as "error" | "warning" | "info",
|
|
12
|
+
check: (file: string, adapter: import('../../types').Adapter): Violation[] => {
|
|
13
|
+
const violations: Violation[] = [];
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const classes = adapter.extractClasses() || [];
|
|
17
|
+
const maxMethods = methodThreshold as number;
|
|
18
|
+
const sev = severity as "error" | "warning" | "info";
|
|
19
|
+
|
|
20
|
+
for (const raw of classes) {
|
|
21
|
+
const cls = raw as { code?: string; line?: number; name?: string; methodCount?: number; imports?: Record<string, unknown> };
|
|
22
|
+
const methodCount = cls.methodCount || 0;
|
|
23
|
+
const importCategories = cls.imports ? Object.keys(cls.imports).length : 0;
|
|
24
|
+
const line = cls.line ?? 1;
|
|
25
|
+
|
|
26
|
+
if (methodCount > maxMethods) {
|
|
27
|
+
violations.push({
|
|
28
|
+
file, line, ruleId: 'solid.srp', severity: sev,
|
|
29
|
+
message: `Class "${cls.name}" has too many methods: ${methodCount} (maximum: ${maxMethods}). Consider splitting into focused classes.`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (importCategories > 3) {
|
|
34
|
+
violations.push({
|
|
35
|
+
file, line, ruleId: 'solid.srp', severity: sev,
|
|
36
|
+
message: `Class "${cls.name}" imports from ${importCategories} different domains. Each class should focus on one responsibility.`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch { }
|
|
41
|
+
|
|
42
|
+
return violations;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Severity = 'error' | 'warning' | 'info';
|
|
2
|
+
|
|
3
|
+
export interface Rule {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
threshold: number;
|
|
7
|
+
severity: Severity;
|
|
8
|
+
check: (file: string, adapter: Adapter) => Violation[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Violation {
|
|
12
|
+
file: string;
|
|
13
|
+
line: number;
|
|
14
|
+
column?: number;
|
|
15
|
+
ruleId: string;
|
|
16
|
+
message: string;
|
|
17
|
+
severity: Severity;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Adapter {
|
|
21
|
+
detectLanguage: () => string;
|
|
22
|
+
parseAST: () => unknown;
|
|
23
|
+
extractFunctions: () => unknown[];
|
|
24
|
+
extractClasses: () => unknown[];
|
|
25
|
+
extractExports: () => unknown[];
|
|
26
|
+
countLines: () => number;
|
|
27
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# SKILLS/DELPHI-REVIEW KNOWLEDGE BASE
|
|
2
2
|
|
|
3
|
-
**Generated:** 2026-
|
|
4
|
-
**Commit:**
|
|
3
|
+
**Generated:** 2026-06-14
|
|
4
|
+
**Commit:** e215a50
|
|
5
5
|
**Branch:** main
|
|
6
|
-
**Version:**
|
|
6
|
+
**Version:** 0.8.10.0
|
|
7
7
|
|
|
8
8
|
## OVERVIEW
|
|
9
|
-
Delphi Consensus Review — multi-round anonymous expert review (≥
|
|
9
|
+
Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, 3 experts from ≥2 providers, domestic models only). Supports design + code-walkthrough modes.
|
|
10
10
|
|
|
11
11
|
## STRUCTURE
|
|
12
12
|
```
|
|
@@ -30,7 +30,7 @@ skills/delphi-review/
|
|
|
30
30
|
|
|
31
31
|
## CONVENTIONS
|
|
32
32
|
- 3 experts anonymous in Round 1 (no cross-expert bias)
|
|
33
|
-
- ≥
|
|
33
|
+
- ≥90% consensus threshold (was 95%, now unified to 90%)
|
|
34
34
|
- Max 5 rounds before forcing decision
|
|
35
35
|
- Cross-provider required: experts from ≥2 different providers
|
|
36
36
|
- Domestic models only: glm, kimi, minimax, qwen, deepseek
|
|
@@ -39,7 +39,7 @@ skills/delphi-review/
|
|
|
39
39
|
- Code-walkthrough skipped on main/master pushes (by design)
|
|
40
40
|
|
|
41
41
|
## ANTI-PATTERNS (THIS PROJECT)
|
|
42
|
-
- Do NOT terminate before achieving true consensus (≥
|
|
42
|
+
- Do NOT terminate before achieving true consensus (≥90%)
|
|
43
43
|
- Do NOT reveal other experts' opinions during Round 1
|
|
44
44
|
- Do NOT accept partial agreement without resolution
|
|
45
45
|
- Do NOT skip code-walkthrough when over thresholds (BLOCK + user decision)
|
|
@@ -49,7 +49,7 @@ skills/delphi-review/
|
|
|
49
49
|
|
|
50
50
|
## UNIQUE STYLES
|
|
51
51
|
- Anonymous expert reviews (Round 1)
|
|
52
|
-
- Statistical consensus measurement (≥
|
|
52
|
+
- Statistical consensus measurement (≥90% threshold)
|
|
53
53
|
- Two modes: design review + code-walkthrough
|
|
54
54
|
- Pre-push integration: .code-walkthrough-result.json stores commit hash + verdict
|
|
55
55
|
- Delphi guard in claude-code plugin: blocks Edit/Write before APPROVAL
|
|
@@ -96,7 +96,7 @@ The skill requires at least 2 experts for code changes, 3 for architecture decis
|
|
|
96
96
|
| `experts.architecture` | Architecture reviewer configuration | Required |
|
|
97
97
|
| `experts.technical` | Technical reviewer configuration | Required |
|
|
98
98
|
| `experts.feasibility` | Feasibility reviewer configuration | Required for 3-expert mode |
|
|
99
|
-
| `consensus.threshold_percent` | Agreement threshold |
|
|
99
|
+
| `consensus.threshold_percent` | Agreement threshold | 90 |
|
|
100
100
|
| `consensus.max_review_rounds` | Maximum review rounds | 5 |
|
|
101
101
|
| `consensus.cross_provider_required` | Require different providers | true |
|
|
102
102
|
|
|
@@ -9,7 +9,7 @@ description: "Use when asked to review a design, plan, or architecture; before i
|
|
|
9
9
|
|
|
10
10
|
**In Scope:**
|
|
11
11
|
- Multi-round anonymous expert consensus review (design + code-walkthrough modes)
|
|
12
|
-
- 2-3 experts from different providers with statistical consensus (>=
|
|
12
|
+
- 2-3 experts from different providers with statistical consensus (>= 90%)
|
|
13
13
|
- Structured verdict: APPROVED / PASS_WITH_CAVEATS / REQUEST_CHANGES
|
|
14
14
|
- Domestic models only (no Anthropic/OpenAI/Google)
|
|
15
15
|
|
|
@@ -27,7 +27,7 @@ description: "Use when asked to review a design, plan, or architecture; before i
|
|
|
27
27
|
1. **匿名性** — Round 1 专家互不知道对方意见
|
|
28
28
|
2. **迭代** — 多轮直到共识,不是固定轮数
|
|
29
29
|
3. **受控反馈** — 每轮看到其他专家意见
|
|
30
|
-
4. **统计共识** — >=
|
|
30
|
+
4. **统计共识** — >=90% 一致才算共识
|
|
31
31
|
|
|
32
32
|
### 质量优先
|
|
33
33
|
|
|
@@ -95,7 +95,7 @@ description: "Use when asked to review a design, plan, or architecture; before i
|
|
|
95
95
|
|
|
96
96
|
| 阈值 | 说明 |
|
|
97
97
|
|------|------|
|
|
98
|
-
| **>=
|
|
98
|
+
| **>=90%** | 推荐默认 |
|
|
99
99
|
| 100% | 完全一致(更严格) |
|
|
100
100
|
|
|
101
101
|
---
|
|
@@ -105,14 +105,14 @@ description: "Use when asked to review a design, plan, or architecture; before i
|
|
|
105
105
|
```
|
|
106
106
|
Phase 0: 准备 → Round 1: 匿名独立评审 → 共识检查
|
|
107
107
|
│
|
|
108
|
-
├─ 一致 + >=
|
|
108
|
+
├─ 一致 + >=90% + APPROVED → ✅ 完成
|
|
109
109
|
│
|
|
110
|
-
└─ 不一致 或 <
|
|
110
|
+
└─ 不一致 或 <90% 或 REQUEST_CHANGES
|
|
111
111
|
│
|
|
112
112
|
▼
|
|
113
113
|
Round 2: 交换意见 → 共识检查
|
|
114
114
|
│
|
|
115
|
-
├─ 一致 + >=
|
|
115
|
+
├─ 一致 + >=90% + APPROVED → ✅ 完成
|
|
116
116
|
│
|
|
117
117
|
└─ 仍分歧 或 REQUEST_CHANGES
|
|
118
118
|
│
|
|
@@ -248,11 +248,11 @@ This skill activates on any request for multi-expert review. Common triggers:
|
|
|
248
248
|
2. **Dispatch anonymous experts** - 2-3 experts from ≥2 different domestic model providers
|
|
249
249
|
3. **Collect Round 1 independent reviews** - Anonymous, no cross-expert bias
|
|
250
250
|
4. **Synthesize feedback** - Measure consensus, identify disagreements
|
|
251
|
-
5. **Run Round 2+ until consensus** - Exchange opinions, iterate until ≥
|
|
251
|
+
5. **Run Round 2+ until consensus** - Exchange opinions, iterate until ≥90% agreement
|
|
252
252
|
6. **Block on unresolved Critical/Major** - Zero-tolerance: all Critical/Major must be resolved
|
|
253
253
|
7. **Emit verdict** - APPROVED (with specification.yaml) or REQUEST_CHANGES (fix + re-review)
|
|
254
254
|
|
|
255
|
-
**Consensus threshold:** ≥
|
|
255
|
+
**Consensus threshold:** ≥90% (project standard for Delphi review approval)
|
|
256
256
|
**Model policy:** Domestic models only (DeepSeek, Qwen, Kimi, GLM, MiniMax). Foreign models (Anthropic/OpenAI/Google) forbidden.
|
|
257
257
|
|
|
258
258
|
---
|
|
@@ -340,7 +340,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
|
|
|
340
340
|
- [ ] Round 2+ 完成(交换意见 / 最终立场)
|
|
341
341
|
|
|
342
342
|
**CRITICAL — 共识验证:**
|
|
343
|
-
- [ ] 问题共识比例 >=
|
|
343
|
+
- [ ] 问题共识比例 >=90%
|
|
344
344
|
- [ ] 所有 Critical Issues 已解决
|
|
345
345
|
- [ ] 所有 Major Concerns 已处理
|
|
346
346
|
|
|
@@ -422,7 +422,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
|
|
|
422
422
|
| 只处理 Critical,忽略 Major | 零容忍:Critical/Major 全部必须处理,不可跳过或降级 |
|
|
423
423
|
| 单专家自评 | 至少 2 位不同 provider 的专家 |
|
|
424
424
|
| 用户说"时间紧急"就跳过 | 评审是投资不是开销,跳过后期返工成本更高 |
|
|
425
|
-
| "专家几乎一致"就通过 | "几乎" = 不一致,继续到 >=
|
|
425
|
+
| "专家几乎一致"就通过 | "几乎" = 不一致,继续到 >=90% |
|
|
426
426
|
| 使用 Anthropic/GPT/Gemini 等国外昂贵模型 | 必须使用国产开源模型(DeepSeek, Qwen, Kimi, GLM, MiniMax) |
|
|
427
427
|
| 三个专家使用同一厂家模型 | 必须来自至少 2 家不同厂家 |
|
|
428
428
|
|
|
@@ -437,7 +437,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
|
|
|
437
437
|
| "这只是小变更" | 所有变更都需要评审 |
|
|
438
438
|
| "Round 1 就够了" | 不够,必须多轮直到共识 |
|
|
439
439
|
| "生成报告就完成了" | APPROVED 才算完成 |
|
|
440
|
-
| "2/3 同意就是共识" | 还要检查问题共识比例 >=
|
|
440
|
+
| "2/3 同意就是共识" | 还要检查问题共识比例 >=90% |
|
|
441
441
|
|
|
442
442
|
---
|
|
443
443
|
|
|
@@ -445,7 +445,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
|
|
|
445
445
|
|
|
446
446
|
**Delphi 评审完成的唯一标准:**
|
|
447
447
|
1. ✅ 所有专家裁决 APPROVED
|
|
448
|
-
2. ✅ 问题共识 >=
|
|
448
|
+
2. ✅ 问题共识 >=90%
|
|
449
449
|
3. ✅ 所有 Critical Issues 已修复验证
|
|
450
450
|
4. ✅ 所有 Major Concerns 已处理
|
|
451
451
|
5. ✅ 共识报告已生成
|
|
@@ -393,7 +393,7 @@ IF 任何检查失败:
|
|
|
393
393
|
| `confidence` | number | 整体置信度 (1-10) |
|
|
394
394
|
| `experts` | array | 专家评审结果 |
|
|
395
395
|
| `issues` | array | 未解决的问题(如有) |
|
|
396
|
-
| `consensus_ratio` | number | 问题共识比例 (≥0.
|
|
396
|
+
| `consensus_ratio` | number | 问题共识比例 (≥0.90 为共识) |
|
|
397
397
|
|
|
398
398
|
**有效期机制**:
|
|
399
399
|
|