Purpose & When-To-Use
Trigger conditions:
- Reviewing code quality before merge/commit
- Establishing baseline standards for multi-language codebases
- Training developers on language-agnostic and language-specific best practices
- Automated code review workflows requiring consistent quality gates
Not for:
- Runtime debugging or performance profiling
- Vulnerability scanning (use dedicated security tools)
- Complete rewrite automation (provides suggestions only)
Pre-Checks
Time normalization:
- Compute
NOW_ET using NIST/time.gov semantics (America/New_York, ISO-8601)
- Use
NOW_ET for all citation access dates
Input validation:
code_path must exist and be readable
language must be one of: go, javascript, kotlin, python, rust, shell, swift, typescript, or null (auto-detect)
ruleset must be: "universal", "language-specific", or "both"
severity_threshold must be: "error", "warning", or "info"
Source freshness:
- Style guide links must be accessible (HTTP 200)
- If language-specific rules reference versioned specs, verify version matches target language version
Procedure
T1: Universal Principles (≤2k tokens)
Fast path for common cases:
Language Detection (if not provided)
- Use file extension and shebang analysis
- Fallback to syntax pattern matching
Universal Rules Application
- DRY (Don't Repeat Yourself): Flag duplicate code blocks >5 lines
- SOLID Principles: Detect single-responsibility violations (functions >50 lines)
- Naming Conventions: Check snake_case, camelCase, PascalCase per language norms
- Magic Numbers: Identify hardcoded constants without explanation
- Documentation: Require docstrings/comments for public APIs
Quick Score
- Calculate preliminary score:
100 - (errors×10 + warnings×3 + info×1)
Decision: If ruleset == "universal" → STOP at T1; otherwise proceed to T2.
T2: Language-Specific Rules (≤6k tokens)
Extended validation with style guides:
Route to Language Module (see resources/language-rules.json)
- Python: PEP 8 compliance (line length ≤79, import order, naming) accessed 2025-10-25T21:30:36-04:00
- Go: Effective Go patterns (error handling, receiver names, package comments) accessed 2025-10-25T21:30:36-04:00
- JavaScript/TypeScript: Airbnb style (const/let, arrow functions, template literals) accessed 2025-10-25T21:30:36-04:00
- Kotlin: Official conventions (property declarations, lambda syntax) accessed 2025-10-25T21:30:36-04:00
- Rust: API guidelines (method naming, trait bounds, error types) accessed 2025-10-25T21:30:36-04:00
- Swift: Google Swift style (access control, guard clauses) accessed 2025-10-25T21:30:36-04:00
- Shell: Google Shell guide (quoting, function names, error handling) accessed 2025-10-25T21:30:36-04:00
Automated Fix Generation
- Provide diff-ready patches for mechanical issues (formatting, imports)
- Surface manual-review items for logic/architecture changes
Final Scoring
- Adjust score based on language-specific violations
- Apply severity weights:
critical=15, error=10, warning=3, info=1
- Cap score at 0 (minimum)
T3: Deep Dive (not implemented in v1.0.0)
Reserved for:
- Cross-file dependency analysis
- Architecture pattern validation
- Performance anti-pattern detection
Decision Rules
Language Detection Confidence:
- If confidence <80%, return error requesting explicit
language parameter
Abort Conditions:
code_path not readable → error "File/directory not accessible"
- Unsupported language → error "Language not in supported set"
- Parse failure (syntax errors) → return partial results with "unparseable code" warning
Severity Filtering:
- Only include issues at or above
severity_threshold in final report
- Always compute full score regardless of threshold (for metrics consistency)
Ambiguity Handling:
- Mixed-language directories: analyze per-file, aggregate scores
- Conflicting rules (e.g., line length): prefer language-specific over universal
Output Contract
Schema (JSON):
{
"code_path": "string",
"language": "string",
"score": "integer (0-100)",
"issues": [
{
"file": "string",
"line": "integer",
"column": "integer (optional)",
"severity": "error | warning | info",
"rule": "string (e.g., 'PEP8-E501')",
"message": "string",
"fix": "string (optional, diff or instruction)"
}
],
"metrics": {
"total_lines": "integer",
"error_count": "integer",
"warning_count": "integer",
"info_count": "integer"
},
"timestamp": "ISO-8601 string (NOW_ET)"
}
Required Fields:
code_path, language, score, issues, metrics, timestamp
Fix Suggestions (Markdown):
- Grouped by severity
- Max 5 suggestions per severity level (prioritize high-impact fixes)
- Include code snippets and references to style guides
Examples
Example 1: Python PEP 8 Analysis
INPUT: {code_path: "src/calc.py", language: "python", ruleset: "both"}
T1 (Universal):
- ✗ Function exceeds 50 lines (42-105)
- ✗ Magic number: 86400 (line 57)
- ✗ Missing docstrings: 4 functions
T2 (PEP 8):
- ✗ E501: Line too long (12 instances)
- ✗ N806: Variable 'X' should be lowercase
OUTPUT:
{
"score": 68,
"issues": [{
"line": 57,
"rule": "UNIVERSAL-MAGIC",
"message": "Magic number 86400",
"fix": "SECONDS_PER_DAY = 86400"
}],
"metrics": {"warnings": 17}
}
Quality Gates
Token Budgets:
- T1: ≤2k tokens (language detection + universal rules)
- T2: ≤6k tokens (language-specific analysis + fix generation)
Safety:
- No code execution; static analysis only
- Sandbox file reads (no writes without explicit user consent)
- Redact any accidentally detected secrets before output
Auditability:
- Log all rule applications with source citations
- Include style guide versions in output metadata
- Emit deterministic results (same input → same output)
Performance:
- T1 response time: <2 seconds for files ≤1000 lines
- T2 response time: <5 seconds for files ≤1000 lines
- Fail fast on files >10,000 lines (recommend splitting)
Resources
Language-Specific Rule Mappings:
/resources/language-rules.json - Complete rule ID to description mappings
Official Style Guides (accessed 2025-10-25T21:30:36-04:00):
- Google Style Guides (multi-language)
- Kotlin Coding Conventions
- Effective Go
- PEP 8 – Style Guide for Python Code
- Rust API Guidelines
- Airbnb JavaScript Style Guide
Community Standards:
Tool Integration Guides:
- ESLint, Pylint, golangci-lint, ktlint, Clippy configuration templates in
resources/tool-configs/
1---2name: polyglot-coding-standards-analyzer3description: Evaluate code quality across 8+ languages using language-agnostic principles and language-specific best practices.4license: MIT5---67## Purpose & When-To-Use89**Trigger conditions:**10- Reviewing code quality before merge/commit11- Establishing baseline standards for multi-language codebases12- Training developers on language-agnostic and language-specific best practices13- Automated code review workflows requiring consistent quality gates1415**Not for:**16- Runtime debugging or performance profiling17- Vulnerability scanning (use dedicated security tools)18- Complete rewrite automation (provides suggestions only)1920---2122## Pre-Checks2324**Time normalization:**25- Compute `NOW_ET` using NIST/time.gov semantics (America/New_York, ISO-8601)26- Use `NOW_ET` for all citation access dates2728**Input validation:**29- `code_path` must exist and be readable30- `language` must be one of: go, javascript, kotlin, python, rust, shell, swift, typescript, or null (auto-detect)31- `ruleset` must be: "universal", "language-specific", or "both"32- `severity_threshold` must be: "error", "warning", or "info"3334**Source freshness:**35- Style guide links must be accessible (HTTP 200)36- If language-specific rules reference versioned specs, verify version matches target language version3738---3940## Procedure4142### T1: Universal Principles (≤2k tokens)4344**Fast path for common cases:**45461. **Language Detection** (if not provided)47 - Use file extension and shebang analysis48 - Fallback to syntax pattern matching49502. **Universal Rules Application**51 - **DRY (Don't Repeat Yourself):** Flag duplicate code blocks >5 lines52 - **SOLID Principles:** Detect single-responsibility violations (functions >50 lines)53 - **Naming Conventions:** Check snake_case, camelCase, PascalCase per language norms54 - **Magic Numbers:** Identify hardcoded constants without explanation55 - **Documentation:** Require docstrings/comments for public APIs56573. **Quick Score**58 - Calculate preliminary score: `100 - (errors×10 + warnings×3 + info×1)`5960**Decision:** If `ruleset == "universal"` → STOP at T1; otherwise proceed to T2.6162---6364### T2: Language-Specific Rules (≤6k tokens)6566**Extended validation with style guides:**67681. **Route to Language Module** (see `resources/language-rules.json`)6970 - **Python:** PEP 8 compliance (line length ≤79, import order, naming) [accessed 2025-10-25T21:30:36-04:00](https://peps.python.org/pep-0008/)71 - **Go:** Effective Go patterns (error handling, receiver names, package comments) [accessed 2025-10-25T21:30:36-04:00](https://go.dev/doc/effective_go)72 - **JavaScript/TypeScript:** Airbnb style (const/let, arrow functions, template literals) [accessed 2025-10-25T21:30:36-04:00](https://github.com/airbnb/javascript)73 - **Kotlin:** Official conventions (property declarations, lambda syntax) [accessed 2025-10-25T21:30:36-04:00](https://kotlinlang.org/docs/coding-conventions.html)74 - **Rust:** API guidelines (method naming, trait bounds, error types) [accessed 2025-10-25T21:30:36-04:00](https://rust-lang.github.io/api-guidelines/)75 - **Swift:** Google Swift style (access control, guard clauses) [accessed 2025-10-25T21:30:36-04:00](https://google.github.io/styleguide/swift.html)76 - **Shell:** Google Shell guide (quoting, function names, error handling) [accessed 2025-10-25T21:30:36-04:00](https://google.github.io/styleguide/shellguide.html)77782. **Automated Fix Generation**79 - Provide diff-ready patches for mechanical issues (formatting, imports)80 - Surface manual-review items for logic/architecture changes81823. **Final Scoring**83 - Adjust score based on language-specific violations84 - Apply severity weights: `critical=15, error=10, warning=3, info=1`85 - Cap score at 0 (minimum)8687---8889### T3: Deep Dive (not implemented in v1.0.0)9091Reserved for:92- Cross-file dependency analysis93- Architecture pattern validation94- Performance anti-pattern detection9596---9798## Decision Rules99100**Language Detection Confidence:**101- If confidence <80%, return error requesting explicit `language` parameter102103**Abort Conditions:**104- `code_path` not readable → error "File/directory not accessible"105- Unsupported language → error "Language not in supported set"106- Parse failure (syntax errors) → return partial results with "unparseable code" warning107108**Severity Filtering:**109- Only include issues at or above `severity_threshold` in final report110- Always compute full score regardless of threshold (for metrics consistency)111112**Ambiguity Handling:**113- Mixed-language directories: analyze per-file, aggregate scores114- Conflicting rules (e.g., line length): prefer language-specific over universal115116---117118## Output Contract119120**Schema (JSON):**121122```json123{124 "code_path": "string",125 "language": "string",126 "score": "integer (0-100)",127 "issues": [128 {129 "file": "string",130 "line": "integer",131 "column": "integer (optional)",132 "severity": "error | warning | info",133 "rule": "string (e.g., 'PEP8-E501')",134 "message": "string",135 "fix": "string (optional, diff or instruction)"136 }137 ],138 "metrics": {139 "total_lines": "integer",140 "error_count": "integer",141 "warning_count": "integer",142 "info_count": "integer"143 },144 "timestamp": "ISO-8601 string (NOW_ET)"145}146```147148**Required Fields:**149- `code_path`, `language`, `score`, `issues`, `metrics`, `timestamp`150151**Fix Suggestions (Markdown):**152- Grouped by severity153- Max 5 suggestions per severity level (prioritize high-impact fixes)154- Include code snippets and references to style guides155156---157158## Examples159160**Example 1: Python PEP 8 Analysis**161162```163INPUT: {code_path: "src/calc.py", language: "python", ruleset: "both"}164165T1 (Universal):166- ✗ Function exceeds 50 lines (42-105)167- ✗ Magic number: 86400 (line 57)168- ✗ Missing docstrings: 4 functions169170T2 (PEP 8):171- ✗ E501: Line too long (12 instances)172- ✗ N806: Variable 'X' should be lowercase173174OUTPUT:175{176 "score": 68,177 "issues": [{178 "line": 57,179 "rule": "UNIVERSAL-MAGIC",180 "message": "Magic number 86400",181 "fix": "SECONDS_PER_DAY = 86400"182 }],183 "metrics": {"warnings": 17}184}185```186187---188189## Quality Gates190191**Token Budgets:**192- **T1:** ≤2k tokens (language detection + universal rules)193- **T2:** ≤6k tokens (language-specific analysis + fix generation)194195**Safety:**196- No code execution; static analysis only197- Sandbox file reads (no writes without explicit user consent)198- Redact any accidentally detected secrets before output199200**Auditability:**201- Log all rule applications with source citations202- Include style guide versions in output metadata203- Emit deterministic results (same input → same output)204205**Performance:**206- T1 response time: <2 seconds for files ≤1000 lines207- T2 response time: <5 seconds for files ≤1000 lines208- Fail fast on files >10,000 lines (recommend splitting)209210---211212## Resources213214**Language-Specific Rule Mappings:**215- `/resources/language-rules.json` - Complete rule ID to description mappings216217**Official Style Guides (accessed 2025-10-25T21:30:36-04:00):**2181. [Google Style Guides (multi-language)](https://google.github.io/styleguide/)2192. [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html)2203. [Effective Go](https://go.dev/doc/effective_go)2214. [PEP 8 – Style Guide for Python Code](https://peps.python.org/pep-0008/)2225. [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/)2236. [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)224225**Community Standards:**226- [Swift.org API Design Guidelines](https://swift.org/documentation/api-design-guidelines/)227- [ShellCheck Wiki](https://www.shellcheck.net/wiki/)228229**Tool Integration Guides:**230- ESLint, Pylint, golangci-lint, ktlint, Clippy configuration templates in `resources/tool-configs/`