opencode-metis 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/dist/cli.cjs +63 -0
- package/dist/mcp-server.cjs +51 -0
- package/dist/plugin.cjs +4 -0
- package/dist/worker.cjs +224 -0
- package/opencode/agent/the-analyst/feature-prioritization.md +66 -0
- package/opencode/agent/the-analyst/market-research.md +77 -0
- package/opencode/agent/the-analyst/project-coordination.md +81 -0
- package/opencode/agent/the-analyst/requirements-analysis.md +77 -0
- package/opencode/agent/the-architect/compatibility-review.md +138 -0
- package/opencode/agent/the-architect/complexity-review.md +137 -0
- package/opencode/agent/the-architect/quality-review.md +67 -0
- package/opencode/agent/the-architect/security-review.md +127 -0
- package/opencode/agent/the-architect/system-architecture.md +119 -0
- package/opencode/agent/the-architect/system-documentation.md +83 -0
- package/opencode/agent/the-architect/technology-research.md +85 -0
- package/opencode/agent/the-chief.md +79 -0
- package/opencode/agent/the-designer/accessibility-implementation.md +101 -0
- package/opencode/agent/the-designer/design-foundation.md +74 -0
- package/opencode/agent/the-designer/interaction-architecture.md +75 -0
- package/opencode/agent/the-designer/user-research.md +70 -0
- package/opencode/agent/the-meta-agent.md +155 -0
- package/opencode/agent/the-platform-engineer/ci-cd-pipelines.md +109 -0
- package/opencode/agent/the-platform-engineer/containerization.md +106 -0
- package/opencode/agent/the-platform-engineer/data-architecture.md +81 -0
- package/opencode/agent/the-platform-engineer/dependency-review.md +144 -0
- package/opencode/agent/the-platform-engineer/deployment-automation.md +81 -0
- package/opencode/agent/the-platform-engineer/infrastructure-as-code.md +107 -0
- package/opencode/agent/the-platform-engineer/performance-tuning.md +82 -0
- package/opencode/agent/the-platform-engineer/pipeline-engineering.md +81 -0
- package/opencode/agent/the-platform-engineer/production-monitoring.md +105 -0
- package/opencode/agent/the-qa-engineer/exploratory-testing.md +66 -0
- package/opencode/agent/the-qa-engineer/performance-testing.md +81 -0
- package/opencode/agent/the-qa-engineer/quality-assurance.md +77 -0
- package/opencode/agent/the-qa-engineer/test-execution.md +66 -0
- package/opencode/agent/the-software-engineer/api-development.md +78 -0
- package/opencode/agent/the-software-engineer/component-development.md +79 -0
- package/opencode/agent/the-software-engineer/concurrency-review.md +141 -0
- package/opencode/agent/the-software-engineer/domain-modeling.md +66 -0
- package/opencode/agent/the-software-engineer/performance-optimization.md +113 -0
- package/opencode/command/analyze.md +149 -0
- package/opencode/command/constitution.md +178 -0
- package/opencode/command/debug.md +194 -0
- package/opencode/command/document.md +178 -0
- package/opencode/command/implement.md +225 -0
- package/opencode/command/refactor.md +207 -0
- package/opencode/command/review.md +229 -0
- package/opencode/command/simplify.md +267 -0
- package/opencode/command/specify.md +191 -0
- package/opencode/command/validate.md +224 -0
- package/opencode/skill/accessibility-design/SKILL.md +566 -0
- package/opencode/skill/accessibility-design/checklists/wcag-checklist.md +435 -0
- package/opencode/skill/agent-coordination/SKILL.md +224 -0
- package/opencode/skill/api-contract-design/SKILL.md +550 -0
- package/opencode/skill/api-contract-design/templates/graphql-schema-template.md +818 -0
- package/opencode/skill/api-contract-design/templates/rest-api-template.md +417 -0
- package/opencode/skill/architecture-design/SKILL.md +160 -0
- package/opencode/skill/architecture-design/examples/architecture-examples.md +170 -0
- package/opencode/skill/architecture-design/template.md +749 -0
- package/opencode/skill/architecture-design/validation.md +99 -0
- package/opencode/skill/architecture-selection/SKILL.md +522 -0
- package/opencode/skill/architecture-selection/examples/adrs/001-example-adr.md +71 -0
- package/opencode/skill/architecture-selection/examples/architecture-patterns.md +239 -0
- package/opencode/skill/bug-diagnosis/SKILL.md +235 -0
- package/opencode/skill/code-quality-review/SKILL.md +337 -0
- package/opencode/skill/code-quality-review/examples/anti-patterns.md +629 -0
- package/opencode/skill/code-quality-review/reference.md +322 -0
- package/opencode/skill/code-review/SKILL.md +363 -0
- package/opencode/skill/code-review/reference.md +450 -0
- package/opencode/skill/codebase-analysis/SKILL.md +139 -0
- package/opencode/skill/codebase-navigation/SKILL.md +227 -0
- package/opencode/skill/codebase-navigation/examples/exploration-patterns.md +263 -0
- package/opencode/skill/coding-conventions/SKILL.md +178 -0
- package/opencode/skill/coding-conventions/checklists/accessibility-checklist.md +176 -0
- package/opencode/skill/coding-conventions/checklists/performance-checklist.md +154 -0
- package/opencode/skill/coding-conventions/checklists/security-checklist.md +127 -0
- package/opencode/skill/constitution-validation/SKILL.md +315 -0
- package/opencode/skill/constitution-validation/examples/CONSTITUTION.md +202 -0
- package/opencode/skill/constitution-validation/reference/rule-patterns.md +328 -0
- package/opencode/skill/constitution-validation/template.md +115 -0
- package/opencode/skill/context-preservation/SKILL.md +445 -0
- package/opencode/skill/data-modeling/SKILL.md +385 -0
- package/opencode/skill/data-modeling/templates/schema-design-template.md +268 -0
- package/opencode/skill/deployment-pipeline-design/SKILL.md +579 -0
- package/opencode/skill/deployment-pipeline-design/templates/pipeline-template.md +633 -0
- package/opencode/skill/documentation-extraction/SKILL.md +259 -0
- package/opencode/skill/documentation-sync/SKILL.md +431 -0
- package/opencode/skill/domain-driven-design/SKILL.md +509 -0
- package/opencode/skill/domain-driven-design/examples/ddd-patterns.md +688 -0
- package/opencode/skill/domain-driven-design/reference.md +465 -0
- package/opencode/skill/drift-detection/SKILL.md +383 -0
- package/opencode/skill/drift-detection/reference.md +340 -0
- package/opencode/skill/error-recovery/SKILL.md +162 -0
- package/opencode/skill/error-recovery/examples/error-patterns.md +484 -0
- package/opencode/skill/feature-prioritization/SKILL.md +419 -0
- package/opencode/skill/feature-prioritization/examples/rice-template.md +139 -0
- package/opencode/skill/feature-prioritization/reference.md +256 -0
- package/opencode/skill/git-workflow/SKILL.md +453 -0
- package/opencode/skill/implementation-planning/SKILL.md +215 -0
- package/opencode/skill/implementation-planning/examples/phase-examples.md +217 -0
- package/opencode/skill/implementation-planning/template.md +220 -0
- package/opencode/skill/implementation-planning/validation.md +88 -0
- package/opencode/skill/implementation-verification/SKILL.md +272 -0
- package/opencode/skill/knowledge-capture/SKILL.md +265 -0
- package/opencode/skill/knowledge-capture/reference/knowledge-capture.md +402 -0
- package/opencode/skill/knowledge-capture/reference.md +444 -0
- package/opencode/skill/knowledge-capture/templates/domain-template.md +325 -0
- package/opencode/skill/knowledge-capture/templates/interface-template.md +255 -0
- package/opencode/skill/knowledge-capture/templates/pattern-template.md +144 -0
- package/opencode/skill/observability-design/SKILL.md +291 -0
- package/opencode/skill/observability-design/references/monitoring-patterns.md +461 -0
- package/opencode/skill/pattern-detection/SKILL.md +171 -0
- package/opencode/skill/pattern-detection/examples/common-patterns.md +359 -0
- package/opencode/skill/performance-analysis/SKILL.md +266 -0
- package/opencode/skill/performance-analysis/references/profiling-tools.md +499 -0
- package/opencode/skill/requirements-analysis/SKILL.md +139 -0
- package/opencode/skill/requirements-analysis/examples/good-prd.md +66 -0
- package/opencode/skill/requirements-analysis/template.md +177 -0
- package/opencode/skill/requirements-analysis/validation.md +69 -0
- package/opencode/skill/requirements-elicitation/SKILL.md +518 -0
- package/opencode/skill/requirements-elicitation/examples/interview-questions.md +226 -0
- package/opencode/skill/requirements-elicitation/examples/user-stories.md +414 -0
- package/opencode/skill/safe-refactoring/SKILL.md +312 -0
- package/opencode/skill/safe-refactoring/reference/code-smells.md +347 -0
- package/opencode/skill/security-assessment/SKILL.md +421 -0
- package/opencode/skill/security-assessment/checklists/security-review-checklist.md +285 -0
- package/opencode/skill/specification-management/SKILL.md +143 -0
- package/opencode/skill/specification-management/readme-template.md +32 -0
- package/opencode/skill/specification-management/reference.md +115 -0
- package/opencode/skill/specification-management/spec.py +229 -0
- package/opencode/skill/specification-validation/SKILL.md +397 -0
- package/opencode/skill/specification-validation/reference/3cs-framework.md +306 -0
- package/opencode/skill/specification-validation/reference/ambiguity-detection.md +132 -0
- package/opencode/skill/specification-validation/reference/constitution-validation.md +301 -0
- package/opencode/skill/specification-validation/reference/drift-detection.md +383 -0
- package/opencode/skill/task-delegation/SKILL.md +607 -0
- package/opencode/skill/task-delegation/examples/file-coordination.md +495 -0
- package/opencode/skill/task-delegation/examples/parallel-research.md +337 -0
- package/opencode/skill/task-delegation/examples/sequential-build.md +504 -0
- package/opencode/skill/task-delegation/reference.md +825 -0
- package/opencode/skill/tech-stack-detection/SKILL.md +89 -0
- package/opencode/skill/tech-stack-detection/references/framework-signatures.md +598 -0
- package/opencode/skill/technical-writing/SKILL.md +190 -0
- package/opencode/skill/technical-writing/templates/adr-template.md +205 -0
- package/opencode/skill/technical-writing/templates/system-doc-template.md +380 -0
- package/opencode/skill/test-design/SKILL.md +464 -0
- package/opencode/skill/test-design/examples/test-pyramid.md +724 -0
- package/opencode/skill/testing/SKILL.md +213 -0
- package/opencode/skill/testing/examples/test-pyramid.md +724 -0
- package/opencode/skill/user-insight-synthesis/SKILL.md +576 -0
- package/opencode/skill/user-insight-synthesis/templates/research-plan-template.md +217 -0
- package/opencode/skill/user-research/SKILL.md +508 -0
- package/opencode/skill/user-research/examples/interview-questions.md +265 -0
- package/opencode/skill/user-research/examples/personas.md +267 -0
- package/opencode/skill/vibe-security/SKILL.md +654 -0
- package/package.json +45 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Ambiguity Detection Reference
|
|
2
|
+
|
|
3
|
+
Techniques for detecting and scoring ambiguous language in specifications.
|
|
4
|
+
|
|
5
|
+
## Vague Language Patterns
|
|
6
|
+
|
|
7
|
+
| Pattern | Example | Recommendation |
|
|
8
|
+
|---------|---------|----------------|
|
|
9
|
+
| Hedge words | "should", "might", "could" | Use "must" or "will" |
|
|
10
|
+
| Vague quantifiers | "fast", "many", "various" | Specify metrics |
|
|
11
|
+
| Open-ended lists | "etc.", "and so on" | Enumerate all items |
|
|
12
|
+
| Undefined terms | "the system", "appropriate" | Define specifically |
|
|
13
|
+
| Passive voice | "errors are handled" | Specify who/what |
|
|
14
|
+
| Weak verbs | "support", "allow" | Use concrete actions |
|
|
15
|
+
|
|
16
|
+
## Ambiguity Score
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
ambiguity_score = vague_patterns / total_statements * 100
|
|
20
|
+
|
|
21
|
+
0-5%: Excellent clarity
|
|
22
|
+
5-15%: Acceptable
|
|
23
|
+
15-25%: Recommend clarification
|
|
24
|
+
25%+: High ambiguity
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Ambiguity Red Flags
|
|
28
|
+
|
|
29
|
+
- "should", "might", "could", "may"
|
|
30
|
+
- "fast", "slow", "many", "few"
|
|
31
|
+
- "etc.", "and so on", "..."
|
|
32
|
+
- "appropriate", "reasonable"
|
|
33
|
+
- "some", "several", "a few"
|
|
34
|
+
- "as needed", "when necessary"
|
|
35
|
+
- "properly", "correctly"
|
|
36
|
+
|
|
37
|
+
## Automated Detection
|
|
38
|
+
|
|
39
|
+
### Ambiguity Scan
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
grep -inE "(should|might|could|may|various|etc\.|and so on|appropriate|reasonable|fast|slow|many|few)" [file]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Counting Script
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Count vague patterns
|
|
49
|
+
vague_count=$(grep -icE "(should|might|could|may|various|etc\.|appropriate|reasonable)" [file])
|
|
50
|
+
|
|
51
|
+
# Count total lines (rough statement count)
|
|
52
|
+
total=$(wc -l < [file])
|
|
53
|
+
|
|
54
|
+
# Calculate percentage
|
|
55
|
+
echo "Ambiguity: $((vague_count * 100 / total))%"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Category-Specific Patterns
|
|
59
|
+
|
|
60
|
+
### Requirements Ambiguity
|
|
61
|
+
|
|
62
|
+
| Vague | Specific |
|
|
63
|
+
|-------|----------|
|
|
64
|
+
| "The system should be fast" | "Response time < 200ms p95" |
|
|
65
|
+
| "Handle many users" | "Support 10,000 concurrent users" |
|
|
66
|
+
| "User-friendly interface" | "WCAG 2.1 AA compliant, 5 clicks max to any feature" |
|
|
67
|
+
| "Secure authentication" | "OAuth 2.0 with JWT, 15-min token expiry" |
|
|
68
|
+
|
|
69
|
+
### Architecture Ambiguity
|
|
70
|
+
|
|
71
|
+
| Vague | Specific |
|
|
72
|
+
|-------|----------|
|
|
73
|
+
| "Scalable design" | "Horizontal scaling via K8s, stateless services" |
|
|
74
|
+
| "Proper error handling" | "Errors caught at service boundary, logged with correlation ID" |
|
|
75
|
+
| "Standard patterns" | "Repository pattern for data access, Service layer for business logic" |
|
|
76
|
+
|
|
77
|
+
### Implementation Ambiguity
|
|
78
|
+
|
|
79
|
+
| Vague | Specific |
|
|
80
|
+
|-------|----------|
|
|
81
|
+
| "Validate input" | "Check email format (RFC 5322), length 5-254 chars, sanitize HTML" |
|
|
82
|
+
| "Handle edge cases" | "Null user -> 404, Empty list -> empty array, Invalid ID -> 400" |
|
|
83
|
+
| "Add appropriate logging" | "Log INFO for requests, WARN for retries, ERROR with stack trace" |
|
|
84
|
+
|
|
85
|
+
## Remediation Strategies
|
|
86
|
+
|
|
87
|
+
### For Requirements
|
|
88
|
+
|
|
89
|
+
1. **Add metrics**: Replace qualitative with quantitative
|
|
90
|
+
2. **Define boundaries**: Specify min/max/exact values
|
|
91
|
+
3. **List explicitly**: Replace "etc." with complete list
|
|
92
|
+
4. **Name actors**: Replace "the system" with specific component
|
|
93
|
+
|
|
94
|
+
### For Design
|
|
95
|
+
|
|
96
|
+
1. **Reference standards**: Link to design patterns, RFCs, specs
|
|
97
|
+
2. **Show examples**: Include code snippets or diagrams
|
|
98
|
+
3. **Define interfaces**: Specify method signatures, not just descriptions
|
|
99
|
+
4. **Enumerate options**: List all valid states/values
|
|
100
|
+
|
|
101
|
+
### For Implementation
|
|
102
|
+
|
|
103
|
+
1. **Write tests first**: Tests define unambiguous behavior
|
|
104
|
+
2. **Use types**: Let type system enforce constraints
|
|
105
|
+
3. **Add assertions**: Make implicit assumptions explicit
|
|
106
|
+
4. **Document edge cases**: Comment unusual handling
|
|
107
|
+
|
|
108
|
+
## Report Format
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
Ambiguity Analysis
|
|
112
|
+
|
|
113
|
+
File: [path]
|
|
114
|
+
Score: [X]% ([level])
|
|
115
|
+
|
|
116
|
+
High-Priority (should -> must):
|
|
117
|
+
- Line 23: "should validate" -> "must validate"
|
|
118
|
+
- Line 45: "may include" -> "includes" or "does not include"
|
|
119
|
+
|
|
120
|
+
Medium-Priority (vague quantifiers):
|
|
121
|
+
- Line 67: "fast response" -> "< 200ms"
|
|
122
|
+
- Line 89: "many records" -> "up to 10,000 records"
|
|
123
|
+
|
|
124
|
+
Low-Priority (style):
|
|
125
|
+
- Line 12: "etc." -> list all items
|
|
126
|
+
- Line 34: "appropriate" -> define criteria
|
|
127
|
+
|
|
128
|
+
Recommendations:
|
|
129
|
+
1. Address high-priority items before implementation
|
|
130
|
+
2. Clarify quantifiers with stakeholders
|
|
131
|
+
3. Replace open-ended lists with explicit enumerations
|
|
132
|
+
```
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Constitution Validation Reference
|
|
2
|
+
|
|
3
|
+
Techniques for validating code against project governance rules.
|
|
4
|
+
|
|
5
|
+
## Level System (L1/L2/L3)
|
|
6
|
+
|
|
7
|
+
| Level | Name | Blocking | Autofix | Use Case |
|
|
8
|
+
|-------|------|----------|---------|----------|
|
|
9
|
+
| **L1** | Must | Yes | AI auto-corrects | Critical rules - security, correctness, architecture |
|
|
10
|
+
| **L2** | Should | Yes | No (needs human judgment) | Important rules requiring manual attention |
|
|
11
|
+
| **L3** | May | No | No | Advisory/optional - style preferences, suggestions |
|
|
12
|
+
|
|
13
|
+
**Level Behavior:**
|
|
14
|
+
|
|
15
|
+
| Level | Validation | Implementation | AI Behavior |
|
|
16
|
+
|-------|------------|----------------|-------------|
|
|
17
|
+
| `L1` | Fails check, blocks | Blocks phase completion | **Automatically fixes** before proceeding |
|
|
18
|
+
| `L2` | Fails check, blocks | Blocks phase completion | Reports violation, **requires human action** |
|
|
19
|
+
| `L3` | Reports only | Does not block | Optional improvement, can be ignored |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Rule Schema
|
|
24
|
+
|
|
25
|
+
Each rule in the constitution uses this YAML structure:
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
level: L1 | L2 | L3
|
|
29
|
+
pattern: "regex pattern" # OR
|
|
30
|
+
check: "semantic description for LLM interpretation"
|
|
31
|
+
scope: "glob pattern for files to check"
|
|
32
|
+
exclude: "glob patterns to skip (comma-separated)"
|
|
33
|
+
message: "Human-readable violation message"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| Field | Required | Type | Description |
|
|
37
|
+
|-------|----------|------|-------------|
|
|
38
|
+
| `level` | Required | `L1` \| `L2` \| `L3` | Determines blocking and autofix behavior |
|
|
39
|
+
| `pattern` | One of | Regex | Pattern to match violations in source code |
|
|
40
|
+
| `check` | One of | String | Semantic description for LLM interpretation |
|
|
41
|
+
| `scope` | Required | Glob | File patterns to check (supports `**`) |
|
|
42
|
+
| `exclude` | Optional | Glob | File patterns to skip (comma-separated) |
|
|
43
|
+
| `message` | Required | String | Human-readable violation message |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Rule Types
|
|
48
|
+
|
|
49
|
+
### Pattern Rules
|
|
50
|
+
|
|
51
|
+
Pattern rules use regex to match violations in source code. These are deterministic and fast.
|
|
52
|
+
|
|
53
|
+
**When to use:**
|
|
54
|
+
- Text patterns that can be matched literally
|
|
55
|
+
- Syntax violations (forbidden imports, banned functions)
|
|
56
|
+
- Secret detection (API keys, passwords)
|
|
57
|
+
|
|
58
|
+
**Regex Tips:**
|
|
59
|
+
- Escape special characters: `\.` for literal dot
|
|
60
|
+
- Use `\s*` for flexible whitespace
|
|
61
|
+
- Use `\b` for word boundaries
|
|
62
|
+
- Escape backslashes in YAML: `\\b` for `\b`
|
|
63
|
+
|
|
64
|
+
**Example - Detecting Barrel Exports:**
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
level: L1
|
|
68
|
+
pattern: "export \\* from"
|
|
69
|
+
scope: "src/**/*.ts"
|
|
70
|
+
exclude: "src/index.ts"
|
|
71
|
+
message: Barrel exports prohibited. Import from specific files.
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Check Rules
|
|
75
|
+
|
|
76
|
+
Check rules use semantic descriptions that the LLM interprets. These are flexible but non-deterministic.
|
|
77
|
+
|
|
78
|
+
**When to use:**
|
|
79
|
+
- Architectural patterns that require understanding context
|
|
80
|
+
- Rules that span multiple lines or files
|
|
81
|
+
- Semantic concepts (like "database calls only in repositories")
|
|
82
|
+
|
|
83
|
+
**Example - Repository Pattern:**
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
level: L1
|
|
87
|
+
check: Database queries (Prisma, TypeORM, Knex, raw SQL) only in files matching *Repository.ts or *Repository.js
|
|
88
|
+
scope: "src/**/*.{ts,js}"
|
|
89
|
+
exclude: "**/repositories/**"
|
|
90
|
+
message: Direct database call outside repository layer.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Validation Execution
|
|
96
|
+
|
|
97
|
+
For each parsed rule:
|
|
98
|
+
|
|
99
|
+
1. **Glob files matching scope** (excluding patterns in `exclude`)
|
|
100
|
+
2. **For Pattern rules**: Execute regex match against file contents
|
|
101
|
+
3. **For Check rules**: Use LLM to interpret semantic check
|
|
102
|
+
4. **Collect violations** with file path, line number, code snippet
|
|
103
|
+
5. **Categorize by level** for reporting
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Rule Parsing
|
|
108
|
+
|
|
109
|
+
```pseudocode
|
|
110
|
+
FUNCTION: parse_constitution(markdown_content)
|
|
111
|
+
rules = []
|
|
112
|
+
current_category = null
|
|
113
|
+
|
|
114
|
+
FOR EACH section in markdown:
|
|
115
|
+
IF section.header.level == 2:
|
|
116
|
+
current_category = section.header.text # e.g., "Code Quality", "Security"
|
|
117
|
+
ELSE IF section.header.level == 3:
|
|
118
|
+
yaml_block = extract_yaml_code_block(section.content)
|
|
119
|
+
IF yaml_block:
|
|
120
|
+
rule = {
|
|
121
|
+
id: generate_rule_id(current_category, index), # e.g., "SEC-001"
|
|
122
|
+
name: section.header.text, # e.g., "No Hardcoded Secrets"
|
|
123
|
+
category: current_category,
|
|
124
|
+
level: yaml_block.level,
|
|
125
|
+
pattern: yaml_block.pattern,
|
|
126
|
+
check: yaml_block.check,
|
|
127
|
+
scope: yaml_block.scope,
|
|
128
|
+
exclude: yaml_block.exclude,
|
|
129
|
+
message: yaml_block.message,
|
|
130
|
+
}
|
|
131
|
+
IF rule.pattern OR rule.check:
|
|
132
|
+
# Derive behavior from level
|
|
133
|
+
rule.blocking = (rule.level == "L1" OR rule.level == "L2")
|
|
134
|
+
rule.autofix = (rule.level == "L1")
|
|
135
|
+
rules.append(rule)
|
|
136
|
+
RETURN rules
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Category ID Prefixes
|
|
142
|
+
|
|
143
|
+
| Category | Prefix | Example |
|
|
144
|
+
|----------|--------|---------|
|
|
145
|
+
| Security | SEC | SEC-001 |
|
|
146
|
+
| Architecture | ARCH | ARCH-001 |
|
|
147
|
+
| Code Quality | QUAL | QUAL-001 |
|
|
148
|
+
| Testing | TEST | TEST-001 |
|
|
149
|
+
| Custom | CUST | CUST-001 |
|
|
150
|
+
| [Custom Name] | First 4 letters uppercase | PERF-001 |
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Common Rule Patterns
|
|
155
|
+
|
|
156
|
+
### Security
|
|
157
|
+
|
|
158
|
+
```yaml
|
|
159
|
+
# SQL Injection Detection
|
|
160
|
+
level: L1
|
|
161
|
+
pattern: "\\.(query|execute|raw)\\s*\\([^)]*\\$\\{|\\+\\s*['\"]"
|
|
162
|
+
scope: "**/*.{ts,js}"
|
|
163
|
+
message: Potential SQL injection. Use parameterized queries.
|
|
164
|
+
|
|
165
|
+
# No Sensitive Data in Logs
|
|
166
|
+
level: L2
|
|
167
|
+
pattern: "console\\.(log|info|warn|error)\\([^)]*password|secret|token|key"
|
|
168
|
+
scope: "src/**/*.{ts,js}"
|
|
169
|
+
message: Sensitive data may be logged. Remove or redact.
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Architecture
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
# No Cross-Package Relative Imports
|
|
176
|
+
level: L2
|
|
177
|
+
check: Imports between packages must use package name, not relative path
|
|
178
|
+
scope: "packages/*/src/**"
|
|
179
|
+
message: Cross-package import must use package name, not relative path.
|
|
180
|
+
|
|
181
|
+
# Service Layer Boundaries
|
|
182
|
+
level: L1
|
|
183
|
+
check: HTTP calls (fetch, axios, got) only in files under services/ or api/
|
|
184
|
+
scope: "src/components/**"
|
|
185
|
+
message: API calls must go through service layer.
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Code Quality
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
# No TODO in Main Branch
|
|
192
|
+
level: L3
|
|
193
|
+
pattern: "TODO|FIXME|XXX|HACK"
|
|
194
|
+
scope: "src/**/*.{ts,js}"
|
|
195
|
+
message: Unresolved TODO marker. Complete or track in issue.
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Testing
|
|
199
|
+
|
|
200
|
+
```yaml
|
|
201
|
+
# No .only in Committed Tests
|
|
202
|
+
level: L1
|
|
203
|
+
pattern: "\\.(only|skip)\\s*\\("
|
|
204
|
+
scope: "**/*.test.*, **/*.spec.*"
|
|
205
|
+
message: Remove .only/.skip before committing tests.
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Compliance Report Format
|
|
211
|
+
|
|
212
|
+
```markdown
|
|
213
|
+
## Constitution Compliance Report
|
|
214
|
+
|
|
215
|
+
**Constitution:** CONSTITUTION.md
|
|
216
|
+
**Target:** [spec-id or file path or "entire codebase"]
|
|
217
|
+
**Checked:** [ISO timestamp]
|
|
218
|
+
|
|
219
|
+
### Summary
|
|
220
|
+
|
|
221
|
+
- Passed: [N] rules
|
|
222
|
+
- L3 Advisories: [N] rules
|
|
223
|
+
- L2 Blocking: [N] rules
|
|
224
|
+
- L1 Critical: [N] rules
|
|
225
|
+
|
|
226
|
+
### Critical Violations (L1 - Autofix Required)
|
|
227
|
+
|
|
228
|
+
#### SEC-001: No Hardcoded Secrets
|
|
229
|
+
- **Location:** `src/services/PaymentService.ts:42`
|
|
230
|
+
- **Finding:** Hardcoded secret detected. Use environment variables.
|
|
231
|
+
- **Code:** `const API_KEY = 'sk_live_xxx...'`
|
|
232
|
+
- **Autofix:** Replace with `process.env.PAYMENT_API_KEY`
|
|
233
|
+
|
|
234
|
+
### Blocking Violations (L2 - Human Action Required)
|
|
235
|
+
|
|
236
|
+
#### ARCH-001: Repository Pattern
|
|
237
|
+
- **Location:** `src/services/UserService.ts:18`
|
|
238
|
+
- **Finding:** Direct database call outside repository.
|
|
239
|
+
- **Code:** `await prisma.user.findMany(...)`
|
|
240
|
+
- **Action Required:** Extract to UserRepository
|
|
241
|
+
|
|
242
|
+
### Advisories (L3 - Optional)
|
|
243
|
+
|
|
244
|
+
#### QUAL-001: Function Length
|
|
245
|
+
- **Location:** `src/utils/helpers.ts:45`
|
|
246
|
+
- **Finding:** Function exceeds recommended 25 lines (actual: 38)
|
|
247
|
+
- **Suggestion:** Consider extracting helper functions
|
|
248
|
+
|
|
249
|
+
### Recommendations
|
|
250
|
+
|
|
251
|
+
1. [Prioritized action item based on violations]
|
|
252
|
+
2. [Next action item]
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Graceful Degradation
|
|
258
|
+
|
|
259
|
+
| Scenario | Behavior |
|
|
260
|
+
|----------|----------|
|
|
261
|
+
| No CONSTITUTION.md | Report "No constitution found. Skipping constitution checks." |
|
|
262
|
+
| Invalid rule format | Skip rule, warn user, continue with other rules |
|
|
263
|
+
| Invalid regex pattern | Report as config error, skip rule |
|
|
264
|
+
| Scope matches no files | Report as info, not a failure |
|
|
265
|
+
| File read error | Skip file, warn, continue |
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Scope Patterns
|
|
270
|
+
|
|
271
|
+
### Common Patterns
|
|
272
|
+
|
|
273
|
+
| Pattern | Matches |
|
|
274
|
+
|---------|---------|
|
|
275
|
+
| `**/*.ts` | All TypeScript files |
|
|
276
|
+
| `src/**/*.ts` | TypeScript files in src/ |
|
|
277
|
+
| `**/*.{ts,js}` | TypeScript and JavaScript |
|
|
278
|
+
| `packages/*/src/**` | All packages' src folders |
|
|
279
|
+
| `apps/web/**` | Only the web app |
|
|
280
|
+
|
|
281
|
+
### Monorepo Scoping
|
|
282
|
+
|
|
283
|
+
```yaml
|
|
284
|
+
# Web package only
|
|
285
|
+
scope: "packages/web/src/**/*.{ts,tsx}"
|
|
286
|
+
|
|
287
|
+
# All packages
|
|
288
|
+
scope: "packages/*/src/**/*.ts"
|
|
289
|
+
|
|
290
|
+
# Shared libraries
|
|
291
|
+
scope: "libs/*/src/**/*.ts"
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Performance Considerations
|
|
297
|
+
|
|
298
|
+
1. **Pattern rules are faster** than Check rules (no LLM needed)
|
|
299
|
+
2. **Narrow scopes** reduce file scanning
|
|
300
|
+
3. **Specific excludes** prevent unnecessary checks
|
|
301
|
+
4. **Batch similar rules** under same scope for efficiency
|